shipment
This commit is contained in:
@@ -10,6 +10,7 @@ import { Restaurant } from '../modules/restaurants/entities/restaurant.entity';
|
||||
import { User } from '../modules/users/entities/user.entity';
|
||||
import { Permission, PermissionTitles } from '../common/enums/permission.enum';
|
||||
import { PaymentMethod } from '../modules/payments/entities/payment-method.entity';
|
||||
import { ShipmentMethod } from '../modules/restaurants/entities/shipment-method.entity';
|
||||
|
||||
export class DatabaseSeeder extends Seeder {
|
||||
async run(em: EntityManager) {
|
||||
@@ -105,7 +106,54 @@ export class DatabaseSeeder extends Seeder {
|
||||
|
||||
await em.flush();
|
||||
|
||||
// 4. Create Restaurants (Farsi)
|
||||
// 4. Create Shipment Methods (Farsi)
|
||||
const shipmentMethods = [
|
||||
{
|
||||
name: 'dine-in',
|
||||
title: 'سرو در رستوران',
|
||||
description: 'سرو غذا در رستوران',
|
||||
isActive: true,
|
||||
},
|
||||
{
|
||||
name: 'delivery-location',
|
||||
title: 'تحویل در محل',
|
||||
description: 'تحویل غذا در محل',
|
||||
isActive: true,
|
||||
},
|
||||
{
|
||||
name: 'delivery-car',
|
||||
title: 'تحویل با ماشین',
|
||||
description: 'تحویل غذا با ماشین',
|
||||
isActive: true,
|
||||
},
|
||||
{
|
||||
name: 'delivery-courier',
|
||||
title: 'تحویل با پیک',
|
||||
description: 'تحویل غذا با پیک',
|
||||
isActive: true,
|
||||
},
|
||||
];
|
||||
|
||||
const createdShipmentMethods: ShipmentMethod[] = [];
|
||||
for (const methodData of shipmentMethods) {
|
||||
let shipmentMethod = await em.findOne(ShipmentMethod, { name: methodData.name });
|
||||
if (!shipmentMethod) {
|
||||
shipmentMethod = em.create(ShipmentMethod, methodData);
|
||||
em.persist(shipmentMethod);
|
||||
} else {
|
||||
// Update existing method if needed
|
||||
if (shipmentMethod.title !== methodData.title || shipmentMethod.description !== methodData.description) {
|
||||
shipmentMethod.title = methodData.title;
|
||||
shipmentMethod.description = methodData.description;
|
||||
em.persist(shipmentMethod);
|
||||
}
|
||||
}
|
||||
createdShipmentMethods.push(shipmentMethod);
|
||||
}
|
||||
|
||||
await em.flush();
|
||||
|
||||
// 5. Create Restaurants (Farsi)
|
||||
const zhivanRestaurant = await em.findOne(Restaurant, { slug: 'zhivan' });
|
||||
if (!zhivanRestaurant) {
|
||||
const restaurant = em.create(Restaurant, {
|
||||
@@ -115,7 +163,15 @@ export class DatabaseSeeder extends Seeder {
|
||||
phone: '09123456789',
|
||||
serviceArea: {
|
||||
type: 'Polygon',
|
||||
coordinates: [[[51.389, 35.6892], [51.390, 35.6892], [51.390, 35.6902], [51.389, 35.6902], [51.389, 35.6892]]],
|
||||
coordinates: [
|
||||
[
|
||||
[51.389, 35.6892],
|
||||
[51.39, 35.6892],
|
||||
[51.39, 35.6902],
|
||||
[51.389, 35.6902],
|
||||
[51.389, 35.6892],
|
||||
],
|
||||
],
|
||||
},
|
||||
});
|
||||
em.persist(restaurant);
|
||||
@@ -130,7 +186,15 @@ export class DatabaseSeeder extends Seeder {
|
||||
phone: '09123456790',
|
||||
serviceArea: {
|
||||
type: 'Polygon',
|
||||
coordinates: [[[51.389, 35.6892], [51.390, 35.6892], [51.390, 35.6902], [51.389, 35.6902], [51.389, 35.6892]]],
|
||||
coordinates: [
|
||||
[
|
||||
[51.389, 35.6892],
|
||||
[51.39, 35.6892],
|
||||
[51.39, 35.6902],
|
||||
[51.389, 35.6902],
|
||||
[51.389, 35.6892],
|
||||
],
|
||||
],
|
||||
},
|
||||
});
|
||||
em.persist(restaurant);
|
||||
@@ -142,7 +206,7 @@ export class DatabaseSeeder extends Seeder {
|
||||
const zhivan = await em.findOne(Restaurant, { slug: 'zhivan' });
|
||||
const boote = await em.findOne(Restaurant, { slug: 'boote' });
|
||||
|
||||
// 5. Create Categories (Farsi)
|
||||
// 6. Create Categories (Farsi)
|
||||
const categories = [
|
||||
{ title: 'غذای اصلی', restId: zhivan?.id },
|
||||
{ title: 'پیش غذا', restId: zhivan?.id },
|
||||
@@ -172,7 +236,7 @@ export class DatabaseSeeder extends Seeder {
|
||||
|
||||
await em.flush();
|
||||
|
||||
// 6. Create Foods (Farsi)
|
||||
// 7. Create Foods (Farsi)
|
||||
const foods = [
|
||||
// Zhivan Restaurant Foods
|
||||
{
|
||||
@@ -455,7 +519,7 @@ export class DatabaseSeeder extends Seeder {
|
||||
|
||||
await em.flush();
|
||||
|
||||
// 7. Create Admins (Farsi)
|
||||
// 8. Create Admins (Farsi)
|
||||
const adminMorteza = await em.findOne(Admin, { phone: '09362532122' });
|
||||
if (!adminMorteza && restaurantRole && zhivan) {
|
||||
const admin = em.create(Admin, {
|
||||
@@ -515,7 +579,7 @@ export class DatabaseSeeder extends Seeder {
|
||||
|
||||
await em.flush();
|
||||
|
||||
// 8. Create Users (Farsi)
|
||||
// 9. Create Users (Farsi)
|
||||
const userMorteza = await em.findOne(User, { phone: '09362532122' });
|
||||
if (!userMorteza && zhivan) {
|
||||
const user = em.create(User, {
|
||||
|
||||
Reference in New Issue
Block a user