From caaeb0d34ad388fefe646c6e149aa1b70e33bb5b Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Sun, 7 Jun 2026 16:17:49 +0330 Subject: [PATCH] add card to card payment method --- database/migrations/.snapshot-postgres.json | 215 ++++++++---------- ...4425_add_card_number_to_payment_methods.ts | 13 ++ .../payments/dto/create-payment-method.dto.ts | 5 + .../entities/payment-method.entity.ts | 3 + src/modules/payments/interface/payment.ts | 1 + src/seeders/data/payment-methods.data.ts | 1 + src/seeders/payment-methods.seeder.ts | 7 +- 7 files changed, 121 insertions(+), 124 deletions(-) create mode 100644 database/migrations/Migration20260607124425_add_card_number_to_payment_methods.ts diff --git a/database/migrations/.snapshot-postgres.json b/database/migrations/.snapshot-postgres.json index 1bd60f9..c82541f 100644 --- a/database/migrations/.snapshot-postgres.json +++ b/database/migrations/.snapshot-postgres.json @@ -976,6 +976,16 @@ "primary": false, "unique": false }, + { + "keyName": "restaurants_slug_index", + "columnNames": [ + "slug" + ], + "composite": false, + "constraint": false, + "primary": false, + "unique": false + }, { "keyName": "restaurants_slug_is_active_index", "columnNames": [ @@ -987,16 +997,6 @@ "primary": false, "unique": false }, - { - "keyName": "restaurants_is_active_index", - "columnNames": [ - "is_active" - ], - "composite": false, - "constraint": false, - "primary": false, - "unique": false - }, { "keyName": "restaurants_pkey", "columnNames": [ @@ -1076,7 +1076,8 @@ "enumItems": [ "Online", "Cash", - "Wallet" + "Wallet", + "Cart" ], "mappedType": "enum" }, @@ -1102,6 +1103,16 @@ "length": 255, "mappedType": "string" }, + "card_number": { + "name": "card_number", + "type": "varchar(255)", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 255, + "mappedType": "string" + }, "enabled": { "name": "enabled", "type": "boolean", @@ -1156,6 +1167,16 @@ "primary": false, "unique": false }, + { + "keyName": "payment_methods_restaurant_id_index", + "columnNames": [ + "restaurant_id" + ], + "composite": false, + "constraint": false, + "primary": false, + "unique": false + }, { "keyName": "payment_methods_restaurant_id_enabled_index", "columnNames": [ @@ -2146,6 +2167,17 @@ "primary": false, "unique": false }, + { + "keyName": "categories_restaurant_id_id_index", + "columnNames": [ + "restaurant_id", + "id" + ], + "composite": true, + "constraint": false, + "primary": false, + "unique": false + }, { "keyName": "categories_restaurant_id_is_active_index", "columnNames": [ @@ -2419,27 +2451,6 @@ "primary": false, "unique": false }, - { - "keyName": "foods_is_active_index", - "columnNames": [ - "is_active" - ], - "composite": false, - "constraint": false, - "primary": false, - "unique": false - }, - { - "keyName": "foods_category_id_is_active_index", - "columnNames": [ - "category_id", - "is_active" - ], - "composite": true, - "constraint": false, - "primary": false, - "unique": false - }, { "keyName": "foods_restaurant_id_is_active_index", "columnNames": [ @@ -2892,17 +2903,6 @@ "primary": false, "unique": false }, - { - "keyName": "admin_roles_admin_id_restaurant_id_unique", - "columnNames": [ - "admin_id", - "restaurant_id" - ], - "composite": true, - "constraint": true, - "primary": false, - "unique": true - }, { "keyName": "admin_roles_pkey", "columnNames": [ @@ -3140,6 +3140,16 @@ "primary": false, "unique": false }, + { + "keyName": "schedules_rest_id_index", + "columnNames": [ + "rest_id" + ], + "composite": false, + "constraint": false, + "primary": false, + "unique": false + }, { "keyName": "schedules_pkey", "columnNames": [ @@ -3399,9 +3409,9 @@ "unique": false }, { - "keyName": "users_is_active_index", + "keyName": "users_phone_index", "columnNames": [ - "is_active" + "phone" ], "composite": false, "constraint": false, @@ -3556,26 +3566,6 @@ "primary": false, "unique": false }, - { - "keyName": "point_transactions_restaurant_id_index", - "columnNames": [ - "restaurant_id" - ], - "composite": false, - "constraint": false, - "primary": false, - "unique": false - }, - { - "keyName": "point_transactions_user_id_index", - "columnNames": [ - "user_id" - ], - "composite": false, - "constraint": false, - "primary": false, - "unique": false - }, { "keyName": "point_transactions_user_id_restaurant_id_index", "columnNames": [ @@ -3771,6 +3761,16 @@ "primary": false, "unique": false }, + { + "keyName": "pagers_restaurant_id_index", + "columnNames": [ + "restaurant_id" + ], + "composite": false, + "constraint": false, + "primary": false, + "unique": false + }, { "keyName": "pagers_pkey", "columnNames": [ @@ -4108,16 +4108,6 @@ "primary": false, "unique": false }, - { - "keyName": "orders_status_index", - "columnNames": [ - "status" - ], - "composite": false, - "constraint": false, - "primary": false, - "unique": false - }, { "keyName": "orders_restaurant_id_order_number_index", "columnNames": [ @@ -4129,17 +4119,6 @@ "primary": false, "unique": false }, - { - "keyName": "orders_user_id_status_index", - "columnNames": [ - "user_id", - "status" - ], - "composite": true, - "constraint": false, - "primary": false, - "unique": false - }, { "keyName": "orders_restaurant_id_status_index", "columnNames": [ @@ -4152,15 +4131,14 @@ "unique": false }, { - "keyName": "orders_restaurant_id_order_number_unique", + "keyName": "orders_restaurant_id_index", "columnNames": [ - "restaurant_id", - "order_number" + "restaurant_id" ], - "composite": true, - "constraint": true, + "composite": false, + "constraint": false, "primary": false, - "unique": true + "unique": false }, { "keyName": "orders_pkey", @@ -4556,7 +4534,8 @@ "enumItems": [ "Online", "Cash", - "Wallet" + "Wallet", + "Cart" ], "mappedType": "enum" }, @@ -4690,6 +4669,16 @@ "primary": false, "unique": false }, + { + "keyName": "payments_order_id_index", + "columnNames": [ + "order_id" + ], + "composite": false, + "constraint": false, + "primary": false, + "unique": false + }, { "keyName": "payments_pkey", "columnNames": [ @@ -4849,16 +4838,6 @@ "primary": false, "unique": false }, - { - "keyName": "order_items_food_id_index", - "columnNames": [ - "food_id" - ], - "composite": false, - "constraint": false, - "primary": false, - "unique": false - }, { "keyName": "order_items_order_id_index", "columnNames": [ @@ -5402,6 +5381,16 @@ "primary": false, "unique": false }, + { + "keyName": "user_addresses_user_id_index", + "columnNames": [ + "user_id" + ], + "composite": false, + "constraint": false, + "primary": false, + "unique": false + }, { "keyName": "user_addresses_pkey", "columnNames": [ @@ -5569,26 +5558,6 @@ "primary": false, "unique": false }, - { - "keyName": "wallet_transactions_restaurant_id_index", - "columnNames": [ - "restaurant_id" - ], - "composite": false, - "constraint": false, - "primary": false, - "unique": false - }, - { - "keyName": "wallet_transactions_user_id_index", - "columnNames": [ - "user_id" - ], - "composite": false, - "constraint": false, - "primary": false, - "unique": false - }, { "keyName": "wallet_transactions_user_id_restaurant_id_index", "columnNames": [ diff --git a/database/migrations/Migration20260607124425_add_card_number_to_payment_methods.ts b/database/migrations/Migration20260607124425_add_card_number_to_payment_methods.ts new file mode 100644 index 0000000..92d4849 --- /dev/null +++ b/database/migrations/Migration20260607124425_add_card_number_to_payment_methods.ts @@ -0,0 +1,13 @@ +import { Migration } from '@mikro-orm/migrations'; + +export class Migration20260607124425_add_card_number_to_payment_methods extends Migration { + + override async up(): Promise { + this.addSql(`alter table "payment_methods" add column "card_number" varchar(255) null;`); + } + + override async down(): Promise { + this.addSql(`alter table "payment_methods" drop column "card_number";`); + } + +} diff --git a/src/modules/payments/dto/create-payment-method.dto.ts b/src/modules/payments/dto/create-payment-method.dto.ts index 24acc82..d943f6f 100644 --- a/src/modules/payments/dto/create-payment-method.dto.ts +++ b/src/modules/payments/dto/create-payment-method.dto.ts @@ -18,6 +18,11 @@ export class CreatePaymentMethodDto { @IsString() description?: string; + @ApiProperty({ description: 'Card number for card-to-card payments', required: false }) + @IsOptional() + @IsString() + cardNumber?: string; + @ApiProperty({ description: 'Is payment method enabled', required: false, default: true }) @IsOptional() @IsBoolean() diff --git a/src/modules/payments/entities/payment-method.entity.ts b/src/modules/payments/entities/payment-method.entity.ts index b41b07e..61365ac 100644 --- a/src/modules/payments/entities/payment-method.entity.ts +++ b/src/modules/payments/entities/payment-method.entity.ts @@ -20,6 +20,9 @@ export class PaymentMethod extends BaseEntity { @Property({ nullable: true }) description?: string; + @Property({ nullable: true }) + cardNumber?: string; + @Property({ default: true }) enabled: boolean = true; diff --git a/src/modules/payments/interface/payment.ts b/src/modules/payments/interface/payment.ts index 6fd70c2..245d633 100644 --- a/src/modules/payments/interface/payment.ts +++ b/src/modules/payments/interface/payment.ts @@ -4,6 +4,7 @@ export enum PaymentMethodEnum { Online = 'Online', Cash = 'Cash', Wallet = 'Wallet', + Cart = 'Cart', } export enum PaymentStatusEnum { Pending = 'pending', diff --git a/src/seeders/data/payment-methods.data.ts b/src/seeders/data/payment-methods.data.ts index 673a1fc..cf5f610 100644 --- a/src/seeders/data/payment-methods.data.ts +++ b/src/seeders/data/payment-methods.data.ts @@ -6,6 +6,7 @@ export interface PaymentMethodData { enabled: boolean; order: number; gateway: PaymentGatewayEnum | null; + cardNumber?: string; merchantId?: string; } diff --git a/src/seeders/payment-methods.seeder.ts b/src/seeders/payment-methods.seeder.ts index 1765ce0..c3ce182 100644 --- a/src/seeders/payment-methods.seeder.ts +++ b/src/seeders/payment-methods.seeder.ts @@ -22,6 +22,7 @@ export class PaymentMethodsSeeder { enabled: methodData.enabled, order: methodData.order, gateway: methodData.gateway, + cardNumber: methodData.cardNumber, merchantId: methodData.merchantId, }); em.persist(paymentMethod); @@ -30,7 +31,8 @@ export class PaymentMethodsSeeder { if ( existing.description !== methodData.description || existing.enabled !== methodData.enabled || - existing.order !== methodData.order + existing.order !== methodData.order || + existing.cardNumber !== methodData.cardNumber ) { existing.description = methodData.description; existing.enabled = methodData.enabled; @@ -38,6 +40,9 @@ export class PaymentMethodsSeeder { if (methodData.gateway !== undefined) { existing.gateway = methodData.gateway; } + if (methodData.cardNumber !== undefined) { + existing.cardNumber = methodData.cardNumber; + } if (methodData.merchantId !== undefined) { existing.merchantId = methodData.merchantId; }