Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions packages/backend/src/resolvers/comment.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,57 @@ export const commentResolver: GqlResolvers<AuthenticatedContext> = {
createCommentOnReport: async (_parent, { id, text, traineeId }, { currentUser }) => {
const report = await reportById(id)

if (report?.traineeId !== traineeId) {
const reportCleaned = report
? {
...report,
comments: report?.comments.map((com) => {
if (com.published === false) {
return com
} else {
return {
...com,
published: true,
}
}
}),
days: report?.days.map((day) => ({
...day,
entries: day.entries.map((entry) => ({
...entry,
comments: entry.comments.map((com) => {
if (com.published === false) {
return com
} else {
return {
...com,
published: true,
}
}
}),
})),
comments: day.comments.map((com) => {
if (com.published === false) {
return com
} else {
return {
...com,
published: true,
}
}
}),
})),
}
: undefined

if (reportCleaned?.traineeId !== traineeId) {
throw new GraphQLError(t('errors.missingReport', currentUser.language))
}

return createCommentOnCommentable({
commentable: report,
commentable: reportCleaned,
text,
currentUser,
report,
report: reportCleaned,
})
},
updateCommentOnDay: async (_parent, { id, text, traineeId, commentId }, { currentUser }) => {
Expand Down
46 changes: 44 additions & 2 deletions packages/backend/src/resolvers/trainer.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,53 @@ export const trainerResolver: GqlResolvers<TrainerContext> = {

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

if (!report || report.traineeId !== trainee.id) {
const reportCleaned = report
? {
...report,
comments: report?.comments.map((com) => {
if (com.published === false) {
return com
} else {
return {
...com,
published: true,
}
}
}),
days: report?.days.map((day) => ({
...day,
entries: day.entries.map((entry) => ({
...entry,
comments: entry.comments.map((com) => {
if (com.published === false) {
return com
} else {
return {
...com,
published: true,
}
}
}),
})),
comments: day.comments.map((com) => {
if (com.published === false) {
return com
} else {
return {
...com,
published: true,
}
}
}),
})),
}
: undefined

if (!reportCleaned || reportCleaned.traineeId !== trainee.id) {
throw new GraphQLError(t('errors.missingReport'))
}

return report
return reportCleaned
},
},
Mutation: {
Expand Down