Files
sistema_base/apps/api/src/database/seeds/inventory.seed.ts

43 lines
1.2 KiB
TypeScript

import { NodePgDatabase } from 'drizzle-orm/node-postgres';
import * as schema from '../index';
import { products } from '../schema/inventory';
export async function seedProducts(db: NodePgDatabase<typeof schema>) {
console.log('Seeding example product...');
// Insert inventory
const array = [
{
title:'manzana',
description:'Fruta pequeña y roja, extraída de los árboles de nuestra fundación, de increíble sabor',
price:'100',
stock:10,
address:"Calle 1",
status:'PUBLICADO', // PUBLICADO, AGOTADO, BORRADOR
urlImg:'apple.avif',
userId:1,
gallery: ["Pruebas"]
}
];
for (const item of array) {
try {
// await db.insert(products).values({
// title: item.title,
// description: item.description,
// price: item.price,
// stock: item.stock,
// address: item.address,
// urlImg: item.urlImg,
// userId: item.userId
// }).onConflictDoNothing();
await db.insert(products).values(item).onConflictDoNothing();
} catch (error) {
console.error(`Error creating products '${item.title}':`, error);
}
}
console.log('All products seeded successfully');
}