Skip to content

Commit

Permalink
add change shipment way and order status method for total orders
Browse files Browse the repository at this point in the history
  • Loading branch information
bahram1249 committed Jun 27, 2024
1 parent b5bfeb5 commit a8aebe7
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { IsNumber } from 'class-validator';

export class ChangeOrderStatusDto {
@IsNumber()
orderStatusId: number;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { IsNumber, IsOptional, IsString } from 'class-validator';

export class ChangeShipmentWayDto {
@IsNumber()
shipmentWayId: number;
}
2 changes: 2 additions & 0 deletions apps/e-commerce/src/admin/totalOrders/dto/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './post-process.dto';
export * from './change-shipmentway.dto';
export * from './change-orderstatus.dto';
31 changes: 31 additions & 0 deletions apps/e-commerce/src/admin/totalOrders/total-order.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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);
}
}
4 changes: 4 additions & 0 deletions apps/e-commerce/src/admin/totalOrders/total-order.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -23,6 +25,8 @@ import { FinalizedPaymentModule } from '@rahino/ecommerce/user/payment/util/fina
ECOrderDetail,
ECPayment,
ECPaymentGateway,
ECOrderStatus,
ECOrderShipmentWay,
]),
SequelizeModule,
UtilOrderModule,
Expand Down
73 changes: 73 additions & 0 deletions apps/e-commerce/src/admin/totalOrders/total-order.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
BadRequestException,
ForbiddenException,
Injectable,
InternalServerErrorException,
NotFoundException,
Expand All @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
};
}
}
17 changes: 17 additions & 0 deletions apps/main/src/sql/core-v1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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';


Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a8aebe7

Please sign in to comment.