diff --git a/apps/api/src/features/inventory/inventory.controller.ts b/apps/api/src/features/inventory/inventory.controller.ts index 2865279..98f7400 100644 --- a/apps/api/src/features/inventory/inventory.controller.ts +++ b/apps/api/src/features/inventory/inventory.controller.ts @@ -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 }; + } diff --git a/apps/web/app/dashboard/productos/[id]/page.tsx b/apps/web/app/dashboard/productos/[id]/page.tsx index 53ac9bd..aa0bcd4 100644 --- a/apps/web/app/dashboard/productos/[id]/page.tsx +++ b/apps/web/app/dashboard/productos/[id]/page.tsx @@ -30,65 +30,8 @@ export default async function SurveyResponsePage({ if (!data?.data) { return
Encuesta no encontrada
; } - - 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 ( - - // - //
- //
- - // - - //
- // - //
- //
- // - // - // - // {product.title.charAt(0).toUpperCase() + product.title.slice(1)} - // - //

$ {product.price}

- // {product.status === 'AGOTADO' ? ( - //

AGOTADO

- // ) : ('')} - //
- // - //
- //

Descripción

- //

{product.description}

- // {/*

{lorem+lorem+lorem+lorem}

*/} - //
- - //
- //

Dirección

- //

{product.address}

- //
- //
- - // - //
- //

Información del vendedor

- //

{product.fullname}

- //

{product.phone}

- //

{product.email}

- //
- //
- //
- //
+ ); } \ No newline at end of file diff --git a/apps/web/feactures/inventory/actions/actions.ts b/apps/web/feactures/inventory/actions/actions.ts index 960ce53..914034a 100644 --- a/apps/web/feactures/inventory/actions/actions.ts +++ b/apps/web/feactures/inventory/actions/actions.ts @@ -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) => { - try { - // const { id, urlImg, ...payloadWithoutId } = payload; - - // const formData = new FormData(); - // formData.append('file', urlImg); - - - // console.log(formData); - - +export const updateProductAction = async (payload: InventoryTable) => { + try { 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, diff --git a/apps/web/feactures/inventory/hooks/use-mutation.ts b/apps/web/feactures/inventory/hooks/use-mutation.ts index e5fa84b..98e9797 100644 --- a/apps/web/feactures/inventory/hooks/use-mutation.ts +++ b/apps/web/feactures/inventory/hooks/use-mutation.ts @@ -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) }) diff --git a/apps/web/feactures/inventory/schemas/inventory.ts b/apps/web/feactures/inventory/schemas/inventory.ts index 094676e..0d02265 100644 --- a/apps/web/feactures/inventory/schemas/inventory.ts +++ b/apps/web/feactures/inventory/schemas/inventory.ts @@ -3,7 +3,7 @@ import { url } from 'inspector'; import { z } from 'zod'; -export type InventoryTable = z.infer; +export type InventoryTable = z.infer; export type EditInventory = z.infer; export type ProductApiResponseSchema = z.infer; export type allProducts = z.infer; @@ -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().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({ diff --git a/apps/web/public/uploads/inventory/1/7/1-D_NQ_NP_989621-MLV81067179982_122024-O.webp b/apps/web/public/uploads/inventory/1/7/1-D_NQ_NP_989621-MLV81067179982_122024-O.webp deleted file mode 100644 index 5f45489..0000000 Binary files a/apps/web/public/uploads/inventory/1/7/1-D_NQ_NP_989621-MLV81067179982_122024-O.webp and /dev/null differ