Cambios de nombres de variables y esquema
This commit is contained in:
@@ -68,20 +68,20 @@ export class UsersController {
|
||||
}
|
||||
|
||||
@Patch('/upload')
|
||||
@ApiOperation({ summary: 'Update a product' })
|
||||
@ApiResponse({ status: 200, description: 'Product uploaded successfully.'})
|
||||
@ApiResponse({ status: 404, description: 'Product not found.' })
|
||||
@ApiResponse({ status: 500, description: 'Internal server error.' })
|
||||
@UseInterceptors(FilesInterceptor('urlImg'))
|
||||
async uploadFile(
|
||||
@Req() req: Request,
|
||||
@UploadedFiles() files: Express.Multer.File[],
|
||||
@Body() body: any
|
||||
) {
|
||||
const id = Number(req['user'].id);
|
||||
const result = await this.inventoryService.saveImages(files,body,id);
|
||||
return { data: result };
|
||||
}
|
||||
@ApiOperation({ summary: 'Update a product' })
|
||||
@ApiResponse({ status: 200, description: 'Product uploaded successfully.'})
|
||||
@ApiResponse({ status: 404, description: 'Product not found.' })
|
||||
@ApiResponse({ status: 500, description: 'Internal server error.' })
|
||||
@UseInterceptors(FilesInterceptor('urlImg'))
|
||||
async uploadFile(
|
||||
@Req() req: Request,
|
||||
@UploadedFiles() files: Express.Multer.File[],
|
||||
@Body() body: any
|
||||
) {
|
||||
const id = Number(req['user'].id);
|
||||
const result = await this.inventoryService.saveImages(files,body,id);
|
||||
return { data: result };
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -31,64 +31,7 @@ export default async function SurveyResponsePage({
|
||||
return <div>Encuesta no encontrada</div>;
|
||||
}
|
||||
|
||||
const product = 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 (
|
||||
<ProductList product={product} />
|
||||
// <PageContainer>
|
||||
// <main className='px-4 lg:px-6 flex flex-col md:flex-row gap-3 lg:gap-4 md:relative'>
|
||||
// <div className='w-full flex justify-between flex-col'>
|
||||
|
||||
// <img
|
||||
// className="border-2 object-contain w-full f-full min-h-[400px] md:h-[70vh] aspect-square rounded-2xl"
|
||||
// src={`http://localhost:3000/uploads/inventory/${product.userId}/${product.urlImg}`}
|
||||
// alt=""
|
||||
// />
|
||||
|
||||
// <section className=''>
|
||||
// <img
|
||||
// className="border-2 object-cover w-[64px] h-[64px] md:w-[96px] md:h-[96px] aspect-square rounded-2xl"
|
||||
// src={`http://localhost:3000/uploads/inventory/${product.userId}/${product.urlImg}`}
|
||||
// alt=""
|
||||
// />
|
||||
// </section>
|
||||
// </div>
|
||||
// <Card className="flex flex-col md:w-[400px] lg:w-[500px] min-h-[400px] md:h-[85vh] md:overflow-auto md:sticky top-0 right-0">
|
||||
// <CardHeader className='py-2 px-2 md:px-4 lg:px-6'>
|
||||
// <CardTitle className="font-bold text-2xl">
|
||||
// {product.title.charAt(0).toUpperCase() + product.title.slice(1)}
|
||||
// </CardTitle>
|
||||
// <p className='font-semibold'>$ {product.price} </p>
|
||||
// {product.status === 'AGOTADO' ? (
|
||||
// <p className="font-semibold text-lg text-red-900">AGOTADO</p>
|
||||
// ) : ('')}
|
||||
// </CardHeader>
|
||||
// <CardContent className="py-0 px-2 md:px-4 lg:px-6 flex-col justify-between flex-grow md:overflow-auto">
|
||||
// <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 className='mt-2'>
|
||||
// <p className='font-semibold text-lg border-t border-b'> Dirección</p>
|
||||
// <p className='p-1'>{product.address}</p>
|
||||
// </div>
|
||||
// </CardContent>
|
||||
|
||||
// <CardFooter className="px-2 md:px-4 lg:px-6">
|
||||
// <div>
|
||||
// <p className='font-semibold text-lg border-t border-b mt-4'>Información del vendedor</p>
|
||||
// <p>{product.fullname}</p>
|
||||
// <p>{product.phone}</p>
|
||||
// <p>{product.email}</p>
|
||||
// </div>
|
||||
// </CardFooter>
|
||||
// </Card>
|
||||
// </main>
|
||||
<ProductList product={data.data} />
|
||||
);
|
||||
}
|
||||
@@ -118,15 +118,8 @@ export const getProductById = async (id: number) => {
|
||||
};
|
||||
|
||||
export const createProductAction = async (payload: FormData) => {
|
||||
// const session = await auth()
|
||||
// const userId = session?.user?.id
|
||||
|
||||
// if (userId) {
|
||||
// payload.append('userId', String(userId));
|
||||
// }
|
||||
|
||||
const [error, data] = await safeFetchApi(
|
||||
test,
|
||||
productMutate,
|
||||
'/products',
|
||||
'POST',
|
||||
payload,
|
||||
@@ -140,19 +133,10 @@ export const createProductAction = async (payload: FormData) => {
|
||||
return data;
|
||||
};
|
||||
|
||||
export const updateUserAction2 = async (payload: InventoryTable) => {
|
||||
export const updateProductAction = async (payload: InventoryTable) => {
|
||||
try {
|
||||
// const { id, urlImg, ...payloadWithoutId } = payload;
|
||||
|
||||
// const formData = new FormData();
|
||||
// formData.append('file', urlImg);
|
||||
|
||||
|
||||
// console.log(formData);
|
||||
|
||||
|
||||
const [error, data] = await safeFetchApi(
|
||||
test,
|
||||
productMutate,
|
||||
`/products/upload`,
|
||||
'PATCH',
|
||||
payload,
|
||||
@@ -170,27 +154,6 @@ export const updateUserAction2 = async (payload: InventoryTable) => {
|
||||
}
|
||||
}
|
||||
|
||||
export const updateUserAction = async (payload: InventoryTable) => {
|
||||
try {
|
||||
const { id, ...payloadWithoutId } = payload;
|
||||
|
||||
const [error, data] = await safeFetchApi(
|
||||
productMutate,
|
||||
`/products/${id}`,
|
||||
'PATCH',
|
||||
payloadWithoutId,
|
||||
);
|
||||
|
||||
if (error) {
|
||||
console.error(error);
|
||||
throw new Error(error?.message || 'Error al actualizar el producto');
|
||||
}
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
export const deleteProductAction = async (id: Number) => {
|
||||
const [error] = await safeFetchApi(
|
||||
productMutate,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { EditInventory } from "../schemas/inventory";
|
||||
import { updateUserAction, createProductAction, updateUserAction2 } from "../actions/actions";
|
||||
// import { EditInventory } from "../schemas/inventory";
|
||||
import { updateProductAction, createProductAction, } from "../actions/actions";
|
||||
|
||||
// Create mutation
|
||||
export function useCreateProduct() {
|
||||
@@ -17,7 +17,7 @@ export function useUpdateProduct() {
|
||||
const queryClient = useQueryClient();
|
||||
const mutation = useMutation({
|
||||
// mutationFn: (data: EditInventory) => updateUserAction(data),
|
||||
mutationFn: (data: any) => updateUserAction2(data),
|
||||
mutationFn: (data: any) => updateProductAction(data),
|
||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['product'] }),
|
||||
onError: (e) => console.error('Error:', e)
|
||||
})
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { url } from 'inspector';
|
||||
import { z } from 'zod';
|
||||
|
||||
export type InventoryTable = z.infer<typeof product>;
|
||||
export type InventoryTable = z.infer<typeof seeProduct>;
|
||||
export type EditInventory = z.infer<typeof editInventory>;
|
||||
export type ProductApiResponseSchema = z.infer<typeof productApiResponseSchema>;
|
||||
export type allProducts = z.infer<typeof productDetails>;
|
||||
@@ -17,12 +17,10 @@ export const product = z.object({
|
||||
title: z.string(),
|
||||
description: z.string(),
|
||||
address: z.string(),
|
||||
// category: z.string(),
|
||||
stock: z.number(),
|
||||
price: z.string(),
|
||||
urlImg: z.custom<FileList | undefined>().optional(),
|
||||
gallery: z.array(z.string()).optional(),
|
||||
// urlImg: z.string(),
|
||||
status: z.string(),
|
||||
userId: z.number().optional()
|
||||
})
|
||||
@@ -98,7 +96,7 @@ export const test = z.object({
|
||||
|
||||
export const productMutate = z.object({
|
||||
message: z.string(),
|
||||
data: product,
|
||||
data: seeProduct,
|
||||
})
|
||||
|
||||
export const getProduct = z.object({
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 9.9 KiB |
Reference in New Issue
Block a user