@@ -133,15 +133,15 @@ export const createInvoiceController = async (req: ConfacRequest, res: Response)
133
133
. find ( { _id : { $in : linkedInvoiceIds } } )
134
134
. toArray ( ) ;
135
135
136
- linkedInvoices . forEach ( invoice => {
137
- invoice . creditNotas = [ ...( invoice . creditNotas || [ ] ) , createdInvoice . _id ] ;
138
- emitEntityEvent ( req , SocketEventTypes . EntityUpdated , CollectionNames . INVOICES , invoice . _id , invoice , 'everyone' ) ;
139
- } ) ;
140
-
141
136
await req . db . collection < IInvoice > ( CollectionNames . INVOICES ) . updateMany (
142
137
{ _id : { $in : linkedInvoiceIds } } ,
143
138
{ $push : { creditNotas : createdInvoice . _id . toString ( ) } }
144
139
) ;
140
+
141
+ linkedInvoices . forEach ( invoice => {
142
+ invoice . creditNotas = [ ...( invoice . creditNotas || [ ] ) , createdInvoice . _id ] ;
143
+ emitEntityEvent ( req , SocketEventTypes . EntityUpdated , CollectionNames . INVOICES , invoice . _id , invoice , 'everyone' ) ;
144
+ } ) ;
145
145
}
146
146
147
147
return res . send ( createdInvoice ) ;
@@ -258,15 +258,15 @@ export const deleteInvoiceController = async (req: ConfacRequest, res: Response)
258
258
. find ( { _id : { $in : linkedInvoiceIds } } )
259
259
. toArray ( ) ;
260
260
261
- linkedInvoices . forEach ( toUpdate => {
262
- toUpdate . creditNotas = toUpdate . creditNotas . filter ( x => x !== invoice . _id ) ;
263
- emitEntityEvent ( req , SocketEventTypes . EntityUpdated , CollectionNames . INVOICES , toUpdate . _id , toUpdate , 'everyone' ) ;
264
- } ) ;
265
-
266
261
await req . db . collection < IInvoice > ( CollectionNames . INVOICES ) . updateMany (
267
262
{ _id : { $in : linkedInvoiceIds } } ,
268
263
{ $pull : { creditNotas : invoice . _id . toString ( ) } }
269
264
) ;
265
+
266
+ linkedInvoices . forEach ( toUpdate => {
267
+ toUpdate . creditNotas = toUpdate . creditNotas . filter ( x => x !== invoice . _id . toString ( ) ) ;
268
+ emitEntityEvent ( req , SocketEventTypes . EntityUpdated , CollectionNames . INVOICES , toUpdate . _id , toUpdate , 'everyone' ) ;
269
+ } ) ;
270
270
}
271
271
272
272
await req . db . collection ( CollectionNames . INVOICES ) . findOneAndDelete ( { _id : new ObjectID ( invoiceId ) } ) ;
0 commit comments