Skip to content

Commit b5ff66f

Browse files
Merge pull request #372 from lara-learning/fix/comment-unable-to-load-when-published-null
fix: allow published = null
2 parents 9f7175f + 25d01e9 commit b5ff66f

File tree

2 files changed

+89
-5
lines changed

2 files changed

+89
-5
lines changed

packages/backend/src/resolvers/comment.resolver.ts

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,57 @@ export const commentResolver: GqlResolvers<AuthenticatedContext> = {
6666
createCommentOnReport: async (_parent, { id, text, traineeId }, { currentUser }) => {
6767
const report = await reportById(id)
6868

69-
if (report?.traineeId !== traineeId) {
69+
const reportCleaned = report
70+
? {
71+
...report,
72+
comments: report?.comments.map((com) => {
73+
if (com.published === false) {
74+
return com
75+
} else {
76+
return {
77+
...com,
78+
published: true,
79+
}
80+
}
81+
}),
82+
days: report?.days.map((day) => ({
83+
...day,
84+
entries: day.entries.map((entry) => ({
85+
...entry,
86+
comments: entry.comments.map((com) => {
87+
if (com.published === false) {
88+
return com
89+
} else {
90+
return {
91+
...com,
92+
published: true,
93+
}
94+
}
95+
}),
96+
})),
97+
comments: day.comments.map((com) => {
98+
if (com.published === false) {
99+
return com
100+
} else {
101+
return {
102+
...com,
103+
published: true,
104+
}
105+
}
106+
}),
107+
})),
108+
}
109+
: undefined
110+
111+
if (reportCleaned?.traineeId !== traineeId) {
70112
throw new GraphQLError(t('errors.missingReport', currentUser.language))
71113
}
72114

73115
return createCommentOnCommentable({
74-
commentable: report,
116+
commentable: reportCleaned,
75117
text,
76118
currentUser,
77-
report,
119+
report: reportCleaned,
78120
})
79121
},
80122
updateCommentOnDay: async (_parent, { id, text, traineeId, commentId }, { currentUser }) => {

packages/backend/src/resolvers/trainer.resolver.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,53 @@ export const trainerResolver: GqlResolvers<TrainerContext> = {
3131

3232
const report = await reportByYearAndWeek(year, week, trainee.id)
3333

34-
if (!report || report.traineeId !== trainee.id) {
34+
const reportCleaned = report
35+
? {
36+
...report,
37+
comments: report?.comments.map((com) => {
38+
if (com.published === false) {
39+
return com
40+
} else {
41+
return {
42+
...com,
43+
published: true,
44+
}
45+
}
46+
}),
47+
days: report?.days.map((day) => ({
48+
...day,
49+
entries: day.entries.map((entry) => ({
50+
...entry,
51+
comments: entry.comments.map((com) => {
52+
if (com.published === false) {
53+
return com
54+
} else {
55+
return {
56+
...com,
57+
published: true,
58+
}
59+
}
60+
}),
61+
})),
62+
comments: day.comments.map((com) => {
63+
if (com.published === false) {
64+
return com
65+
} else {
66+
return {
67+
...com,
68+
published: true,
69+
}
70+
}
71+
}),
72+
})),
73+
}
74+
: undefined
75+
76+
if (!reportCleaned || reportCleaned.traineeId !== trainee.id) {
3577
throw new GraphQLError(t('errors.missingReport'))
3678
}
3779

38-
return report
80+
return reportCleaned
3981
},
4082
},
4183
Mutation: {

0 commit comments

Comments
 (0)