From b9d7a4adc3492745c951849e5c12e58d22361e32 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Tue, 14 Jul 2026 16:27:53 +0330 Subject: [PATCH] shift --- .../controllers/cash-shifts.controller.ts | 15 +++++++++ .../orders/dto/update-cash-shift.dto.ts | 17 ++++++++++ .../orders/providers/cash-shifts.service.ts | 31 +++++++++++++++++++ .../controllers/payments.controller.ts | 2 +- 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 src/modules/orders/dto/update-cash-shift.dto.ts diff --git a/src/modules/orders/controllers/cash-shifts.controller.ts b/src/modules/orders/controllers/cash-shifts.controller.ts index 67f139c..80046e7 100644 --- a/src/modules/orders/controllers/cash-shifts.controller.ts +++ b/src/modules/orders/controllers/cash-shifts.controller.ts @@ -9,6 +9,7 @@ import { Permission } from 'src/common/enums/permission.enum'; import { OpenCashShiftDto } from '../dto/open-cash-shift.dto'; import { CloseCashShiftDto } from '../dto/close-cash-shift.dto'; import { FindCashShiftsDto } from '../dto/find-cash-shifts.dto'; +import { UpdateCashShiftDto } from '../dto/update-cash-shift.dto'; @ApiTags('cash-shifts') @ApiBearerAuth() @@ -25,6 +26,20 @@ export class CashShiftsController { return this.cashShiftsService.openShift(restId, adminId, dto); } + @UseGuards(AdminAuthGuard) + @Permissions(Permission.MANAGE_ORDERS) + @Patch('admin/cash-shifts/:shiftId') + @ApiOperation({ summary: 'Update a cash shift' }) + @ApiParam({ name: 'shiftId', description: 'Cash shift ID' }) + @ApiBody({ type: UpdateCashShiftDto }) + updateShift( + @Param('shiftId') shiftId: string, + @RestId() restId: string, + @Body() dto: UpdateCashShiftDto, + ) { + return this.cashShiftsService.updateShift(shiftId, restId, dto); + } + @UseGuards(AdminAuthGuard) @Permissions(Permission.MANAGE_ORDERS) @Patch('admin/cash-shifts/:shiftId/close') diff --git a/src/modules/orders/dto/update-cash-shift.dto.ts b/src/modules/orders/dto/update-cash-shift.dto.ts new file mode 100644 index 0000000..3d28a12 --- /dev/null +++ b/src/modules/orders/dto/update-cash-shift.dto.ts @@ -0,0 +1,17 @@ +import { ApiPropertyOptional } from '@nestjs/swagger'; +import { Type } from 'class-transformer'; +import { IsNumber, IsOptional, IsString, Min } from 'class-validator'; + +export class UpdateCashShiftDto { + @ApiPropertyOptional({ description: 'Opening cash amount in drawer', minimum: 0 }) + @Type(() => Number) + @IsOptional() + @IsNumber() + @Min(0) + openingAmount?: number; + + @ApiPropertyOptional() + @IsOptional() + @IsString() + notes?: string; +} diff --git a/src/modules/orders/providers/cash-shifts.service.ts b/src/modules/orders/providers/cash-shifts.service.ts index ac79331..07dfc50 100644 --- a/src/modules/orders/providers/cash-shifts.service.ts +++ b/src/modules/orders/providers/cash-shifts.service.ts @@ -6,6 +6,7 @@ import { CashShiftRepository } from '../repositories/cash-shift.repository'; import { OpenCashShiftDto } from '../dto/open-cash-shift.dto'; import { CloseCashShiftDto } from '../dto/close-cash-shift.dto'; import { FindCashShiftsDto } from '../dto/find-cash-shifts.dto'; +import { UpdateCashShiftDto } from '../dto/update-cash-shift.dto'; import { Admin } from '../../admin/entities/admin.entity'; import { Restaurant } from '../../restaurants/entities/restaurant.entity'; import { Order } from '../entities/order.entity'; @@ -53,6 +54,36 @@ export class CashShiftsService { return shift; } + async updateShift(shiftId: string, restaurantId: string, dto: UpdateCashShiftDto): Promise { + const shift = await this.em.findOne( + CashShift, + { id: shiftId, restaurant: { id: restaurantId } }, + { populate: ['admin', 'restaurant'] }, + ); + + if (!shift) { + throw new NotFoundException(CashShiftMessage.NOT_FOUND); + } + + if (dto.openingAmount !== undefined) { + shift.openingAmount = dto.openingAmount; + + if (shift.status === CashShiftStatus.CLOSED && shift.countedAmount !== null) { + const summary = await this.calculateShiftSummary(shiftId, restaurantId); + shift.expectedAmount = summary.expectedAmount; + shift.differenceAmount = Number(shift.countedAmount) - summary.expectedAmount; + shift.ordersCount = summary.ordersCount; + } + } + + if (dto.notes !== undefined) { + shift.notes = dto.notes; + } + + await this.em.persistAndFlush(shift); + return shift; + } + async closeShift(shiftId: string, restaurantId: string, dto: CloseCashShiftDto): Promise { const shift = await this.em.findOne( CashShift, diff --git a/src/modules/payments/controllers/payments.controller.ts b/src/modules/payments/controllers/payments.controller.ts index dc82151..6fed964 100644 --- a/src/modules/payments/controllers/payments.controller.ts +++ b/src/modules/payments/controllers/payments.controller.ts @@ -127,7 +127,7 @@ export class PaymentsController { @Post('admin/payments/verify/:paymentId') @ApiOperation({ summary: 'Verify cash/creditcard payment ' }) @ApiParam({ name: 'paymentId', type: 'string', description: 'Payment ID' }) - verifyCashPayment(@Param('paymentId') paymentId: string) { + verifyCashCreditPayment(@Param('paymentId') paymentId: string) { return this.paymentsService.verifyCashAnCreditPayment(paymentId); }