fix lint errors
This commit is contained in:
parent
26d65396b4
commit
d86944034e
2 changed files with 24 additions and 18 deletions
|
@ -4,14 +4,17 @@ import generateSlug from '../utils/generateSlug';
|
||||||
|
|
||||||
const { Schema } = mongoose;
|
const { Schema } = mongoose;
|
||||||
|
|
||||||
const fileSchema = new Schema({
|
const fileSchema = new Schema(
|
||||||
|
{
|
||||||
name: { type: String, default: 'sketch.js' },
|
name: { type: String, default: 'sketch.js' },
|
||||||
content: { type: String, default: '' },
|
content: { type: String, default: '' },
|
||||||
url: { type: String },
|
url: { type: String },
|
||||||
children: { type: [String], default: [] },
|
children: { type: [String], default: [] },
|
||||||
fileType: { type: String, default: 'file' },
|
fileType: { type: String, default: 'file' },
|
||||||
isSelectedFile: { type: Boolean }
|
isSelectedFile: { type: Boolean }
|
||||||
}, { timestamps: true, _id: true, usePushEach: true });
|
},
|
||||||
|
{ timestamps: true, _id: true, usePushEach: true }
|
||||||
|
);
|
||||||
|
|
||||||
fileSchema.virtual('id').get(function getFileId() {
|
fileSchema.virtual('id').get(function getFileId() {
|
||||||
return this._id.toHexString();
|
return this._id.toHexString();
|
||||||
|
@ -21,14 +24,17 @@ fileSchema.set('toJSON', {
|
||||||
virtuals: true
|
virtuals: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const projectSchema = new Schema({
|
const projectSchema = new Schema(
|
||||||
|
{
|
||||||
name: { type: String, default: "Hello p5.js, it's the server" },
|
name: { type: String, default: "Hello p5.js, it's the server" },
|
||||||
user: { type: Schema.Types.ObjectId, ref: 'User' },
|
user: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||||
serveSecure: { type: Boolean, default: false },
|
serveSecure: { type: Boolean, default: false },
|
||||||
files: { type: [fileSchema] },
|
files: { type: [fileSchema] },
|
||||||
_id: { type: String, default: shortid.generate },
|
_id: { type: String, default: shortid.generate },
|
||||||
slug: { type: String }
|
slug: { type: String }
|
||||||
}, { timestamps: true, usePushEach: true });
|
},
|
||||||
|
{ timestamps: true, usePushEach: true }
|
||||||
|
);
|
||||||
|
|
||||||
projectSchema.virtual('id').get(function getProjectId() {
|
projectSchema.virtual('id').get(function getProjectId() {
|
||||||
return this._id;
|
return this._id;
|
||||||
|
@ -38,7 +44,7 @@ projectSchema.set('toJSON', {
|
||||||
virtuals: true
|
virtuals: true
|
||||||
});
|
});
|
||||||
|
|
||||||
projectSchema.pre('save', function generateSlug(next) {
|
projectSchema.pre('save', function slugGenerator(next) {
|
||||||
const project = this;
|
const project = this;
|
||||||
project.slug = generateSlug(project.name, '_');
|
project.slug = generateSlug(project.name, '_');
|
||||||
return next();
|
return next();
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
* @param {String} string
|
* @param {String} string
|
||||||
* @param {String} replacer (optional) character to replace invalid characters
|
* @param {String} replacer (optional) character to replace invalid characters
|
||||||
*/
|
*/
|
||||||
export function generateSlug(string, replacer) {
|
function generateSlug(string, replacer) {
|
||||||
// from here https://serverfault.com/a/242134
|
// from here https://serverfault.com/a/242134
|
||||||
const INVALID_CHARS_REGEX = /[*/?:\\<>|"\u0000-\u001F]/g;
|
const INVALID_CHARS_REGEX = /[*/?:\\<>|"\u0000-\u001F]/g;
|
||||||
const slug = string.replace(INVALID_CHARS_REGEX, replacer || '');
|
const slug = string.replace(INVALID_CHARS_REGEX, replacer || '');
|
||||||
|
|
Loading…
Reference in a new issue