Skip to content

Commit fa7de89

Browse files
committed
update project and collection models from docs
1 parent 5e8cc73 commit fa7de89

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

server/models/collection.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const { Schema } = mongoose;
66

77
const collectedProjectSchema = new Schema(
88
{
9-
project: { type: Schema.Types.ObjectId, ref: 'Project' }
9+
project: { type: Schema.Types.String, ref: 'Project' }
1010
},
11-
{ timestamps: true, _id: true, usePushEach: true }
11+
{ timestamps: true }
1212
);
1313

1414
collectedProjectSchema.virtual('id').get(function getId() {
@@ -36,7 +36,7 @@ const collectionSchema = new Schema(
3636
owner: { type: Schema.Types.ObjectId, ref: 'User' },
3737
items: { type: [collectedProjectSchema] }
3838
},
39-
{ timestamps: true, usePushEach: true }
39+
{ timestamps: true }
4040
);
4141

4242
collectionSchema.virtual('id').get(function getId() {
@@ -48,9 +48,8 @@ collectionSchema.set('toJSON', {
4848
});
4949

5050
collectionSchema.pre('save', function generateSlug(next) {
51-
const collection = this;
52-
collection.slug = slugify(collection.name, '_');
53-
return next();
51+
this.slug = slugify(this.name, { lower: true, strict: true });
52+
next();
5453
});
5554

5655
export default mongoose.models.Collection ||

server/models/project.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ const fileSchema = new Schema(
1414
url: { type: String },
1515
children: { type: [String], default: [] },
1616
fileType: { type: String, default: 'file' },
17-
isSelectedFile: { type: Boolean }
17+
isSelectedFile: { type: Boolean, default: false }
1818
},
19-
{ timestamps: true, _id: true, usePushEach: true }
19+
{ timestamps: true }
2020
);
2121

2222
fileSchema.virtual('id').get(function getFileId() {
@@ -36,11 +36,11 @@ const projectSchema = new Schema(
3636
},
3737
user: { type: Schema.Types.ObjectId, ref: 'User' },
3838
serveSecure: { type: Boolean, default: false },
39-
files: { type: [fileSchema] },
39+
files: { type: [fileSchema], default: [] },
4040
_id: { type: String, default: shortid.generate },
4141
slug: { type: String }
4242
},
43-
{ timestamps: true, usePushEach: true }
43+
{ timestamps: true }
4444
);
4545

4646
projectSchema.virtual('id').get(function getProjectId() {
@@ -52,13 +52,10 @@ projectSchema.set('toJSON', {
5252
});
5353

5454
projectSchema.pre('save', function generateSlug(next) {
55-
const project = this;
56-
57-
if (!project.slug) {
58-
project.slug = slugify(project.name, '_');
55+
if (!this.slug) {
56+
this.slug = slugify(this.name, { lower: true, strict: true });
5957
}
60-
61-
return next();
58+
next();
6259
});
6360

6461
/**

0 commit comments

Comments
 (0)