inventario
This commit is contained in:
28
apps/api/src/database/seeds/inventory.seed.ts
Normal file
28
apps/api/src/database/seeds/inventory.seed.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
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 roja',price:'100',urlImg:'apple.avif',userId:1,stock:0}];
|
||||
|
||||
for (const item of array) {
|
||||
try {
|
||||
await db.insert(products).values({
|
||||
title: item.title,
|
||||
description: item.description,
|
||||
price: item.price,
|
||||
stock: item.stock,
|
||||
urlImg: item.urlImg,
|
||||
userId: item.userId
|
||||
}).onConflictDoNothing();
|
||||
} catch (error) {
|
||||
console.error(`Error creating products '${item.title}':`, error);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('All products seeded successfully');
|
||||
}
|
||||
Reference in New Issue
Block a user