@@ -4,7 +4,13 @@ import { AuthenticatedContext, GqlResolvers } from '@lara/api'
44
55import { reportById } from '../repositories/report.repo'
66import { userById } from '../repositories/user.repo'
7- import { commentableReports , createCommentOnCommentable } from '../services/comment.service'
7+ import {
8+ commentableReports ,
9+ createCommentOnCommentable ,
10+ deleteCommentOnCommentable ,
11+ publishCommentsOnReport ,
12+ updateCommentOnCommentable ,
13+ } from '../services/comment.service'
814import { reportDayByDayId } from '../services/day.service'
915import { reportDayEntryByEntryId } from '../services/entry.service'
1016import { t } from '../i18n'
@@ -71,5 +77,92 @@ export const commentResolver: GqlResolvers<AuthenticatedContext> = {
7177 report,
7278 } )
7379 } ,
80+ updateCommentOnDay : async ( _parent , { id, text, traineeId, commentId } , { currentUser } ) => {
81+ const reports = await commentableReports ( traineeId )
82+ const { report, day } = reportDayByDayId ( id , reports )
83+
84+ return updateCommentOnCommentable ( {
85+ commentable : day ,
86+ text,
87+ currentUser,
88+ report,
89+ commentId,
90+ } )
91+ } ,
92+ updateCommentOnEntry : async ( _parent , { id, text, traineeId, commentId } , { currentUser } ) => {
93+ const reports = await commentableReports ( traineeId )
94+ const { report, entry } = reportDayEntryByEntryId ( id , reports )
95+
96+ return updateCommentOnCommentable ( {
97+ commentable : entry ,
98+ text,
99+ currentUser,
100+ report,
101+ commentId,
102+ } )
103+ } ,
104+ updateCommentOnReport : async ( _parent , { id, text, traineeId, commentId } , { currentUser } ) => {
105+ const report = await reportById ( id )
106+
107+ if ( report ?. traineeId !== traineeId ) {
108+ throw new GraphQLError ( t ( 'errors.missingReport' , currentUser . language ) )
109+ }
110+
111+ return updateCommentOnCommentable ( {
112+ commentable : report ,
113+ text,
114+ currentUser,
115+ report,
116+ commentId,
117+ } )
118+ } ,
119+ deleteCommentOnDay : async ( _parent , { id, traineeId, commentId } , { currentUser } ) => {
120+ const reports = await commentableReports ( traineeId )
121+ const { report, day } = reportDayByDayId ( id , reports )
122+
123+ return deleteCommentOnCommentable ( {
124+ commentable : day ,
125+ currentUser,
126+ report,
127+ commentId,
128+ } )
129+ } ,
130+ deleteCommentOnEntry : async ( _parent , { id, traineeId, commentId } , { currentUser } ) => {
131+ const reports = await commentableReports ( traineeId )
132+ const { report, entry } = reportDayEntryByEntryId ( id , reports )
133+
134+ return deleteCommentOnCommentable ( {
135+ commentable : entry ,
136+ currentUser,
137+ report,
138+ commentId,
139+ } )
140+ } ,
141+ deleteCommentOnReport : async ( _parent , { id, traineeId, commentId } , { currentUser } ) => {
142+ const report = await reportById ( id )
143+
144+ if ( report ?. traineeId !== traineeId ) {
145+ throw new GraphQLError ( t ( 'errors.missingReport' , currentUser . language ) )
146+ }
147+
148+ return deleteCommentOnCommentable ( {
149+ commentable : report ,
150+ currentUser,
151+ report,
152+ commentId,
153+ } )
154+ } ,
155+ publishAllComments : async ( _parent , { id, traineeId } , { currentUser } ) => {
156+ const report = await reportById ( id )
157+
158+ if ( report ?. traineeId !== traineeId ) {
159+ throw new GraphQLError ( t ( 'errors.missingReport' , currentUser . language ) )
160+ }
161+
162+ return publishCommentsOnReport ( {
163+ currentUser,
164+ report,
165+ } )
166+ } ,
74167 } ,
75168}
0 commit comments