mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 21:14:54 +00:00
added product controller
This commit is contained in:
1
src/product/controllers/index.ts
Normal file
1
src/product/controllers/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './product.controller';
|
||||
27
src/product/controllers/product.controller.ts
Normal file
27
src/product/controllers/product.controller.ts
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
1
src/product/index.ts
Normal file
1
src/product/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './product.module';
|
||||
10
src/product/product.module.ts
Normal file
10
src/product/product.module.ts
Normal file
@ -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 {}
|
||||
1
src/product/services/index.ts
Normal file
1
src/product/services/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './product.service';
|
||||
24
src/product/services/product.service.ts
Normal file
24
src/product/services/product.service.ts
Normal file
@ -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