@@ -198,23 +198,27 @@ const plugin: FastifyPluginAsync = async (fastify) => {
198198 repositories ,
199199 resultOfToList ( items ) ,
200200 ) ;
201- if ( member ) {
202- websockets . publish (
203- memberItemsTopic ,
204- member . id ,
205- ItemOpFeedbackEvent ( 'update' , ids , items ) ,
206- ) ;
207- }
208- } ) . catch ( ( e : Error ) => {
209- log . error ( e ) ;
210- if ( member ) {
211- websockets . publish (
212- memberItemsTopic ,
213- member . id ,
214- ItemOpFeedbackEvent ( 'update' , ids , { error : e } ) ,
215- ) ;
216- }
217- } ) ;
201+ return items ;
202+ } )
203+ . then ( ( items ) => {
204+ if ( member ) {
205+ websockets . publish (
206+ memberItemsTopic ,
207+ member . id ,
208+ ItemOpFeedbackEvent ( 'update' , ids , items ) ,
209+ ) ;
210+ }
211+ } )
212+ . catch ( ( e : Error ) => {
213+ log . error ( e ) ;
214+ if ( member ) {
215+ websockets . publish (
216+ memberItemsTopic ,
217+ member . id ,
218+ ItemOpFeedbackEvent ( 'update' , ids , { error : e } ) ,
219+ ) ;
220+ }
221+ } ) ;
218222 reply . status ( StatusCodes . ACCEPTED ) ;
219223 return ids ;
220224 } ,
@@ -236,26 +240,30 @@ const plugin: FastifyPluginAsync = async (fastify) => {
236240 const repositories = buildRepositories ( manager ) ;
237241 const items = await itemService . deleteMany ( member , repositories , ids ) ;
238242 await actionItemService . postManyDeleteAction ( request , reply , repositories , items ) ;
239- if ( member ) {
240- websockets . publish (
241- memberItemsTopic ,
242- member . id ,
243- ItemOpFeedbackEvent ( 'delete' , ids , {
244- data : Object . fromEntries ( items . map ( ( i ) => [ i . id , i ] ) ) ,
245- errors : [ ] ,
246- } ) ,
247- ) ;
248- }
249- } ) . catch ( ( e ) => {
250- log . error ( e ) ;
251- if ( member ) {
252- websockets . publish (
253- memberItemsTopic ,
254- member . id ,
255- ItemOpFeedbackEvent ( 'delete' , ids , { error : e } ) ,
256- ) ;
257- }
258- } ) ;
243+ return items ;
244+ } )
245+ . then ( ( items ) => {
246+ if ( member ) {
247+ websockets . publish (
248+ memberItemsTopic ,
249+ member . id ,
250+ ItemOpFeedbackEvent ( 'delete' , ids , {
251+ data : Object . fromEntries ( items . map ( ( i ) => [ i . id , i ] ) ) ,
252+ errors : [ ] ,
253+ } ) ,
254+ ) ;
255+ }
256+ } )
257+ . catch ( ( e ) => {
258+ log . error ( e ) ;
259+ if ( member ) {
260+ websockets . publish (
261+ memberItemsTopic ,
262+ member . id ,
263+ ItemOpFeedbackEvent ( 'delete' , ids , { error : e } ) ,
264+ ) ;
265+ }
266+ } ) ;
259267 reply . status ( StatusCodes . ACCEPTED ) ;
260268 return ids ;
261269 } ,
@@ -277,7 +285,6 @@ const plugin: FastifyPluginAsync = async (fastify) => {
277285 await actionItemService . postManyMoveAction ( request , reply , repositories , items ) ;
278286 return items ;
279287 } )
280- // TODO: do the same for the copy and the others ?
281288 . then ( ( items ) => {
282289 if ( member ) {
283290 websockets . publish (
@@ -324,26 +331,30 @@ const plugin: FastifyPluginAsync = async (fastify) => {
324331 parentId,
325332 } ) ;
326333 await actionItemService . postManyCopyAction ( request , reply , repositories , items ) ;
327- if ( member ) {
328- websockets . publish (
329- memberItemsTopic ,
330- member . id ,
331- ItemOpFeedbackEvent ( 'copy' , ids , {
332- data : Object . fromEntries ( items . map ( ( i ) => [ i . id , i ] ) ) ,
333- errors : [ ] ,
334- } ) ,
335- ) ;
336- }
337- } ) . catch ( ( e ) => {
338- log . error ( e ) ;
339- if ( member ) {
340- websockets . publish (
341- memberItemsTopic ,
342- member . id ,
343- ItemOpFeedbackEvent ( 'copy' , ids , { error : e } ) ,
344- ) ;
345- }
346- } ) ;
334+ return items ;
335+ } )
336+ . then ( ( items ) => {
337+ if ( member ) {
338+ websockets . publish (
339+ memberItemsTopic ,
340+ member . id ,
341+ ItemOpFeedbackEvent ( 'copy' , ids , {
342+ data : Object . fromEntries ( items . map ( ( i ) => [ i . id , i ] ) ) ,
343+ errors : [ ] ,
344+ } ) ,
345+ ) ;
346+ }
347+ } )
348+ . catch ( ( e ) => {
349+ log . error ( e ) ;
350+ if ( member ) {
351+ websockets . publish (
352+ memberItemsTopic ,
353+ member . id ,
354+ ItemOpFeedbackEvent ( 'copy' , ids , { error : e } ) ,
355+ ) ;
356+ }
357+ } ) ;
347358 reply . status ( StatusCodes . ACCEPTED ) ;
348359 return ids ;
349360 } ,
0 commit comments