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;
|
||||
|
||||
|
||||
@@ -34,8 +34,9 @@ export default async function SurveyResponsePage({
|
||||
|
||||
const product = data.data
|
||||
|
||||
// console.log(data.data);
|
||||
const lorem = "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolore placeat est corporis minus exercitationem impedit ab architecto dolorum nihil nam facilis suscipit porro, iure et quidem illo mollitia officia amet?"
|
||||
|
||||
// console.log(data.data);
|
||||
|
||||
return (
|
||||
// <PageContainer>
|
||||
@@ -52,19 +53,27 @@ export default async function SurveyResponsePage({
|
||||
</CardTitle>
|
||||
<p className='font-semibold'>$ {product.price}</p>
|
||||
</CardHeader>
|
||||
<CardContent className="flex-grow">
|
||||
<CardContent className="flex-grow flex justify-between flex-col gap-4">
|
||||
<div>
|
||||
<p className='font-semibold text-lg border-t border-b'> Descripción</p>
|
||||
<p className='p-1'>{product.description}</p>
|
||||
{/* <p className='p-1'>{lorem+lorem+lorem+lorem}</p> */}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p className='font-semibold text-lg border-t border-b'> Dirección</p>
|
||||
<p>{product.address}</p>
|
||||
</div>
|
||||
|
||||
|
||||
</CardContent>
|
||||
<CardFooter className="">
|
||||
<div>
|
||||
<p className='font-semibold text-lg border-t border-b mt-4'>Información del vendedor</p>
|
||||
<p>{product.fullname}</p>
|
||||
<p>Correo@gmail.com</p>
|
||||
<p>0412-7848101</p>
|
||||
<p>{product.phone}</p>
|
||||
<p>{product.email}</p>
|
||||
</div>
|
||||
{/* <p className="font-semibold text-lg">$ {product.price}</p> */}
|
||||
</CardFooter>
|
||||
</Card>
|
||||
</main>
|
||||
|
||||
@@ -6,18 +6,25 @@ export type InventoryTable = z.infer<typeof product>;
|
||||
export type EditInventory = z.infer<typeof editInventory>; //output
|
||||
export type formDataInput = z.input<typeof editInventory>;
|
||||
export type ProductApiResponseSchema = z.infer<typeof productApiResponseSchema>;
|
||||
export type allProducts = z.infer<typeof allProducts>;
|
||||
export type allProducts = z.infer<typeof productDetails>;
|
||||
|
||||
export const product = z.object({
|
||||
id: z.number().optional(),
|
||||
title: z.string(),
|
||||
description: z.string(),
|
||||
address: z.string(),
|
||||
// category: z.string(),
|
||||
stock: z.number(),
|
||||
price: z.string(),
|
||||
urlImg: z.string(),
|
||||
userId: z.number().optional()
|
||||
});
|
||||
})
|
||||
|
||||
export const productDetails = product.extend({
|
||||
fullname: z.string(),
|
||||
phone: z.string().nullable(),
|
||||
email: z.string().email().nullable()
|
||||
})
|
||||
|
||||
export const editInventory = z.object({
|
||||
id: z.number().optional(),
|
||||
@@ -31,16 +38,16 @@ export const editInventory = z.object({
|
||||
userId: z.number().optional(),
|
||||
})
|
||||
|
||||
export const allProducts = z.object({
|
||||
id: z.number().optional(),
|
||||
title: z.string().min(5, { message: "Debe de tener 5 o más caracteres" }),
|
||||
description: z.string().min(10, { message: "Debe de tener 10 o más caracteres" }),
|
||||
stock: z.number(),
|
||||
price: z.string(),
|
||||
urlImg: z.string(),
|
||||
userId: z.number(),
|
||||
fullname: z.string()
|
||||
})
|
||||
// export const productDetails = z.object({
|
||||
// id: z.number().optional(),
|
||||
// title: z.string().min(5),
|
||||
// description: z.string().min(10),
|
||||
// stock: z.number(),
|
||||
// price: z.string(),
|
||||
// address: z.string(),
|
||||
// urlImg: z.string(),
|
||||
// userId: z.number(),
|
||||
// })
|
||||
|
||||
export const ApiResponseSchema = z.object({
|
||||
message: z.string(),
|
||||
@@ -59,7 +66,7 @@ export const ApiResponseSchema = z.object({
|
||||
|
||||
export const productApiResponseSchema = z.object({
|
||||
message: z.string(),
|
||||
data: z.array(allProducts),
|
||||
data: z.array(productDetails),
|
||||
meta: z.object({
|
||||
page: z.number(),
|
||||
limit: z.number(),
|
||||
@@ -79,5 +86,5 @@ export const productMutate = z.object({
|
||||
|
||||
export const getProduct = z.object({
|
||||
message: z.string(),
|
||||
data: allProducts,
|
||||
data: productDetails,
|
||||
})
|
||||
Reference in New Issue
Block a user