mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-23 12:37:55 +00:00
added product controller
This commit is contained in:
@@ -0,0 +1 @@
|
||||
export * from './product.controller';
|
||||
@@ -0,0 +1,27 @@
|
||||
import { Controller, Get, UseGuards } from '@nestjs/common';
|
||||
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { ControllerRoute } from '@app/common/constants/controller-route';
|
||||
import { ProductService } from '../services';
|
||||
|
||||
@ApiTags('Product Module')
|
||||
@Controller({
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: ControllerRoute.PRODUCT.ROUTE,
|
||||
})
|
||||
export class ProductController {
|
||||
constructor(private readonly productService: ProductService) {}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get()
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.PRODUCT.ACTIONS.LIST_PRODUCT_SUMMARY,
|
||||
description: ControllerRoute.PRODUCT.ACTIONS.LIST_PRODUCT_DESCRIPTION,
|
||||
})
|
||||
async getProducts(): Promise<BaseResponseDto> {
|
||||
return await this.productService.list();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './product.module';
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ProductService } from './services';
|
||||
import { ProductRepository } from '@app/common/modules/product/repositories';
|
||||
import { ProductController } from './controllers';
|
||||
|
||||
@Module({
|
||||
controllers: [ProductController],
|
||||
providers: [ProductService, ProductRepository],
|
||||
})
|
||||
export class ProductModule {}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './product.service';
|
||||
@@ -0,0 +1,24 @@
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||
import { ProductRepository } from '@app/common/modules/product/repositories';
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class ProductService {
|
||||
constructor(private readonly productRepository: ProductRepository) {}
|
||||
|
||||
async list(): Promise<BaseResponseDto> {
|
||||
const products = await this.productRepository.find();
|
||||
|
||||
if (!products) {
|
||||
throw new HttpException(
|
||||
`No products found in the system`,
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
return new SuccessResponseDto({
|
||||
data: products,
|
||||
message: 'List of products retrieved successfully',
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user