feat(products): update products service, controller and module
Updated products.service.ts to improve product fetching with added console logs and response modifications. Endpoint name in products.controller.ts has been changed from 'new' to 'add' with parameter adjustments for fetching. In products.module.ts, CredentialsModule was imported for enhanced functionality.
This commit is contained in:
parent
5ee51daf82
commit
b9b2adb804
@ -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)
|
||||
|
@ -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]
|
||||
})
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user