2016-06-16 20:07:38 +00:00
|
|
|
import mongoose from 'mongoose';
|
|
|
|
const Schema = mongoose.Schema;
|
2016-06-17 20:40:13 +00:00
|
|
|
import shortid from 'shortid';
|
2016-06-16 20:07:38 +00:00
|
|
|
|
2016-06-17 18:11:52 +00:00
|
|
|
const fileSchema = new Schema({
|
2016-06-23 22:29:55 +00:00
|
|
|
name: { type: String, default: 'sketch.js' },
|
2016-08-24 21:59:15 +00:00
|
|
|
content: { type: String, default: '' },
|
2016-08-23 04:10:42 +00:00
|
|
|
url: { type: String },
|
2016-11-17 16:15:35 +00:00
|
|
|
children: { type: [String], default: [] },
|
2016-08-25 21:32:27 +00:00
|
|
|
fileType: { type: String, default: 'file' },
|
2016-09-14 19:57:52 +00:00
|
|
|
isSelectedFile: { type: Boolean }
|
2016-07-07 17:04:54 +00:00
|
|
|
}, { timestamps: true, _id: true });
|
2016-06-17 18:11:52 +00:00
|
|
|
|
2016-11-17 16:15:35 +00:00
|
|
|
fileSchema.virtual('id').get(function () {
|
|
|
|
return this._id.toHexString();
|
2016-07-07 17:50:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
fileSchema.set('toJSON', {
|
2016-11-17 16:15:35 +00:00
|
|
|
virtuals: true
|
2016-07-07 17:50:52 +00:00
|
|
|
});
|
|
|
|
|
2016-06-16 20:07:38 +00:00
|
|
|
const projectSchema = new Schema({
|
2016-06-23 22:29:55 +00:00
|
|
|
name: { type: String, default: "Hello p5.js, it's the server" },
|
|
|
|
user: { type: Schema.Types.ObjectId, ref: 'User' },
|
2016-11-17 16:15:35 +00:00
|
|
|
files: { type: [fileSchema] },
|
2016-08-24 17:09:48 +00:00
|
|
|
_id: { type: String, default: shortid.generate }
|
2016-06-23 22:29:55 +00:00
|
|
|
}, { timestamps: true });
|
2016-06-16 20:07:38 +00:00
|
|
|
|
2016-11-17 16:15:35 +00:00
|
|
|
projectSchema.virtual('id').get(function () {
|
|
|
|
return this._id;
|
2016-07-07 17:50:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
projectSchema.set('toJSON', {
|
2016-11-17 16:15:35 +00:00
|
|
|
virtuals: true
|
2016-07-07 17:50:52 +00:00
|
|
|
});
|
|
|
|
|
2016-06-23 22:29:55 +00:00
|
|
|
export default mongoose.model('Project', projectSchema);
|