41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { initializeApp } from 'firebase-admin/app'
|
|
import { getFirestore } from 'firebase-admin/firestore'
|
|
import { products } from '../src/data/products.js'
|
|
import { services } from '../src/data/services.js'
|
|
|
|
initializeApp()
|
|
const db = getFirestore()
|
|
|
|
function toStoragePath(image: string): string {
|
|
return image.replace(/^\//, '')
|
|
}
|
|
|
|
async function seed() {
|
|
const batch = db.batch()
|
|
|
|
for (const product of products) {
|
|
const { id, image, ...rest } = product
|
|
batch.set(db.doc(`products/${id}`), { ...rest, image: toStoragePath(image) })
|
|
}
|
|
|
|
for (const service of services) {
|
|
const { id, image, ...rest } = service
|
|
batch.set(db.doc(`services/${id}`), { ...rest, image: toStoragePath(image) })
|
|
}
|
|
|
|
batch.set(db.doc('scheduleTemplate/default'), {
|
|
workingDays: [2, 3, 4, 5, 6],
|
|
startTime: '09:00',
|
|
endTime: '18:00',
|
|
slotMinutes: 120,
|
|
})
|
|
|
|
await batch.commit()
|
|
console.log(`Seeded ${products.length} products, ${services.length} services, and the default schedule.`)
|
|
}
|
|
|
|
seed().catch((err) => {
|
|
console.error(err)
|
|
process.exit(1)
|
|
})
|