Skip to content

Commit 3891010

Browse files
committed
merge to recieve from khuong
2 parents adb9603 + 0d44638 commit 3891010

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:
@@ -65,14 +66,18 @@ const Project = {
6566
makeCopy: async (parent, { projId, userId, username }) => {
6667
const filter = { _id: projId };
6768
const target = await Projects.findOne(filter);
69+
6870
// make a copy with the passed in userId
71+
// IMPORTANT: DO NOT CHANGE copy.name, it will create a nother copy of the document with the origional project name.
6972
const copy = {
70-
name: target.name,
71-
likes: target.likes,
73+
name: target.name,
7274
project: target.project,
7375
userId,
7476
username,
7577
};
78+
79+
// IMPORTANT: MUST MAKE A DEEP COPY OF target.project, otherwise, field 'style' is lost during the copy process. See 'minimize' option in projectSchema
80+
7681
const resp = await Projects.create(copy);
7782

7883
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)