Skip to content

Commit 76d4a55

Browse files
chore: clean
1 parent 0fb639b commit 76d4a55

File tree

2 files changed

+5
-91
lines changed

2 files changed

+5
-91
lines changed

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

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

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

11673
return createCommentOnCommentable({
117-
commentable: reportCleaned,
74+
commentable: report,
11875
text,
11976
currentUser,
120-
report: reportCleaned,
77+
report: report,
12178
})
12279
},
12380
updateCommentOnDay: async (_parent, { id, text, traineeId, commentId }, { currentUser }) => {

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

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,54 +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 == null) com.published = true
39-
if (com.published === false) {
40-
return com
41-
} else {
42-
return {
43-
...com,
44-
published: true,
45-
}
46-
}
47-
}),
48-
days: report?.days.map((day) => ({
49-
...day,
50-
entries: day.entries.map((entry) => ({
51-
...entry,
52-
comments: entry.comments.map((com) => {
53-
if (com.published === false) {
54-
return com
55-
} else {
56-
return {
57-
...com,
58-
published: true,
59-
}
60-
}
61-
}),
62-
})),
63-
comments: day.comments.map((com) => {
64-
if (com.published === false) {
65-
return com
66-
} else {
67-
return {
68-
...com,
69-
published: true,
70-
}
71-
}
72-
}),
73-
})),
74-
}
75-
: undefined
76-
77-
if (!reportCleaned || reportCleaned.traineeId !== trainee.id) {
34+
if (!report || report.traineeId !== trainee.id) {
7835
throw new GraphQLError(t('errors.missingReport'))
7936
}
8037

81-
return reportCleaned
38+
return report
8239
},
8340
},
8441
Mutation: {

0 commit comments

Comments
 (0)