diff --git a/apps/api/src/database/schema/inventory.ts b/apps/api/src/database/schema/inventory.ts index 300d452..c3381ee 100644 --- a/apps/api/src/database/schema/inventory.ts +++ b/apps/api/src/database/schema/inventory.ts @@ -25,8 +25,10 @@ export const viewProductsStore = t.pgView('v_product_store', { stock: t.integer('stock'), urlImg: t.text('url_img'), userId: t.integer('user_id'), - fullname: t.text('fullname') + 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 + 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`); \ No newline at end of file diff --git a/apps/api/src/features/inventory/entities/inventory.entity.ts b/apps/api/src/features/inventory/entities/inventory.entity.ts index cbd6420..6599083 100644 --- a/apps/api/src/features/inventory/entities/inventory.entity.ts +++ b/apps/api/src/features/inventory/entities/inventory.entity.ts @@ -6,6 +6,7 @@ export class Product { stock: number | null; urlImg: string | null; userId?: number | null; + fullname?: string | null; } export class Inventory { diff --git a/apps/api/src/features/inventory/inventory.controller.ts b/apps/api/src/features/inventory/inventory.controller.ts index 80779c5..1dd0922 100644 --- a/apps/api/src/features/inventory/inventory.controller.ts +++ b/apps/api/src/features/inventory/inventory.controller.ts @@ -30,8 +30,8 @@ export class UsersController { @ApiResponse({ status: 200, description: 'Return paginated products.' }) async findAllByUserId(@Req() req: Request, @Query() paginationDto: PaginationDto) { console.log(req['user'].id) - const id = 1 - // const id = Number(req['user'].id); + // const id = 1 + const id = Number(req['user'].id); const result = await this.inventoryService.findAllByUserId(id,paginationDto); return { message: 'products fetched successfully', @@ -40,7 +40,7 @@ export class UsersController { }; } - @Get(':id') + @Get('/id/:id') // @Roles('admin') @ApiOperation({ summary: 'Get a product by ID' }) @ApiResponse({ status: 200, description: 'Return the product.' }) diff --git a/apps/api/src/features/inventory/inventory.service.ts b/apps/api/src/features/inventory/inventory.service.ts index b0bcf9d..7b37e89 100644 --- a/apps/api/src/features/inventory/inventory.service.ts +++ b/apps/api/src/features/inventory/inventory.service.ts @@ -141,15 +141,17 @@ export class InventoryService { async findOne(id: string): Promise { const find = await this.drizzle .select({ - id: products.id, - title: products.title, - description: products.description, - price: products.price, - urlImg: products.urlImg, - stock: products.stock + id: viewProductsStore.id, + title: viewProductsStore.title, + description: viewProductsStore.description, + price: viewProductsStore.price, + urlImg: viewProductsStore.urlImg, + stock: viewProductsStore.stock, + userId: viewProductsStore.userId, + fullname: viewProductsStore.fullname }) - .from(products) - .where(eq(products.id, parseInt(id))); + .from(viewProductsStore) + .where(eq(viewProductsStore.id, parseInt(id))); if (find.length === 0) { throw new HttpException('Product does not exist', HttpStatus.BAD_REQUEST); diff --git a/apps/api/src/features/users/users.controller.ts b/apps/api/src/features/users/users.controller.ts index 80d26fc..efaf668 100644 --- a/apps/api/src/features/users/users.controller.ts +++ b/apps/api/src/features/users/users.controller.ts @@ -40,12 +40,11 @@ export class UsersController { @ApiResponse({ status: 201, description: 'User created successfully.' }) async create( @Body() createUserDto: CreateUserDto, - @Query('roleId') roleId?: string, + @Query('role') role?: string, ) { - const data = await this.usersService.create( - createUserDto, - roleId ? parseInt(roleId) : undefined, - ); + console.log(role); + + const data = await this.usersService.create(createUserDto) return { message: 'User created successfully', data }; } diff --git a/apps/api/src/features/users/users.service.ts b/apps/api/src/features/users/users.service.ts index ec6a114..64cf2e0 100644 --- a/apps/api/src/features/users/users.service.ts +++ b/apps/api/src/features/users/users.service.ts @@ -159,7 +159,7 @@ export class UsersService { // Assign role to user await tx.insert(usersRole).values({ userId: newUser.id, - roleId: roleId, + roleId: createUserDto.role || roleId, }); // Return the created user with role diff --git a/apps/web/app/dashboard/productos/[id]/page.tsx b/apps/web/app/dashboard/productos/[id]/page.tsx index fb4037e..cc87e82 100644 --- a/apps/web/app/dashboard/productos/[id]/page.tsx +++ b/apps/web/app/dashboard/productos/[id]/page.tsx @@ -1,7 +1,16 @@ -import PageContainer from '@/components/layout/page-container'; -import { getSurveyByIdAction } from '@/feactures/surveys/actions/surveys-actions'; -import { SurveyResponse } from '@/feactures/surveys/components/survey-response'; +// 'use client'; +// import PageContainer from '@/components/layout/page-container'; +import { getProductById } from '@/feactures/inventory/actions/actions'; +// import { SurveyResponse } from '@/feactures/surveys/components/survey-response'; +import { + Card, + CardContent, + CardFooter, + CardHeader, + CardTitle, +} from '@repo/shadcn/card'; +import { Edit } from 'lucide-react'; export default async function SurveyResponsePage({ @@ -17,17 +26,47 @@ export default async function SurveyResponsePage({ } // Call the function passing the dynamic id - const data = await getSurveyByIdAction(Number(id)); + const data = await getProductById(Number(id)); if (!data?.data) { return
Encuesta no encontrada
; } + const product = data.data + + // console.log(data.data); + + return ( - -
- -
-
+ // +
+ + + + + {product.title.charAt(0).toUpperCase() + product.title.slice(1)} + +

$ {product.price}

+
+ +

Descripción

+

{product.description}

+ +
+ +
+

Información del vendedor

+

{product.fullname}

+

Correo@gmail.com

+

0412-7848101

+
+ {/*

$ {product.price}

*/} +
+
+
); } \ No newline at end of file diff --git a/apps/web/app/dashboard/productos/page.tsx b/apps/web/app/dashboard/productos/page.tsx index 03de14f..5d96c70 100644 --- a/apps/web/app/dashboard/productos/page.tsx +++ b/apps/web/app/dashboard/productos/page.tsx @@ -1,5 +1,6 @@ import PageContainer from '@/components/layout/page-container'; -import { SurveyList } from '@/feactures/inventory/components/products/product-list'; +import { ProductList } from '@/feactures/inventory/components/products/product-list'; +import { Button } from '@repo/shadcn/components/ui/button'; import { Metadata } from 'next'; export const metadata: Metadata = { @@ -8,14 +9,18 @@ export const metadata: Metadata = { }; export default function SurveysPage() { - return ( - -
-

Productos Disponibles

- -
-
+ // +
+
+

Productos Disponibles

+ + + +
+ +
+ //
); } \ No newline at end of file diff --git a/apps/web/constants/data.ts b/apps/web/constants/data.ts index de2edfe..d391faf 100644 --- a/apps/web/constants/data.ts +++ b/apps/web/constants/data.ts @@ -11,8 +11,8 @@ export const GeneralItems: NavItem[] = [ items: [], // No child items }, { - title: 'Inventario', - url: '/dashboard/inventario/', + title: 'ProduTienda', + url: '/dashboard/productos/', icon: 'blocks', shortcut: ['p', 'p'], isActive: false, diff --git a/apps/web/feactures/inventory/actions/actions.ts b/apps/web/feactures/inventory/actions/actions.ts index f9a0eb7..4ced31c 100644 --- a/apps/web/feactures/inventory/actions/actions.ts +++ b/apps/web/feactures/inventory/actions/actions.ts @@ -5,7 +5,8 @@ import { InventoryTable, productMutate, // editInventory, - productApiResponseSchema + productApiResponseSchema, + getProduct } from '../schemas/inventory'; import { auth } from '@/lib/auth'; @@ -81,7 +82,7 @@ export const getAllProducts = async (params: { ); if (error) { - console.error('Error:', error); + console.error('Errorrrrr:', error.details); throw new Error(error.message); } @@ -100,6 +101,21 @@ export const getAllProducts = async (params: { }; }; +export const getProductById = async (id: number) => { + const [error, data] = await safeFetchApi( + getProduct, + `/products/id/${id}`, + 'GET', + ); + + if (error) { + console.error('❌ Error en la API:', error); + throw new Error(error.message); + } + + return data; +}; + export const createProductAction = async (payload: InventoryTable) => { const session = await auth() const userId = session?.user?.id diff --git a/apps/web/feactures/inventory/components/inventory/product-tables/columns.tsx b/apps/web/feactures/inventory/components/inventory/product-tables/columns.tsx index a9b47bf..426a721 100644 --- a/apps/web/feactures/inventory/components/inventory/product-tables/columns.tsx +++ b/apps/web/feactures/inventory/components/inventory/product-tables/columns.tsx @@ -9,9 +9,9 @@ export const columns: ColumnDef[] = [ accessorKey: 'urlImg', header: 'img', cell: ({ row }) => { - const status = row.getValue("urlImg") as string | undefined; + const url = row.getValue("urlImg") as string | undefined; return ( - Image + ) }, }, diff --git a/apps/web/feactures/inventory/components/products/product-list.tsx b/apps/web/feactures/inventory/components/products/product-list.tsx index 04d7841..ccf42b0 100644 --- a/apps/web/feactures/inventory/components/products/product-list.tsx +++ b/apps/web/feactures/inventory/components/products/product-list.tsx @@ -1,67 +1,54 @@ -// Este componente maneja la lista de encuestas en el panel de administración -// Funcionalidades: -// - Muestra todas las encuestas en una tabla -// - Permite editar encuestas existentes -// - Permite eliminar encuestas con confirmación -// - Muestra el estado (publicada/borrador), fechas y conteo de respuestas - - 'use client'; -import { Button } from '@repo/shadcn/button'; import { Card, CardContent, - CardDescription, CardFooter, CardHeader, CardTitle, } from '@repo/shadcn/card'; import { useRouter } from 'next/navigation'; -// import { useSurveysForUserQuery } from '@/feactures/surveys/hooks/use-query-surveys'; import { useAllProductQuery } from '@/feactures/inventory/hooks/use-query-products'; import { allProducts } from '../../schemas/inventory'; -import { Badge } from '@repo/shadcn/badge'; -import { BadgeCheck } from 'lucide-react'; - -export function SurveyList() { +import { ImageIcon } from 'lucide-react'; +export function ProductList() { const router = useRouter(); - const {data: produts} = useAllProductQuery() + const { data: produts } = useAllProductQuery(); - const handleRespond = (surveyId: number) => { - router.push(`/dashboard/productos/${surveyId}`); + const handle = (id: number) => { + router.push(`/dashboard/productos/${id}`); }; - // console.log(produts?.data) return ( -
+
{produts?.meta.totalPages === 0 ? ( -
-

No hay productos disponibles en este momento.

-
+
+

+ No hay productos disponibles en este momento. +

+
) : ( produts?.data.map((data: allProducts) => ( - - + handle(Number(data.id))} + > - {data.title} - {data.description} + + {data.title.charAt(0).toUpperCase() + data.title.slice(1)} + - -
-
- -
-
+ + - - + +

$ {data.price}

)) diff --git a/apps/web/feactures/inventory/schemas/inventory.ts b/apps/web/feactures/inventory/schemas/inventory.ts index 0aab4e4..2823f0e 100644 --- a/apps/web/feactures/inventory/schemas/inventory.ts +++ b/apps/web/feactures/inventory/schemas/inventory.ts @@ -16,7 +16,7 @@ export const product = z.object({ stock: z.number(), price: z.string(), urlImg: z.string(), - userId: z.number().optional(), + userId: z.number().optional() }); export const editInventory = z.object({ @@ -38,10 +38,8 @@ export const allProducts = z.object({ stock: z.number(), price: z.string(), urlImg: z.string(), - user: z.object({ - userId: z.number(), - username: z.string(), - }) + userId: z.number(), + fullname: z.string() }) export const ApiResponseSchema = z.object({ @@ -77,4 +75,9 @@ export const productApiResponseSchema = z.object({ export const productMutate = z.object({ message: z.string(), data: product, +}) + +export const getProduct = z.object({ + message: z.string(), + data: allProducts, }) \ No newline at end of file diff --git a/apps/web/feactures/users/components/admin/create-user-form.tsx b/apps/web/feactures/users/components/admin/create-user-form.tsx index b0339d9..ce1dc6e 100644 --- a/apps/web/feactures/users/components/admin/create-user-form.tsx +++ b/apps/web/feactures/users/components/admin/create-user-form.tsx @@ -68,10 +68,9 @@ export function CreateUserForm({ mode: 'onChange', // Enable real-time validation }); - const onSubmit = async (data: CreateUser) => { - - const formData = data - + const onSubmit = async (formData: CreateUser) => { + console.log(formData); + saveAccountingAccounts(formData, { onSuccess: () => { form.reset();