diff --git a/packages/backend/src/resolvers/comment.resolver.ts b/packages/backend/src/resolvers/comment.resolver.ts index 48ebdfc..f67702e 100644 --- a/packages/backend/src/resolvers/comment.resolver.ts +++ b/packages/backend/src/resolvers/comment.resolver.ts @@ -66,15 +66,57 @@ export const commentResolver: GqlResolvers = { 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 }) => { diff --git a/packages/backend/src/resolvers/trainer.resolver.ts b/packages/backend/src/resolvers/trainer.resolver.ts index 6264890..c95245b 100644 --- a/packages/backend/src/resolvers/trainer.resolver.ts +++ b/packages/backend/src/resolvers/trainer.resolver.ts @@ -31,11 +31,53 @@ export const trainerResolver: GqlResolvers = { 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: {