@@ -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')
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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<CashShift> {
|
||||
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<CashShift> {
|
||||
const shift = await this.em.findOne(
|
||||
CashShift,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user