38674-vm/backend/src/db/seeders/20260221000000-minimarket-sample.js
Flatlogic Bot c7d62cba01 PREM
2026-02-21 19:06:55 +00:00

155 lines
7.0 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { v4: uuid } = require("uuid");
module.exports = {
async up(queryInterface) {
const createdAt = new Date();
const updatedAt = new Date();
const catDrinkId = uuid();
const catSnackId = uuid();
const catGroceryId = uuid();
const langEnId = uuid();
const langMsId = uuid();
const langZhId = uuid();
const langTaId = uuid();
const shopId = uuid();
// Check if languages exist before inserting
const [existingLangs] = await queryInterface.sequelize.query('SELECT id, code FROM "languages"');
const existingCodes = existingLangs.map(l => l.code);
const languagesToInsert = [
{ id: langEnId, name: "English", code: "en", createdAt, updatedAt },
{ id: langMsId, name: "Bahasa Melayu", code: "ms", createdAt, updatedAt },
{ id: langZhId, name: "Mandarin", code: "zh", createdAt, updatedAt },
{ id: langTaId, name: "Tamil", code: "ta", createdAt, updatedAt },
].filter(l => !existingCodes.includes(l.code));
if (languagesToInsert.length > 0) {
await queryInterface.bulkInsert("languages", languagesToInsert);
}
// Get the actual IDs for translations
const [allLangs] = await queryInterface.sequelize.query('SELECT id, code FROM "languages"');
const langMap = allLangs.reduce((acc, l) => ({ ...acc, [l.code]: l.id }), {});
await queryInterface.bulkInsert("shops", [
{
id: shopId,
name: "Super Star Store",
tagline: "Your Neighbourhood Choice in Ipoh",
primary_color_hex: "#22c55e",
secondary_color_hex: "#fbbf24",
whatsapp_number: "60125749390",
phone_number: "012-574 9390",
email: "superstarstore@gmail.com",
address_line_1: "1-25, Laluan Menglembu Impiana 8",
address_line_2: "Taman Menglembu Impiana Adril",
postcode: "31450",
city: "Ipoh",
state: "Perak",
country: "Malaysia",
latitude: 4.5670,
longitude: 101.0450,
google_maps_embed_url: "https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3976.99!2d101.04!3d4.56!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0x0!2zNMKwMzMnMzguMiJOIDEwMcKwMDInNDIuMCJF!5e0!3m2!1sen!2smy!4v1700000000000!5m2!1sen!2smy",
opening_hours_text: "Closed · Opens 8:30am",
is_published: true,
createdAt,
updatedAt
}
]);
await queryInterface.bulkInsert("product_categories", [
{ id: catDrinkId, code: "Drinks", shopId, createdAt, updatedAt },
{ id: catSnackId, code: "Snacks", shopId, createdAt, updatedAt },
{ id: catGroceryId, code: "Groceries", shopId, createdAt, updatedAt },
]);
await queryInterface.bulkInsert("category_translations", [
{ id: uuid(), name: "Minuman", languageId: langMap["ms"], categoryId: catDrinkId, createdAt, updatedAt },
{ id: uuid(), name: "饮料", languageId: langMap["zh"], categoryId: catDrinkId, createdAt, updatedAt },
{ id: uuid(), name: "பானங்கள்", languageId: langMap["ta"], categoryId: catDrinkId, createdAt, updatedAt },
{ id: uuid(), name: "Snek", languageId: langMap["ms"], categoryId: catSnackId, createdAt, updatedAt },
{ id: uuid(), name: "零食", languageId: langMap["zh"], categoryId: catSnackId, createdAt, updatedAt },
{ id: uuid(), name: "சிற்றுண்டி", languageId: langMap["ta"], categoryId: catSnackId, createdAt, updatedAt },
{ id: uuid(), name: "Runcit", languageId: langMap["ms"], categoryId: catGroceryId, createdAt, updatedAt },
{ id: uuid(), name: "杂货", languageId: langMap["zh"], categoryId: catGroceryId, createdAt, updatedAt },
{ id: uuid(), name: "மளிகை", languageId: langMap["ta"], categoryId: catGroceryId, createdAt, updatedAt },
]);
const prod1Id = uuid();
const prod2Id = uuid();
const prod3Id = uuid();
await queryInterface.bulkInsert("products", [
{
id: prod1Id,
sku: "DRK-001",
price_rm: 2.50,
compare_at_price_rm: 3.00,
stock_quantity: 100,
status: "active",
categoryId: catDrinkId,
shopId,
createdAt, updatedAt
},
{
id: prod2Id,
sku: "SNK-001",
price_rm: 1.80,
stock_quantity: 50,
status: "active",
categoryId: catSnackId,
shopId,
createdAt, updatedAt
},
{
id: prod3Id,
sku: "GRC-001",
price_rm: 4.50,
stock_quantity: 200,
status: "active",
categoryId: catGroceryId,
shopId,
createdAt, updatedAt
},
]);
await queryInterface.bulkInsert("product_translations", [
{ id: uuid(), name: "Milo Can 240ml", languageId: langMap["en"], productId: prod1Id, createdAt, updatedAt },
{ id: uuid(), name: "Tin Milo 240ml", languageId: langMap["ms"], productId: prod1Id, createdAt, updatedAt },
{ id: uuid(), name: "美禄罐装 240ml", languageId: langMap["zh"], productId: prod1Id, createdAt, updatedAt },
{ id: uuid(), name: "மைலோ டின் 240மி", languageId: langMap["ta"], productId: prod1Id, createdAt, updatedAt },
{ id: uuid(), name: "Mamee Monster Snack", languageId: langMap["en"], productId: prod2Id, createdAt, updatedAt },
{ id: uuid(), name: "Snek Mamee Monster", languageId: langMap["ms"], productId: prod2Id, createdAt, updatedAt },
{ id: uuid(), name: "妈咪怪兽零食", languageId: langMap["zh"], productId: prod2Id, createdAt, updatedAt },
{ id: uuid(), name: "மாமி மான்ஸ்டர் சிற்றுண்டி", languageId: langMap["ta"], productId: prod2Id, createdAt, updatedAt },
{ id: uuid(), name: "Maggi Curry Noodles 5-Pack", languageId: langMap["en"], productId: prod3Id, createdAt, updatedAt },
{ id: uuid(), name: "Maggi Kari 5-Pek", languageId: langMap["ms"], productId: prod3Id, createdAt, updatedAt },
{ id: uuid(), name: "美极咖喱面 5包入", languageId: langMap["zh"], productId: prod3Id, createdAt, updatedAt },
{ id: uuid(), name: "மேகி கறி நூடுல்ஸ் 5-பேக்", languageId: langMap["ta"], productId: prod3Id, createdAt, updatedAt },
]);
const promoId = uuid();
await queryInterface.bulkInsert("promotions", [
{ id: promoId, promotion_type: "general", is_active: true, shopId, createdAt, updatedAt }
]);
await queryInterface.bulkInsert("promotion_translations", [
{ id: uuid(), title: "Ramadan Special Sale", languageId: langMap["en"], promotionId: promoId, createdAt, updatedAt },
{ id: uuid(), title: "Jualan Khas Ramadan", languageId: langMap["ms"], promotionId: promoId, createdAt, updatedAt },
{ id: uuid(), title: "斋戒月特别大减价", languageId: langMap["zh"], promotionId: promoId, createdAt, updatedAt },
{ id: uuid(), title: "ரம்ஜான் சிறப்பு விற்பனை", languageId: langMap["ta"], promotionId: promoId, createdAt, updatedAt },
]);
},
async down() {
// Optional
},
};