@@ -9,8 +9,12 @@ export interface IPurchaseLineItemTransaction {
99 createOrUpdatePurchaseLineItems ( payload : CreateOrChangePurchaseLineItemsDTO ) : Promise < PurchaseLineItem [ ] > ;
1010 getPurchaseLineItem ( id : string ) : Promise < PurchaseLineItem | null > ;
1111 getPurchaseLineItemsForPurchase ( purchaseId : string ) : Promise < PurchaseLineItem [ ] > ;
12- updatePurchaseLineItemCategory ( id : string , category : string , removeCategory : boolean ) : Promise < PurchaseLineItem > ;
13- updatePurchaseLineItemType ( id : string , type : PurchaseLineItemType ) : Promise < PurchaseLineItem > ;
12+ updatePurchaseLineItemCategory (
13+ ids : string [ ] ,
14+ category : string ,
15+ removeCategory : boolean
16+ ) : Promise < PurchaseLineItem [ ] > ;
17+ updatePurchaseLineItemType ( ids : string [ ] , type : PurchaseLineItemType ) : Promise < PurchaseLineItem [ ] > ;
1418}
1519
1620export class PurchaseLineItemTransaction implements IPurchaseLineItemTransaction {
@@ -68,39 +72,39 @@ export class PurchaseLineItemTransaction implements IPurchaseLineItemTransaction
6872 }
6973
7074 async updatePurchaseLineItemCategory (
71- id : string ,
75+ ids : string [ ] ,
7276 category : string ,
7377 removeCategory : boolean
74- ) : Promise < PurchaseLineItem > {
78+ ) : Promise < PurchaseLineItem [ ] > {
7579 const qb = this . db . createQueryBuilder ( ) . update ( PurchaseLineItem ) ;
7680
7781 if ( removeCategory ) {
78- qb . set ( { category : null } ) . where ( "id = :id AND category = :category" , { id , category } ) ;
82+ qb . set ( { category : null } ) . where ( "id IN (:...ids) AND category = :category" , { ids , category } ) ;
7983 } else {
80- qb . set ( { category } ) . where ( "id = :id " , { id } ) ;
84+ qb . set ( { category } ) . where ( "id IN (:...ids) " , { ids } ) ;
8185 }
8286
8387 const response = await qb . returning ( "*" ) . execute ( ) ;
8488
8589 if ( ! response ) {
8690 throw Boom . notFound ( "Error updating the purchase line item category" ) ;
8791 }
88- return response . raw [ 0 ] ;
92+ return response . raw ;
8993 }
9094
91- async updatePurchaseLineItemType ( id : string , type : PurchaseLineItemType ) : Promise < PurchaseLineItem > {
95+ async updatePurchaseLineItemType ( ids : string [ ] , type : PurchaseLineItemType ) : Promise < PurchaseLineItem [ ] > {
9296 const response = await this . db
9397 . createQueryBuilder ( )
9498 . update ( PurchaseLineItem )
9599 . set ( { type : type } )
96- . where ( { id } )
100+ . where ( "id IN (:...ids)" , { ids } )
97101 . returning ( "*" )
98102 . execute ( ) ;
99103
100104 if ( ! response || response . affected === 0 ) {
101105 throw Boom . notFound ( "Error updating the purchase line item type" ) ;
102106 }
103107
104- return response . raw [ 0 ] ;
108+ return response . raw ;
105109 }
106110}
0 commit comments