diff --git a/src/products/products.controller.ts b/src/products/products.controller.ts index 75fca83..c294fc4 100644 --- a/src/products/products.controller.ts +++ b/src/products/products.controller.ts @@ -21,7 +21,7 @@ export class ProductsController { @HttpCode(HttpStatus.CREATED) @UseGuards(AdminGuard) - @Post('new') + @Post('add') async newProduct(@Body() dto: CreateProductDto) { const result = await this.productsService.add(dto) if (result.count !== 1) { @@ -33,7 +33,7 @@ export class ProductsController { @HttpCode(HttpStatus.OK) @Get("all") async getAllProducts(@Query('page') page: number) { - return this.productsService.findAll(page || 0, 20); + return this.productsService.findAll(Number(page) || 1, 2); } @HttpCode(HttpStatus.OK) diff --git a/src/products/products.module.ts b/src/products/products.module.ts index 99f61cf..0815b30 100644 --- a/src/products/products.module.ts +++ b/src/products/products.module.ts @@ -2,9 +2,10 @@ import { Module } from '@nestjs/common'; import { ProductsController } from './products.controller'; import { ProductsService } from './products.service'; import { DrizzleModule } from "src/drizzle/drizzle.module"; +import { CredentialsModule } from "src/credentials/credentials.module"; @Module({ - imports: [DrizzleModule], + imports: [DrizzleModule, CredentialsModule], controllers: [ProductsController], providers: [ProductsService] }) diff --git a/src/products/products.service.ts b/src/products/products.service.ts index de22626..80730b5 100644 --- a/src/products/products.service.ts +++ b/src/products/products.service.ts @@ -73,6 +73,8 @@ export class ProductsService { .prepare("countProducts") .execute(); + console.log(count, {page: page}, {limit: limit}) + const res = await this.db.use() .select() .from(ProductsTable) @@ -82,8 +84,9 @@ export class ProductsService { .execute(); console.log(`Fetching products (page ${page}, limit ${limit}) ...\n`) const response = { - total: count[0].total, - page: page, + maxPage: (Math.round(count[0].total / limit)), + currentPage: page, + totalProducts: count[0].total, productsPerPage: limit, products: res }