print invoice field in order
deploy to danak / build_and_deploy (push) Has been cancelled

This commit is contained in:
2026-07-01 12:26:55 +03:30
parent 2a633a28b4
commit bd084e2e63
7 changed files with 45 additions and 2 deletions
+10
View File
@@ -4326,6 +4326,16 @@
"nullable": true, "nullable": true,
"mappedType": "text" "mappedType": "text"
}, },
"print_invoice": {
"name": "print_invoice",
"type": "boolean",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"default": "false",
"mappedType": "boolean"
},
"table_number": { "table_number": {
"name": "table_number", "name": "table_number",
"type": "varchar(255)", "type": "varchar(255)",
@@ -0,0 +1,13 @@
import { Migration } from '@mikro-orm/migrations';
export class Migration20260701083547_addPrintInvoiceToOrders extends Migration {
override async up(): Promise<void> {
this.addSql(`alter table "orders" add column "print_invoice" boolean not null default false;`);
}
override async down(): Promise<void> {
this.addSql(`alter table "orders" drop column "print_invoice";`);
}
}
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger'; import { ApiProperty } from '@nestjs/swagger';
import { IsArray, IsNotEmpty, IsObject, IsOptional, IsString } from 'class-validator'; import { IsArray, IsBoolean, IsNotEmpty, IsObject, IsOptional, IsString } from 'class-validator';
import { SetCarDeliveryDto } from './set-car-delivery.dto'; import { SetCarDeliveryDto } from './set-car-delivery.dto';
@@ -33,6 +33,16 @@ export class SetAllCartParmsDto {
@IsString() @IsString()
tableNumber?: string; tableNumber?: string;
@ApiProperty({
description: 'Whether the customer wants a printed invoice',
required: false,
default: false,
example: false,
})
@IsOptional()
@IsBoolean()
printInvoice?: boolean;
@ApiProperty() @ApiProperty()
@IsOptional() @IsOptional()
@IsObject() @IsObject()
@@ -19,6 +19,7 @@ export interface Cart {
paymentMethodId?: string; paymentMethodId?: string;
deliveryMethodId?: string; deliveryMethodId?: string;
description?: string; description?: string;
printInvoice?: boolean;
tableNumber?: string; tableNumber?: string;
attachments?: string[]; attachments?: string[];
paymentDesc?: string; paymentDesc?: string;
+5 -1
View File
@@ -28,7 +28,7 @@ export class CartService {
* Set all cart parameters at once * Set all cart parameters at once
*/ */
async setAllCartParams(userId: string, restaurantId: string, params: SetAllCartParmsDto): Promise<Cart> { async setAllCartParams(userId: string, restaurantId: string, params: SetAllCartParmsDto): Promise<Cart> {
const { deliveryMethodId, paymentMethodId, addressId, carAddress, description, tableNumber, attachments, paymentDesc } = params; const { deliveryMethodId, paymentMethodId, addressId, carAddress, description, tableNumber, printInvoice, attachments, paymentDesc } = params;
// get existing cart (or throw) // get existing cart (or throw)
const cart = await this.findOneOrFail(userId, restaurantId); const cart = await this.findOneOrFail(userId, restaurantId);
@@ -117,6 +117,10 @@ export class CartService {
cart.description = description; cart.description = description;
} }
if (printInvoice !== undefined) {
cart.printInvoice = printInvoice;
}
if (paymentMethod.method === PaymentMethodEnum.CreditCard) { if (paymentMethod.method === PaymentMethodEnum.CreditCard) {
this.validationService.assertCreditCardPaymentDetails(paymentMethod, paymentDesc, attachments); this.validationService.assertCreditCardPaymentDetails(paymentMethod, paymentDesc, attachments);
cart.paymentDesc = paymentDesc?.trim() || undefined; cart.paymentDesc = paymentDesc?.trim() || undefined;
@@ -92,6 +92,9 @@ export class Order extends BaseEntity {
@Property({ type: 'text', nullable: true }) @Property({ type: 'text', nullable: true })
description?: string; description?: string;
@Property({ type: 'boolean', default: false })
printInvoice: boolean = false;
@Property({ nullable: true }) @Property({ nullable: true })
tableNumber?: string; tableNumber?: string;
@@ -87,6 +87,7 @@ export class OrdersService {
total: cart.total || 0, total: cart.total || 0,
totalItems: cart.totalItems || 0, totalItems: cart.totalItems || 0,
description: cart.description, description: cart.description,
printInvoice: cart.printInvoice ?? false,
tableNumber: cart.tableNumber, tableNumber: cart.tableNumber,
status: OrderStatus.PENDING_PAYMENT, status: OrderStatus.PENDING_PAYMENT,
history: [{ status: OrderStatus.PENDING_PAYMENT, changedAt: new Date() }], history: [{ status: OrderStatus.PENDING_PAYMENT, changedAt: new Date() }],
@@ -199,6 +200,7 @@ export class OrdersService {
total, total,
totalItems, totalItems,
description: dto.description, description: dto.description,
printInvoice: false,
tableNumber: dto.tableNumber, tableNumber: dto.tableNumber,
status: OrderStatus.PENDING_PAYMENT, status: OrderStatus.PENDING_PAYMENT,
history: [{ status: OrderStatus.PENDING_PAYMENT, changedAt: new Date() }], history: [{ status: OrderStatus.PENDING_PAYMENT, changedAt: new Date() }],