Skip to content

Commit

Permalink
feat: get remaining quantity of products
Browse files Browse the repository at this point in the history
  • Loading branch information
daihiep-swe committed Aug 12, 2023
1 parent 4fbb26e commit d992ba2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 56 deletions.
20 changes: 0 additions & 20 deletions src/batches/batches.controller.spec.ts

This file was deleted.

5 changes: 5 additions & 0 deletions src/batches/batches.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,9 @@ export class BatchesController {
getAvailableQuantity(@Payload() availableDto: any) {
return this.batchesService.getAvailableQuantity(availableDto);
}

@MessagePattern('batches.get_remaining_quantity')
getRemainingQuantity(@Payload() id: string) {
return this.batchesService.getRemainingQuantity(id);
}
}
18 changes: 0 additions & 18 deletions src/batches/batches.service.spec.ts

This file was deleted.

17 changes: 17 additions & 0 deletions src/batches/batches.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,23 @@ export class BatchesService {
return products;
}

async getRemainingQuantity(id: string) {
console.log('getRemainingQuantity', id);
const batches = await this.batchRepository.find({
where: {
product_id: id,
expiry_date: MoreThan(moment().format('YYYY-MM-DD')),
},
});

const available = batches.reduce(
(prev, curr) => prev + (curr.import_quantity - curr.sold),
0,
);

return available;
}

async getAvailableQuantity2(branch_id: string, product_ids: string[]) {
// const { product_id, branch_id } = availableDto[0];

Expand Down
18 changes: 0 additions & 18 deletions src/products/products.service.spec.ts

This file was deleted.

0 comments on commit d992ba2

Please sign in to comment.