fix lint errors

This commit is contained in:
Gaurang Tandon 2018-12-15 12:43:58 +05:30
parent 26d65396b4
commit d86944034e
2 changed files with 24 additions and 18 deletions

View file

@ -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' }, {
content: { type: String, default: '' }, name: { type: String, default: 'sketch.js' },
url: { type: String }, content: { type: String, default: '' },
children: { type: [String], default: [] }, url: { type: String },
fileType: { type: String, default: 'file' }, children: { type: [String], default: [] },
isSelectedFile: { type: Boolean } fileType: { type: String, default: 'file' },
}, { timestamps: true, _id: true, usePushEach: true }); isSelectedFile: { type: Boolean }
},
{ 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" }, {
user: { type: Schema.Types.ObjectId, ref: 'User' }, name: { type: String, default: "Hello p5.js, it's the server" },
serveSecure: { type: Boolean, default: false }, user: { type: Schema.Types.ObjectId, ref: 'User' },
files: { type: [fileSchema] }, serveSecure: { type: Boolean, default: false },
_id: { type: String, default: shortid.generate }, files: { type: [fileSchema] },
slug: { type: String } _id: { type: String, default: shortid.generate },
}, { timestamps: true, usePushEach: true }); slug: { type: String }
},
{ 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();

View file

@ -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 || '');