From cab057f68378d2cfdb422b7634f7d073ef23d4a0 Mon Sep 17 00:00:00 2001 From: caturbgs Date: Tue, 14 Dec 2021 20:05:13 +0700 Subject: [PATCH] feat: add set status supplier endpoint --- src/users/supplier/supplier.service.ts | 16 ++++++++++++++++ src/users/users.controller.ts | 14 +++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/users/supplier/supplier.service.ts b/src/users/supplier/supplier.service.ts index 54f1b22..491b858 100644 --- a/src/users/supplier/supplier.service.ts +++ b/src/users/supplier/supplier.service.ts @@ -113,6 +113,22 @@ export class SupplierService { return supplierData; } + setStatus = async (id: string, type: string) => { + const supplierData = new Supplier(); + + if (type === 'active') { + supplierData.status = true; + } else { + supplierData.status = false; + } + + await this.connection.transaction(async (manager) => { + await manager.update(Supplier, { id: id }, supplierData); + }); + + return supplierData; + }; + findAllSupplier(page) { return this.supplierRepository.findAndCount({ skip: page * 10, diff --git a/src/users/users.controller.ts b/src/users/users.controller.ts index ff4b8b7..f8e4e9c 100644 --- a/src/users/users.controller.ts +++ b/src/users/users.controller.ts @@ -51,8 +51,20 @@ export class UsersController { }; } - @Put('supplier/:id') + @Get('supplier/:id/:type') async updateSupplier( + @Param('id', ParseUUIDPipe) id: string, + @Param('type') type: string, + ) { + return { + data: await this.supplierService.setStatus(id, type), + statusCode: HttpStatus.CREATED, + message: 'success', + }; + } + + @Put('supplier/:id') + async setStatusSupplier( @Param('id', ParseUUIDPipe) id: string, @Body() updatePartnerDto: UpdateSupplierDto, ) {