Skip to content

Commit 4605263

Browse files
Merge pull request #381 from lara-learning/chore/clean
Chore/clean
2 parents 80ce3e2 + 76d4a55 commit 4605263

File tree

2 files changed

+5
-89
lines changed

2 files changed

+5
-89
lines changed

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

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

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

11977
return createCommentOnCommentable({
120-
commentable: reportCleaned,
78+
commentable: report,
12179
text,
12280
currentUser,
123-
report: reportCleaned,
81+
report: report,
12482
})
12583
},
12684
updateCommentOnDay: async (_parent, { id, text, traineeId, commentId }, { currentUser }) => {

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

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

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

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) {
34+
if (!report || report.traineeId !== trainee.id) {
7735
throw new GraphQLError(t('errors.missingReport'))
7836
}
7937

80-
return reportCleaned
38+
return report
8139
},
8240
},
8341
Mutation: {

0 commit comments

Comments
 (0)