update payment

This commit is contained in:
2025-12-02 11:11:36 +03:30
parent 1165167619
commit 2e9a1dc7dc
12 changed files with 250 additions and 61 deletions
+47 -8
View File
@@ -94,18 +94,57 @@ export class DatabaseSeeder extends Seeder {
const superAdmin = await em.findOne(Role, { name: 'superAdmin' });
// 3. Create Payment Methods
const zarinpalPaymentMethod = await em.findOne(PaymentMethod, { keyName: 'zarinpal' });
if (!zarinpalPaymentMethod) {
const paymentMethod = em.create(PaymentMethod, {
const paymentMethodsData = [
{
name: 'پرداخت در محل',
keyName: 'payment-on-delivery',
description: 'پرداخت در محل تحویل',
isActive: true,
order: 1,
isOnline: false,
},
{
name: 'نقدی',
keyName: 'cash',
description: 'پرداخت نقدی',
isActive: true,
order: 2,
isOnline: false,
},
{
name: 'زرین‌پال',
keyName: 'zarinpal',
description: 'درگاه پرداخت زرین‌پال',
isActive: true,
order: 1,
order: 3,
isOnline: true,
callbackUrl: 'https://www.zarinpal.com/pg/StartPay',
});
em.persist(paymentMethod);
paymentUrl: 'https://www.zarinpal.com/pg/StartPay',
},
];
for (const methodData of paymentMethodsData) {
let paymentMethod = await em.findOne(PaymentMethod, { keyName: methodData.keyName });
if (!paymentMethod) {
paymentMethod = em.create(PaymentMethod, methodData);
em.persist(paymentMethod);
} else {
// Update existing payment method if needed
if (
paymentMethod.name !== methodData.name ||
paymentMethod.description !== methodData.description ||
paymentMethod.isOnline !== methodData.isOnline ||
paymentMethod.order !== methodData.order
) {
paymentMethod.name = methodData.name;
paymentMethod.description = methodData.description;
paymentMethod.isOnline = methodData.isOnline;
paymentMethod.order = methodData.order;
if (methodData.paymentUrl) {
paymentMethod.paymentUrl = methodData.paymentUrl;
}
em.persist(paymentMethod);
}
}
}
await em.flush();
@@ -211,7 +250,7 @@ export class DatabaseSeeder extends Seeder {
const boote = await em.findOne(Restaurant, { slug: 'boote' });
// 5.5. Create Restaurant Payment Methods
const allRestaurants = [zhivan, boote].filter(Boolean) as Restaurant[];
const allRestaurants = await em.find(Restaurant, {});
const allPaymentMethods = await em.find(PaymentMethod, { isActive: true });
for (const restaurant of allRestaurants) {