icon seeder

This commit is contained in:
2026-02-15 10:31:54 +03:30
parent 98cf3d0a92
commit d460e0a3a1
3 changed files with 222 additions and 28 deletions
+34 -28
View File
@@ -7,6 +7,7 @@ import { ShopsSeeder } from './shops.seeder';
import { PaymentMethodsSeeder } from './payment-methods.seeder';
import { DeliveryMethodsSeeder } from './delivery-methods.seeder';
import { SchedulesSeeder } from './schedules.seeder';
import { IconsSeeder } from './icons.seeder';
import { CategoriesSeeder } from './categories.seeder';
import { ProductsSeeder } from './products.seeder';
import { AdminsSeeder } from './admins.seeder';
@@ -18,7 +19,7 @@ import { UserWalletsSeeder } from './user-wallets.seeder';
export class DatabaseSeeder extends Seeder {
async run(em: EntityManager) {
const TOTAL_STEPS = 14;
const TOTAL_STEPS = 15;
console.info('[Seeder] Starting database seed');
// 1. Create Permissions
console.info(`[Seeder] Step 1/${TOTAL_STEPS}: Creating permissions`);
@@ -63,45 +64,50 @@ export class DatabaseSeeder extends Seeder {
await notificationPreferencesSeeder.run(em, allShops);
console.info(`[Seeder] Step 7/${TOTAL_STEPS}: Done`);
// 8. Create Categories
console.info(`[Seeder] Step 8/${TOTAL_STEPS}: Creating categories`);
const categoriesSeeder = new CategoriesSeeder();
const categoriesMap = await categoriesSeeder.run(em, shopsMap);
// 8. Create Icon groups and Icons
console.info(`[Seeder] Step 8/${TOTAL_STEPS}: Creating icon groups and icons`);
const iconsSeeder = new IconsSeeder();
await iconsSeeder.run(em);
console.info(`[Seeder] Step 8/${TOTAL_STEPS}: Done`);
// 9. Create Products
console.info(`[Seeder] Step 9/${TOTAL_STEPS}: Creating products`);
const productsSeeder = new ProductsSeeder();
await productsSeeder.run(em, shopsMap, categoriesMap);
// 9. Create Categories
console.info(`[Seeder] Step 9/${TOTAL_STEPS}: Creating categories`);
const categoriesSeeder = new CategoriesSeeder();
const categoriesMap = await categoriesSeeder.run(em, shopsMap);
console.info(`[Seeder] Step 9/${TOTAL_STEPS}: Done`);
// 10. Create Coupons
console.info(`[Seeder] Step 10/${TOTAL_STEPS}: Creating coupons`);
const couponsSeeder = new CouponsSeeder();
await couponsSeeder.run(em, shopsMap);
// 10. Create Products
console.info(`[Seeder] Step 10/${TOTAL_STEPS}: Creating products`);
const productsSeeder = new ProductsSeeder();
await productsSeeder.run(em, shopsMap, categoriesMap);
console.info(`[Seeder] Step 10/${TOTAL_STEPS}: Done`);
// 11. Create Admins
console.info(`[Seeder] Step 11/${TOTAL_STEPS}: Creating admins`);
const adminsSeeder = new AdminsSeeder();
await adminsSeeder.run(em, rolesMap, shopsMap);
// 11. Create Coupons
console.info(`[Seeder] Step 11/${TOTAL_STEPS}: Creating coupons`);
const couponsSeeder = new CouponsSeeder();
await couponsSeeder.run(em, shopsMap);
console.info(`[Seeder] Step 11/${TOTAL_STEPS}: Done`);
// 12. Create Users
console.info(`[Seeder] Step 12/${TOTAL_STEPS}: Creating users`);
const usersSeeder = new UsersSeeder();
await usersSeeder.run(em);
// 12. Create Admins
console.info(`[Seeder] Step 12/${TOTAL_STEPS}: Creating admins`);
const adminsSeeder = new AdminsSeeder();
await adminsSeeder.run(em, rolesMap, shopsMap);
console.info(`[Seeder] Step 12/${TOTAL_STEPS}: Done`);
// 13. Create User Wallets
console.info(`[Seeder] Step 13/${TOTAL_STEPS}: Creating user wallets`);
const userWalletsSeeder = new UserWalletsSeeder();
await userWalletsSeeder.run(em);
// 13. Create Users
console.info(`[Seeder] Step 13/${TOTAL_STEPS}: Creating users`);
const usersSeeder = new UsersSeeder();
await usersSeeder.run(em);
console.info(`[Seeder] Step 13/${TOTAL_STEPS}: Done`);
// 14. Create Notifications for admins and users for all shops
console.info(`[Seeder] Step 14/${TOTAL_STEPS}: (optional) creating notifications`);
// 14. Create User Wallets
console.info(`[Seeder] Step 14/${TOTAL_STEPS}: Creating user wallets`);
const userWalletsSeeder = new UserWalletsSeeder();
await userWalletsSeeder.run(em);
console.info(`[Seeder] Step 14/${TOTAL_STEPS}: Done`);
// 15. Create Notifications for admins and users for all shops
console.info(`[Seeder] Step 15/${TOTAL_STEPS}: (optional) creating notifications`);
// const notificationsSeeder = new NotificationsSeeder();
// await notificationsSeeder.run(em);
console.info(`[Seeder] Step 15/${TOTAL_STEPS}: Done`);
+139
View File
@@ -0,0 +1,139 @@
[
{"name": "bread", "url": "https://storage.danakcorp.com/images/1766554365832-411750172.svg", "group": "normal"},
{"name": "avocado", "url": "https://storage.danakcorp.com/images/1766554379149-104970938.svg", "group": "normal"},
{"name": "knife", "url": "https://storage.danakcorp.com/images/1766554389090-593863597.svg", "group": "normal"},
{"name": "baby bottle", "url": "https://storage.danakcorp.com/images/1766554404968-905984091.svg", "group": "normal"},
{"name": "baby bottle", "url": "https://storage.danakcorp.com/images/1766554415325-873800591.svg", "group": "normal"},
{"name": "baby pacifier", "url": "https://storage.danakcorp.com/images/1766554428814-77027818.svg", "group": "normal"},
{"name": "banana", "url": "https://storage.danakcorp.com/images/1766554438632-45072052.svg", "group": "normal"},
{"name": "barbecue", "url": "https://storage.danakcorp.com/images/1766554446340-463157109.svg", "group": "normal"},
{"name": "barbeque2", "url": "https://storage.danakcorp.com/images/1766554456605-280166176.svg", "group": "normal"},
{"name": "drink", "url": "https://storage.danakcorp.com/images/1766554471887-315640495.svg", "group": "normal"},
{"name": "hanburger", "url": "https://storage.danakcorp.com/images/1766554485634-242317100.svg", "group": "normal"},
{"name": "drink2", "url": "https://storage.danakcorp.com/images/1766554504553-157481346.svg", "group": "normal"},
{"name": "bottle1", "url": "https://storage.danakcorp.com/images/1766554528198-919877647.svg", "group": "normal"},
{"name": "bottle2", "url": "https://storage.danakcorp.com/images/1766554544140-886744157.svg", "group": "normal"},
{"name": "broccoli", "url": "https://storage.danakcorp.com/images/1766554565614-684869010.svg", "group": "normal"},
{"name": "cake1", "url": "https://storage.danakcorp.com/images/1766554578855-318583145.svg", "group": "normal"},
{"name": "cake2", "url": "https://storage.danakcorp.com/images/1766554593272-362758712.svg", "group": "normal"},
{"name": "cake piece", "url": "https://storage.danakcorp.com/images/1766554606166-877198688.svg", "group": "normal"},
{"name": "cup cake", "url": "https://storage.danakcorp.com/images/1766554624133-21439996.svg", "group": "normal"},
{"name": "caupcake2", "url": "https://storage.danakcorp.com/images/1766554641691-535696200.svg", "group": "normal"},
{"name": "candle", "url": "https://storage.danakcorp.com/images/1766554658481-114730426.svg", "group": "normal"},
{"name": "candy", "url": "https://storage.danakcorp.com/images/1766554671760-634916570.svg", "group": "normal"},
{"name": "carrot", "url": "https://storage.danakcorp.com/images/1766554967381-660612838.svg", "group": "normal"},
{"name": "cheese", "url": "https://storage.danakcorp.com/images/1766555106925-267924006.svg", "group": "normal"},
{"name": "cheese2", "url": "https://storage.danakcorp.com/images/1766555231674-387319393.svg", "group": "normal"},
{"name": "hat robe", "url": "https://storage.danakcorp.com/images/1766555290519-155637622.svg", "group": "normal"},
{"name": "hat robe 2", "url": "https://storage.danakcorp.com/images/1766555308301-230359494.svg", "group": "normal"},
{"name": "cherry", "url": "https://storage.danakcorp.com/images/1766555420851-186440015.svg", "group": "normal"},
{"name": "chicken", "url": "https://storage.danakcorp.com/images/1766555590828-644527730.svg", "group": "normal"},
{"name": "baken", "url": "https://storage.danakcorp.com/images/1766555606997-571682462.svg", "group": "normal"},
{"name": "lollipop", "url": "https://storage.danakcorp.com/images/1766555663659-433052581.svg", "group": "normal"},
{"name": "cookie1", "url": "https://storage.danakcorp.com/images/1766555713098-988242030.svg", "group": "normal"},
{"name": "cookie2", "url": "https://storage.danakcorp.com/images/1766555726158-680948882.svg", "group": "normal"},
{"name": "crosson", "url": "https://storage.danakcorp.com/images/1766555746650-426516324.svg", "group": "normal"},
{"name": "juice", "url": "https://storage.danakcorp.com/images/1766555765798-127083646.svg", "group": "normal"},
{"name": "juice2", "url": "https://storage.danakcorp.com/images/1766555784837-243715698.svg", "group": "normal"},
{"name": "juice3", "url": "https://storage.danakcorp.com/images/1766555799191-594035927.svg", "group": "normal"},
{"name": "spoon and fork 1", "url": "https://storage.danakcorp.com/images/1766555894624-524350777.svg", "group": "normal"},
{"name": "spoon and fork 2", "url": "https://storage.danakcorp.com/images/1766555932114-485954688.svg", "group": "normal"},
{"name": "spoon and knife", "url": "https://storage.danakcorp.com/images/1766555949650-909996041.svg", "group": "normal"},
{"name": "fork and knife", "url": "https://storage.danakcorp.com/images/1766555966861-75517122.svg", "group": "normal"},
{"name": "hot dog", "url": "https://storage.danakcorp.com/images/1766556006875-239689681.svg", "group": "normal"},
{"name": "soap", "url": "https://storage.danakcorp.com/images/1766556257163-459958715.svg", "group": "normal"},
{"name": "dish", "url": "https://storage.danakcorp.com/images/1766556293812-665835248.svg", "group": "normal"},
{"name": "donuts", "url": "https://storage.danakcorp.com/images/1766556307082-162280793.svg", "group": "normal"},
{"name": "egg plant", "url": "https://storage.danakcorp.com/images/1766556340402-744632392.svg", "group": "normal"},
{"name": "egg", "url": "https://storage.danakcorp.com/images/1766556458335-857124841.svg", "group": "normal"},
{"name": "fast-food", "url": "https://storage.danakcorp.com/images/1766556479530-161860621.svg", "group": "normal"},
{"name": "taco", "url": "https://storage.danakcorp.com/images/1766556498215-91175544.svg", "group": "normal"},
{"name": "fire", "url": "https://storage.danakcorp.com/images/1766556677355-108854669.svg", "group": "normal"},
{"name": "fish", "url": "https://storage.danakcorp.com/images/1766556736283-691587656.svg", "group": "normal"},
{"name": "fish", "url": "https://storage.danakcorp.com/images/1766556759367-58066921.svg", "group": "normal"},
{"name": "french fries", "url": "https://storage.danakcorp.com/images/1766556777353-490756125.svg", "group": "normal"},
{"name": "fried egg", "url": "https://storage.danakcorp.com/images/1766556870740-118553581.svg", "group": "normal"},
{"name": "refrigerator", "url": "https://storage.danakcorp.com/images/1766556890334-962678132.svg", "group": "normal"},
{"name": "grape", "url": "https://storage.danakcorp.com/images/1766556921029-865260745.svg", "group": "normal"},
{"name": "hat robe", "url": "https://storage.danakcorp.com/images/1766556946363-320833501.svg", "group": "normal"},
{"name": "hot dog", "url": "https://storage.danakcorp.com/images/1766556973771-832565827.svg", "group": "normal"},
{"name": "ice cream", "url": "https://storage.danakcorp.com/images/1766557056358-727862983.svg", "group": "normal"},
{"name": "ice cream", "url": "https://storage.danakcorp.com/images/1766557199259-72955190.svg", "group": "normal"},
{"name": "ice cream 3", "url": "https://storage.danakcorp.com/images/1766557252452-988016525.svg", "group": "normal"},
{"name": "jar", "url": "https://storage.danakcorp.com/images/1766557274778-439028456.svg", "group": "normal"},
{"name": "jelly", "url": "https://storage.danakcorp.com/images/1766557289094-415104854.svg", "group": "normal"},
{"name": "juice1", "url": "https://storage.danakcorp.com/images/1766557300923-302277606.svg", "group": "normal"},
{"name": "juice 2", "url": "https://storage.danakcorp.com/images/1766557317091-602116315.svg", "group": "normal"},
{"name": "kitchen stove", "url": "https://storage.danakcorp.com/images/1766557647999-47333939.svg", "group": "normal"},
{"name": "orange slash", "url": "https://storage.danakcorp.com/images/1766557669282-172512141.svg", "group": "normal"},
{"name": "loaf of bread", "url": "https://storage.danakcorp.com/images/1766557705283-692546793.svg", "group": "normal"},
{"name": "loaf of bread 2", "url": "https://storage.danakcorp.com/images/1766557729175-762576743.svg", "group": "normal"},
{"name": "meat", "url": "https://storage.danakcorp.com/images/1766557756487-665300947.svg", "group": "normal"},
{"name": "meat 2", "url": "https://storage.danakcorp.com/images/1766557776067-804149228.svg", "group": "normal"},
{"name": "mixer", "url": "https://storage.danakcorp.com/images/1766557797509-101726352.svg", "group": "normal"},
{"name": "mortar", "url": "https://storage.danakcorp.com/images/1766557816484-357699340.svg", "group": "normal"},
{"name": "noodle", "url": "https://storage.danakcorp.com/images/1766557837292-326521286.svg", "group": "normal"},
{"name": "nuts", "url": "https://storage.danakcorp.com/images/1766559083575-564721059.svg", "group": "normal"},
{"name": "olive", "url": "https://storage.danakcorp.com/images/1766559099561-720966516.svg", "group": "normal"},
{"name": "onion", "url": "https://storage.danakcorp.com/images/1766559116496-834964990.svg", "group": "normal"},
{"name": "pizza", "url": "https://storage.danakcorp.com/images/1766563021426-600579018.svg", "group": "normal"},
{"name": "rolling pin", "url": "https://storage.danakcorp.com/images/1766563038525-727531190.svg", "group": "normal"},
{"name": "solt", "url": "https://storage.danakcorp.com/images/1766563051485-824602001.svg", "group": "normal"},
{"name": "scales", "url": "https://storage.danakcorp.com/images/1766563066017-372210647.svg", "group": "normal"},
{"name": "basket", "url": "https://storage.danakcorp.com/images/1766563124296-331607800.svg", "group": "normal"},
{"name": "skewer", "url": "https://storage.danakcorp.com/images/1766563142133-359920423.svg", "group": "normal"},
{"name": "strawberry", "url": "https://storage.danakcorp.com/images/1766563164270-350101986.svg", "group": "normal"},
{"name": "toast", "url": "https://storage.danakcorp.com/images/1766563181587-86630830.svg", "group": "normal"},
{"name": "watermelon", "url": "https://storage.danakcorp.com/images/1766563204966-651499380.svg", "group": "normal"},
{"name": "whisk", "url": "https://storage.danakcorp.com/images/1766563220596-103699525.svg", "group": "normal"},
{"name": "wine glass", "url": "https://storage.danakcorp.com/images/1766563265634-373953449.svg", "group": "normal"},
{"name": "wine glass 2", "url": "https://storage.danakcorp.com/images/1766563275517-958045207.svg", "group": "normal"},
{"name": "wine glass 3", "url": "https://storage.danakcorp.com/images/1766563286526-622849562.svg", "group": "normal"},
{"name": "colored bakeries", "url": "https://storage.danakcorp.com/images/1766564695339-504553420.svg", "group": "colored"},
{"name": "colored bio", "url": "https://storage.danakcorp.com/images/1766564706032-159367016.svg", "group": "colored"},
{"name": "colored bibimbap", "url": "https://storage.danakcorp.com/images/1766564720683-887818252.svg", "group": "colored"},
{"name": "colored boba", "url": "https://storage.danakcorp.com/images/1766564734432-483528219.svg", "group": "colored"},
{"name": "colored breakfast", "url": "https://storage.danakcorp.com/images/1766564750099-854146988.svg", "group": "colored"},
{"name": "colored hamburger", "url": "https://storage.danakcorp.com/images/1766564758573-696060786.svg", "group": "colored"},
{"name": "colored hamburger 2", "url": "https://storage.danakcorp.com/images/1766564805823-829938380.svg", "group": "colored"},
{"name": "colored coffee", "url": "https://storage.danakcorp.com/images/1766564891137-468827500.svg", "group": "colored"},
{"name": "colored coca", "url": "https://storage.danakcorp.com/images/1766564907215-921380792.svg", "group": "colored"},
{"name": "colored cookies", "url": "https://storage.danakcorp.com/images/1766564926872-672612697.svg", "group": "colored"},
{"name": "colored noodle", "url": "https://storage.danakcorp.com/images/1766565459604-638026702.svg", "group": "colored"},
{"name": "colored crossan", "url": "https://storage.danakcorp.com/images/1766565476771-42527917.svg", "group": "colored"},
{"name": "colored sweet", "url": "https://storage.danakcorp.com/images/1766565491264-946731491.svg", "group": "colored"},
{"name": "colored dumpling", "url": "https://storage.danakcorp.com/images/1766565502475-288189136.svg", "group": "colored"},
{"name": "colored fish and chips", "url": "https://storage.danakcorp.com/images/1766565530628-800474580.svg", "group": "colored"},
{"name": "colored focaccia", "url": "https://storage.danakcorp.com/images/1766565547983-878658938.svg", "group": "colored"},
{"name": "colored french fries", "url": "https://storage.danakcorp.com/images/1766565563263-891688321.svg", "group": "colored"},
{"name": "colored fried chicken", "url": "https://storage.danakcorp.com/images/1766565600547-704332792.svg", "group": "colored"},
{"name": "colored fried rice", "url": "https://storage.danakcorp.com/images/1766565625437-528383713.svg", "group": "colored"},
{"name": "colored fries", "url": "https://storage.danakcorp.com/images/1766565641620-53176909.svg", "group": "colored"},
{"name": "hat robe", "url": "https://storage.danakcorp.com/images/1766565664427-433669317.svg", "group": "normal"},
{"name": "colored hot dog", "url": "https://storage.danakcorp.com/images/1766565971515-159903323.svg", "group": "colored"},
{"name": "colored hot dog", "url": "https://storage.danakcorp.com/images/1766565995424-288101561.svg", "group": "colored"},
{"name": "colored hot pot", "url": "https://storage.danakcorp.com/images/1766566026942-868807643.svg", "group": "colored"},
{"name": "colored ice cream", "url": "https://storage.danakcorp.com/images/1766566041525-973019175.svg", "group": "colored"},
{"name": "colored ice tea", "url": "https://storage.danakcorp.com/images/1766566064741-271844433.svg", "group": "colored"},
{"name": "colored instant noodle cup", "url": "https://storage.danakcorp.com/images/1766566084368-438871956.svg", "group": "colored"},
{"name": "lemon", "url": "https://storage.danakcorp.com/images/1766566106954-47179607.svg", "group": "normal"},
{"name": "colored martini", "url": "https://storage.danakcorp.com/images/1766566122836-486871124.svg", "group": "colored"},
{"name": "colored match", "url": "https://storage.danakcorp.com/images/1766566143171-668309076.svg", "group": "colored"},
{"name": "colored mochi donuts", "url": "https://storage.danakcorp.com/images/1766566161551-844376214.svg", "group": "colored"},
{"name": "colored mochi", "url": "https://storage.danakcorp.com/images/1766566176755-30806596.svg", "group": "colored"},
{"name": "colored nachos", "url": "https://storage.danakcorp.com/images/1766566193720-339416210.svg", "group": "colored"},
{"name": "colored origini", "url": "https://storage.danakcorp.com/images/1766566293736-981836756.svg", "group": "colored"},
{"name": "colored pan cake", "url": "https://storage.danakcorp.com/images/1766566304318-193301989.svg", "group": "colored"},
{"name": "colored pepperoni pizza", "url": "https://storage.danakcorp.com/images/1766566327768-2675508.svg", "group": "colored"},
{"name": "colored pizza 4", "url": "https://storage.danakcorp.com/images/1766566341717-462491426.svg", "group": "colored"},
{"name": "colored podding", "url": "https://storage.danakcorp.com/images/1766566357028-432111036.svg", "group": "colored"},
{"name": "quesadilla", "url": "https://storage.danakcorp.com/images/1766566371354-279596850.svg", "group": "normal"},
{"name": "salad", "url": "https://storage.danakcorp.com/images/1766566385674-569493499.svg", "group": "normal"},
{"name": "colored sandwich", "url": "https://storage.danakcorp.com/images/1766566413058-975642584.svg", "group": "colored"},
{"name": "colored stak", "url": "https://storage.danakcorp.com/images/1766566427440-982841441.svg", "group": "colored"},
{"name": "colored soshi", "url": "https://storage.danakcorp.com/images/1766566442808-761588425.svg", "group": "colored"},
{"name": "colored taco", "url": "https://storage.danakcorp.com/images/1766566468108-51915895.svg", "group": "colored"},
{"name": "colored tempura", "url": "https://storage.danakcorp.com/images/1766566482278-661272876.svg", "group": "colored"},
{"name": "colored tafu", "url": "https://storage.danakcorp.com/images/1766566494050-408184442.svg", "group": "colored"},
{"name": "whisk", "url": "https://storage.danakcorp.com/images/1766566504760-709260995.svg", "group": "normal"}
]
+49
View File
@@ -0,0 +1,49 @@
import type { EntityManager } from '@mikro-orm/core';
import * as fs from 'fs';
import * as path from 'path';
import { Group } from '../modules/icons/entities/group.entity';
import { Icon } from '../modules/icons/entities/icon.entity';
const GROUP_NAMES = ['normal', 'colored'] as const;
export interface IconSeedData {
name: string;
url: string;
group: 'normal' | 'colored';
}
function getIconsData(): IconSeedData[] {
const dataPath = path.join(process.cwd(), 'src', 'seeders', 'data', 'icons.data.json');
const content = fs.readFileSync(dataPath, 'utf-8');
return JSON.parse(content) as IconSeedData[];
}
export class IconsSeeder {
async run(em: EntityManager): Promise<void> {
const groupsMap = new Map<string, Group>();
for (const groupName of GROUP_NAMES) {
let group = await em.findOne(Group, { name: groupName });
if (!group) {
group = em.create(Group, { name: groupName });
em.persist(group);
}
groupsMap.set(groupName, group);
}
const iconsData = getIconsData();
for (const row of iconsData) {
const group = groupsMap.get(row.group);
if (!group) continue;
const exists = await em.findOne(Icon, { url: row.url, group });
if (!exists) {
const icon = em.create(Icon, { url: row.url, group });
em.persist(icon);
}
}
await em.flush();
}
}