From a8aebe72884015330ad7e4b3ed63d3db2d739e90 Mon Sep 17 00:00:00 2001 From: bahram rajabi Date: Thu, 27 Jun 2024 22:55:27 +0330 Subject: [PATCH] add change shipment way and order status method for total orders --- .../totalOrders/dto/change-orderstatus.dto.ts | 6 ++ .../totalOrders/dto/change-shipmentway.dto.ts | 6 ++ .../src/admin/totalOrders/dto/index.ts | 2 + .../totalOrders/total-order.controller.ts | 31 ++++++++ .../admin/totalOrders/total-order.module.ts | 4 + .../admin/totalOrders/total-order.service.ts | 73 +++++++++++++++++++ apps/main/src/sql/core-v1.sql | 17 +++++ 7 files changed, 139 insertions(+) create mode 100644 apps/e-commerce/src/admin/totalOrders/dto/change-orderstatus.dto.ts create mode 100644 apps/e-commerce/src/admin/totalOrders/dto/change-shipmentway.dto.ts diff --git a/apps/e-commerce/src/admin/totalOrders/dto/change-orderstatus.dto.ts b/apps/e-commerce/src/admin/totalOrders/dto/change-orderstatus.dto.ts new file mode 100644 index 00000000..91125729 --- /dev/null +++ b/apps/e-commerce/src/admin/totalOrders/dto/change-orderstatus.dto.ts @@ -0,0 +1,6 @@ +import { IsNumber } from 'class-validator'; + +export class ChangeOrderStatusDto { + @IsNumber() + orderStatusId: number; +} diff --git a/apps/e-commerce/src/admin/totalOrders/dto/change-shipmentway.dto.ts b/apps/e-commerce/src/admin/totalOrders/dto/change-shipmentway.dto.ts new file mode 100644 index 00000000..dbd1cb45 --- /dev/null +++ b/apps/e-commerce/src/admin/totalOrders/dto/change-shipmentway.dto.ts @@ -0,0 +1,6 @@ +import { IsNumber, IsOptional, IsString } from 'class-validator'; + +export class ChangeShipmentWayDto { + @IsNumber() + shipmentWayId: number; +} diff --git a/apps/e-commerce/src/admin/totalOrders/dto/index.ts b/apps/e-commerce/src/admin/totalOrders/dto/index.ts index d53ff985..077f0f9f 100644 --- a/apps/e-commerce/src/admin/totalOrders/dto/index.ts +++ b/apps/e-commerce/src/admin/totalOrders/dto/index.ts @@ -1 +1,3 @@ export * from './post-process.dto'; +export * from './change-shipmentway.dto'; +export * from './change-orderstatus.dto'; diff --git a/apps/e-commerce/src/admin/totalOrders/total-order.controller.ts b/apps/e-commerce/src/admin/totalOrders/total-order.controller.ts index 77414f22..36ca25e6 100644 --- a/apps/e-commerce/src/admin/totalOrders/total-order.controller.ts +++ b/apps/e-commerce/src/admin/totalOrders/total-order.controller.ts @@ -6,12 +6,14 @@ import { } from '@nestjs/swagger'; import { TotalOrderService } from './total-order.service'; import { + Body, Controller, Delete, Get, HttpCode, HttpStatus, Param, + Patch, Query, UseGuards, UseInterceptors, @@ -23,6 +25,7 @@ import { User } from '@rahino/database/models/core/user.entity'; import { PermissionGuard } from '@rahino/permission-checker/guard'; import { CheckPermission } from '@rahino/permission-checker/decorator'; import { ListFilter } from '@rahino/query-filter'; +import { ChangeOrderStatusDto, ChangeShipmentWayDto } from './dto'; @ApiTags('Total-Orders') @UseGuards(JwtGuard, PermissionGuard) @@ -86,4 +89,32 @@ export class TotalOrderController { async removeById(@Param('id') id: bigint, @GetUser() user: User) { return await this.service.removeById(id); } + + @ApiOperation({ description: 'change shipment way order by given id' }) + @CheckPermission({ + permissionSymbol: 'ecommerce.admin.totalorders.changeshipmentway', + }) + @Patch('/changeShipmentWay/:id') + @HttpCode(HttpStatus.OK) + async changeShipmentWay( + @Param('id') id: bigint, + @GetUser() user: User, + @Body() dto: ChangeShipmentWayDto, + ) { + return await this.service.changeShipmentWay(id, dto); + } + + @ApiOperation({ description: 'change order status by given id' }) + @CheckPermission({ + permissionSymbol: 'ecommerce.admin.totalorders.changeorderstatus', + }) + @Patch('/changeOrderStatus/:id') + @HttpCode(HttpStatus.OK) + async changeOrderStatus( + @Param('id') id: bigint, + @GetUser() user: User, + @Body() dto: ChangeOrderStatusDto, + ) { + return await this.service.changeOrderStatus(id, dto); + } } diff --git a/apps/e-commerce/src/admin/totalOrders/total-order.module.ts b/apps/e-commerce/src/admin/totalOrders/total-order.module.ts index 96d4ac1e..8334eded 100644 --- a/apps/e-commerce/src/admin/totalOrders/total-order.module.ts +++ b/apps/e-commerce/src/admin/totalOrders/total-order.module.ts @@ -13,6 +13,8 @@ import { ECPaymentGateway } from '@rahino/database/models/ecommerce-eav/ec-payme import { RoleUtilModule } from '@rahino/core/user/role-util/role-util.module'; import { UserVendorModule } from '@rahino/ecommerce/user/vendor/user-vendor.module'; import { FinalizedPaymentModule } from '@rahino/ecommerce/user/payment/util/finalized-payment/finalized-payment.module'; +import { ECOrderStatus } from '@rahino/database/models/ecommerce-eav/ec-order-status.entity'; +import { ECOrderShipmentWay } from '@rahino/database/models/ecommerce-eav/ec-order-shipmentway.entity'; @Module({ imports: [ @@ -23,6 +25,8 @@ import { FinalizedPaymentModule } from '@rahino/ecommerce/user/payment/util/fina ECOrderDetail, ECPayment, ECPaymentGateway, + ECOrderStatus, + ECOrderShipmentWay, ]), SequelizeModule, UtilOrderModule, diff --git a/apps/e-commerce/src/admin/totalOrders/total-order.service.ts b/apps/e-commerce/src/admin/totalOrders/total-order.service.ts index 4030bb13..d54c25e1 100644 --- a/apps/e-commerce/src/admin/totalOrders/total-order.service.ts +++ b/apps/e-commerce/src/admin/totalOrders/total-order.service.ts @@ -1,5 +1,6 @@ import { BadRequestException, + ForbiddenException, Injectable, InternalServerErrorException, NotFoundException, @@ -23,6 +24,9 @@ import { RoleUtilService } from '@rahino/core/user/role-util/role-util.service'; import { UserVendorService } from '@rahino/ecommerce/user/vendor/user-vendor.service'; import { OrderUtilService } from '../utilOrder/service/order-util.service'; import { FinalizedPaymentService } from '@rahino/ecommerce/user/payment/util/finalized-payment/finalized-payment.service'; +import { ChangeOrderStatusDto, ChangeShipmentWayDto } from './dto'; +import { ECOrderStatus } from '@rahino/database/models/ecommerce-eav/ec-order-status.entity'; +import { ECOrderShipmentWay } from '@rahino/database/models/ecommerce-eav/ec-order-shipmentway.entity'; @Injectable() export class TotalOrderService { @@ -37,6 +41,11 @@ export class TotalOrderService { private readonly paymentRepository: typeof ECPayment, @InjectModel(ECPaymentGateway) private readonly paymentGatewayRepository: typeof ECPaymentGateway, + @InjectModel(ECOrderStatus) + private readonly orderStatusRepository: typeof ECOrderStatus, + @InjectModel(ECOrderShipmentWay) + private readonly orderShipmentWayRepository: typeof ECOrderShipmentWay, + private orderQueryBuilder: OrderQueryBuilder, private readonly snapPayService: SnapPayService, private readonly roleUtilService: RoleUtilService, @@ -574,4 +583,68 @@ export class TotalOrderService { result: 'ok', }; } + + async changeOrderStatus(id: bigint, dto: ChangeOrderStatusDto) { + const orderStatus = await this.orderStatusRepository.findOne( + new QueryOptionsBuilder().filter({ id: dto.orderStatusId }).build(), + ); + if (!orderStatus) { + throw new ForbiddenException( + "you don't have permitted to operate this function", + ); + } + let order = await this.repository.findOne( + new QueryOptionsBuilder() + .filter({ id: id }) + .filter( + Sequelize.where( + Sequelize.fn('isnull', Sequelize.col('ECOrder.isDeleted'), 0), + { + [Op.eq]: 0, + }, + ), + ) + .build(), + ); + if (!order) { + throw new NotFoundException('the order with this given id not founded!'); + } + order.orderStatusId = dto.orderStatusId; + order = await order.save(); + return { + result: order, + }; + } + + async changeShipmentWay(id: bigint, dto: ChangeShipmentWayDto) { + const shipmentway = await this.orderShipmentWayRepository.findOne( + new QueryOptionsBuilder().filter({ id: dto.shipmentWayId }).build(), + ); + if (!shipmentway) { + throw new ForbiddenException( + "you don't have permitted to operate this function", + ); + } + let order = await this.repository.findOne( + new QueryOptionsBuilder() + .filter({ id: id }) + .filter( + Sequelize.where( + Sequelize.fn('isnull', Sequelize.col('ECOrder.isDeleted'), 0), + { + [Op.eq]: 0, + }, + ), + ) + .build(), + ); + if (!order) { + throw new NotFoundException('the order with this given id not founded!'); + } + order.orderShipmentWayId = dto.shipmentWayId; + order = await order.save(); + return { + result: order, + }; + } } diff --git a/apps/main/src/sql/core-v1.sql b/apps/main/src/sql/core-v1.sql index 7b87a6ae..b56c6837 100644 --- a/apps/main/src/sql/core-v1.sql +++ b/apps/main/src/sql/core-v1.sql @@ -12055,6 +12055,9 @@ BEGIN DECLARE @permissionSymbolGetOne nvarchar(512) = @groupName + '.getone'; DECLARE @permissionSymbolRemoveDetail nvarchar(512) = @groupName + '.removedetail'; DECLARE @permissionSymbolDecreaseDetail nvarchar(512) = @groupName + '.decreasedetail'; + DECLARE @permissionSymbolChangeShipmentWay nvarchar(512) = @groupName + '.changeshipmentway'; + DECLARE @permissionSymbolChangeOrderStatus nvarchar(512) = @groupName + '.changeorderstatus'; + DECLARE @permissionSymbolDelete nvarchar(512) = @groupName + '.delete'; @@ -12091,6 +12094,20 @@ BEGIN OUTPUT inserted.id INTO @PermissionTemp(permissionId) SELECT 'DecreaseDetail_' + @entityName, @permissionSymbolDecreaseDetail, @groupId, GETDATE(), GETDATE() + + + + INSERT INTO Permissions(permissionName ,permissionSymbol,permissionGroupId, createdAt, updatedAt) + OUTPUT inserted.id INTO @PermissionTemp(permissionId) + SELECT 'ChangeShipmentWay_' + @entityName, @permissionSymbolChangeShipmentWay, @groupId, GETDATE(), GETDATE() + + + + + INSERT INTO Permissions(permissionName ,permissionSymbol,permissionGroupId, createdAt, updatedAt) + OUTPUT inserted.id INTO @PermissionTemp(permissionId) + SELECT 'ChangeOrderStatus_' + @entityName, @permissionSymbolChangeOrderStatus, @groupId, GETDATE(), GETDATE() + INSERT INTO Permissions(permissionName ,permissionSymbol,permissionGroupId, createdAt, updatedAt)