db: seeder
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user