Files
shop-api/src/db/seeders/themeSeeder.ts
T
morteza-mortezai 1345f81b3a db: seeder
2025-11-30 21:45:24 +03:30

64 lines
1.5 KiB
TypeScript

import { Logger } from "../../core/logging/logger";
import { InputTypeEnum, ThemeModel } from "../../modules/category/models/theme.model";
export const seedTheme = async (logger: Logger) => {
try {
logger.info("Theme seeding started");
const themes = [
{
title: "جریان نام",
inputType: InputTypeEnum.Number,
},
{
title: "ولتاژ کاری",
inputType: InputTypeEnum.Number,
},
{
title: "تعداد پل",
inputType: InputTypeEnum.Number,
},
{
title: "فاز",
inputType: InputTypeEnum.Text,
},
{
title: "رنگ",
inputType: InputTypeEnum.Color,
},
{
title: "سایز",
inputType: InputTypeEnum.Text,
},
{
title: "قدرت قطع",
inputType: InputTypeEnum.Number,
},
{
title: "نوع تغذیه",
inputType: InputTypeEnum.Text,
},
{
title: "تیپ",
inputType: InputTypeEnum.Text,
},
];
// Check if themes already exist
const existingThemes = await ThemeModel.find({
title: { $in: themes.map((t) => t.title) },
});
if (existingThemes.length > 0) {
logger.info(`Themes already exist (${existingThemes.length} found), skipping creation`);
return;
}
await ThemeModel.insertMany(themes);
logger.info(`Theme seeding complete! (${themes.length} themes)`);
} catch (error) {
logger.error("Error seeding themes:", error);
throw error;
}
};