info vendedor + direccion del producto
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
DROP VIEW "public"."v_product_store";--> statement-breakpoint
|
||||
ALTER TABLE "products" ADD COLUMN "address" text NOT NULL;--> statement-breakpoint
|
||||
CREATE VIEW "public"."v_product_store" AS (
|
||||
select p.id as product_id, p.title, p.description, p.price, p.stock, p.url_img, p.user_id, u.fullname, u.email, u.phone
|
||||
from products p
|
||||
left join auth.users as u on u.id = p.user_id);
|
||||
@@ -0,0 +1,5 @@
|
||||
DROP VIEW "public"."v_product_store";--> statement-breakpoint
|
||||
CREATE VIEW "public"."v_product_store" AS (
|
||||
select p.id as product_id, p.title, p.description, p.price, p.stock, p.url_img, p.address, p.user_id, u.fullname, u.email, u.phone
|
||||
from products p
|
||||
left join auth.users as u on u.id = p.user_id);
|
||||
1516
apps/api/src/database/migrations/meta/0004_snapshot.json
Normal file
1516
apps/api/src/database/migrations/meta/0004_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
1522
apps/api/src/database/migrations/meta/0005_snapshot.json
Normal file
1522
apps/api/src/database/migrations/meta/0005_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -29,6 +29,20 @@
|
||||
"when": 1751482400155,
|
||||
"tag": "0003_icy_gertrude_yorkes",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 4,
|
||||
"version": "7",
|
||||
"when": 1752500116385,
|
||||
"tag": "0004_colorful_aqueduct",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 5,
|
||||
"version": "7",
|
||||
"when": 1752500607554,
|
||||
"tag": "0005_little_bloodscream",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -11,6 +11,7 @@ export const products = t.pgTable(
|
||||
description: t.text('description').notNull(),
|
||||
price: t.numeric('price').notNull(),
|
||||
stock: t.integer('stock').notNull(),
|
||||
address: t.text('address').notNull(),
|
||||
urlImg: t.text('url_img').notNull(),
|
||||
userId: t.integer('user_id').references(() => users.id, { onDelete: 'cascade' }).notNull(),
|
||||
...timestamps,
|
||||
@@ -24,11 +25,12 @@ export const viewProductsStore = t.pgView('v_product_store', {
|
||||
price: t.numeric('price'),
|
||||
stock: t.integer('stock'),
|
||||
urlImg: t.text('url_img'),
|
||||
address: t.text('address'),
|
||||
userId: t.integer('user_id'),
|
||||
fullname: t.text('fullname'),
|
||||
email: t.text('email'),
|
||||
phone: t.text('phone')
|
||||
}).as(sql`
|
||||
select p.id as product_id, p.title, p.description, p.price, p.stock, p.url_img, p.user_id, u.fullname, u.email, u.phone
|
||||
select p.id as product_id, p.title, p.description, p.price, p.stock, p.url_img, p.address, p.user_id, u.fullname, u.email, u.phone
|
||||
from products p
|
||||
left join auth.users as u on u.id = p.user_id`);
|
||||
@@ -7,7 +7,7 @@ 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}];
|
||||
const array = [{title:'manzana',description:'fruta roja',price:'100',urlImg:'apple.avif',address:"Calle 1",userId:1,stock:0}];
|
||||
|
||||
for (const item of array) {
|
||||
try {
|
||||
@@ -16,6 +16,7 @@ export async function seedProducts(db: NodePgDatabase<typeof schema>) {
|
||||
description: item.description,
|
||||
price: item.price,
|
||||
stock: item.stock,
|
||||
address: item.address,
|
||||
urlImg: item.urlImg,
|
||||
userId: item.userId
|
||||
}).onConflictDoNothing();
|
||||
|
||||
@@ -24,6 +24,13 @@ export class CreateProductDto {
|
||||
@IsOptional()
|
||||
stock: number;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString({
|
||||
message: 'address must be a string',
|
||||
})
|
||||
@IsOptional()
|
||||
address: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsInt({
|
||||
message: 'stock must be a number',
|
||||
|
||||
@@ -17,6 +17,9 @@ export class UpdateProductDto extends PartialType(CreateProductDto) {
|
||||
@IsOptional()
|
||||
stock: number;
|
||||
|
||||
@IsOptional()
|
||||
address: string;
|
||||
|
||||
@IsOptional()
|
||||
urlImg: string;
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ export class InventoryService {
|
||||
id: products.id,
|
||||
title: products.title,
|
||||
description: products.description,
|
||||
address: products.address,
|
||||
price: products.price,
|
||||
stock: products.stock,
|
||||
urlImg: products.urlImg
|
||||
@@ -113,10 +114,13 @@ export class InventoryService {
|
||||
title: viewProductsStore.title,
|
||||
description: viewProductsStore.description,
|
||||
price: viewProductsStore.price,
|
||||
address: viewProductsStore.address,
|
||||
urlImg: viewProductsStore.urlImg,
|
||||
stock: viewProductsStore.stock,
|
||||
userId: viewProductsStore.userId,
|
||||
fullname: viewProductsStore.fullname
|
||||
fullname: viewProductsStore.fullname,
|
||||
email: viewProductsStore.email,
|
||||
phone: viewProductsStore.phone
|
||||
})
|
||||
.from(viewProductsStore)
|
||||
.where(searchCondition)
|
||||
@@ -145,10 +149,13 @@ export class InventoryService {
|
||||
title: viewProductsStore.title,
|
||||
description: viewProductsStore.description,
|
||||
price: viewProductsStore.price,
|
||||
address: viewProductsStore.address,
|
||||
urlImg: viewProductsStore.urlImg,
|
||||
stock: viewProductsStore.stock,
|
||||
userId: viewProductsStore.userId,
|
||||
fullname: viewProductsStore.fullname
|
||||
fullname: viewProductsStore.fullname,
|
||||
email: viewProductsStore.email,
|
||||
phone: viewProductsStore.phone
|
||||
})
|
||||
.from(viewProductsStore)
|
||||
.where(eq(viewProductsStore.id, parseInt(id)));
|
||||
@@ -175,6 +182,7 @@ export class InventoryService {
|
||||
title: createProductDto.title,
|
||||
description: createProductDto.description,
|
||||
price: createProductDto.price,
|
||||
address: createProductDto.address,
|
||||
urlImg: createProductDto.urlImg,
|
||||
stock: createProductDto.stock,
|
||||
userId: createProductDto.userId
|
||||
@@ -195,6 +203,7 @@ export class InventoryService {
|
||||
if (updateProductDto.title) updateData.title = updateProductDto.title;
|
||||
if (updateProductDto.description) updateData.description = updateProductDto.description;
|
||||
if (updateProductDto.price) updateData.price = updateProductDto.price;
|
||||
if (updateProductDto.address) updateData.address = updateProductDto.address;
|
||||
if (updateProductDto.stock) updateData.stock = updateProductDto.stock;
|
||||
if (updateProductDto.urlImg) updateData.urlImg = updateProductDto.urlImg;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user