Skip to content

Commit 0d44638

Browse files
committed
disable minimize feature for projectSchema to prevent Mongoose from deleting empty {}. Downloaded project can be open in cavas now
1 parent 9f2a207 commit 0d44638

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

server/graphQL/resolvers/mutation.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { Tests, Projects } = require('../../models/reactypeModels');
2+
23
/*
34
* resolvers are functions that handles graphQL requests. This file defines the logic for graphQL mutation requests
45
* Link to Apollo Mutations:
@@ -64,14 +65,18 @@ const Project = {
6465
makeCopy: async (parent, { projId, userId, username }) => {
6566
const filter = { _id: projId };
6667
const target = await Projects.findOne(filter);
68+
6769
// make a copy with the passed in userId
70+
// IMPORTANT: DO NOT CHANGE copy.name, it will create a nother copy of the document with the origional project name.
6871
const copy = {
69-
name: target.name,
70-
likes: target.likes,
72+
name: target.name,
7173
project: target.project,
7274
userId,
7375
username,
7476
};
77+
78+
// IMPORTANT: MUST MAKE A DEEP COPY OF target.project, otherwise, field 'style' is lost during the copy process. See 'minimize' option in projectSchema
79+
7580
const resp = await Projects.create(copy);
7681

7782
if (resp) {

server/models/reactypeModels.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ const projectSchema = new Schema({
6666
},
6767
username: {type: String, required: true },
6868
createdAt: { type: Date, default: Date.now }
69-
});
69+
}, { minimize: false });
70+
// option 'minimize' prevent Mongoose from removing empty 'style' value in the copy
7071

7172
// Test schema for implementing GraphQL
7273
const testSchema = new Schema({

0 commit comments

Comments
 (0)