inventario
This commit is contained in:
@@ -8,6 +8,7 @@ import { seedMunicipalites } from './municipalities';
|
||||
import { seedParishes } from './parishes';
|
||||
import { seedStates } from './states';
|
||||
import { seedUserAdmin } from './user-admin.seed';
|
||||
import {seedProducts} from './inventory.seed'
|
||||
|
||||
async function main() {
|
||||
const pool = new Pool({
|
||||
@@ -25,6 +26,7 @@ async function main() {
|
||||
await seedLocalities(db);
|
||||
await seedAdminRole(db);
|
||||
await seedUserAdmin(db);
|
||||
await seedProducts(db);
|
||||
|
||||
console.log('All seeds completed successfully');
|
||||
} catch (error) {
|
||||
|
||||
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