import type { EntityManager } from '@mikro-orm/core'; import { User } from '../modules/users/entities/user.entity'; import { Shop } from '../../../shops/entities/shop.entity'; import { WalletTransaction } from '../modules/users/entities/wallet-transaction.entity'; import { WalletTransactionReason, WalletTransactionType } from 'src/modules/users/interface/wallet'; export class UserWalletsSeeder { async run(em: EntityManager): Promise { const users = await em.find(User, {}); const shops = await em.find(Shop, {}); for (const user of users) { for (const shop of shops) { // Check if wallet already exists for this user-shop combination const existingWallet = await em.findOne(WalletTransaction, { user: { id: user.id }, shop: { id: shop.id }, }); if (!existingWallet) { const wallet = em.create(WalletTransaction, { user, shop, balance: 150000000, amount: 150000000, type: WalletTransactionType.CREDIT, reason: WalletTransactionReason.DEPOSIT, }); em.persist(wallet); } } } await em.flush(); } }