import "./_bootstrap"; import { Timestamp } from "firebase-admin/firestore"; import { firestore } from "../src/firebase"; const products = [ { id: "acrylic-keyring", name: "아크릴 키링", pointPrice: 3000, displayOrder: 1 }, { id: "magsafe-tok", name: "맥세이프 톡", pointPrice: 6500, displayOrder: 2 }, { id: "keyring-doll", name: "키링 인형", pointPrice: 11000, displayOrder: 3 }, { id: "crossbag", name: "크로스백", pointPrice: 15000, displayOrder: 4 }, ] as const; async function main() { const now = Timestamp.now(); for (const p of products) { const product = firestore.doc(`products/${p.id}`); const old = await product.get(); const existing = old.data(); const draft = old.exists ? {} : { active: false, redeemable: false, mainImages: [], detailImages: [], }; await product.set({ name: p.name, pointPrice: p.pointPrice, displayOrder: p.displayOrder, totalStock: existing?.totalStock ?? 0, reservedStock: existing?.reservedStock ?? 0, safetyStock: existing?.safetyStock ?? 0, ...draft, createdAt: existing?.createdAt ?? now, updatedAt: now, }, { merge: true }); } } main().then(() => console.log(`seeded ${products.length} reward products`)).catch((e) => { console.error(e); process.exitCode = 1; });