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