pos-be/src/modules/item-related/item/infrastructure/item-data.controller.ts

91 lines
2.7 KiB
TypeScript

import {
Body,
Controller,
Delete,
Param,
Patch,
Post,
Put,
UseGuards,
} from '@nestjs/common';
import { ItemDataOrchestrator } from '../domain/usecases/item-data.orchestrator';
import { ItemDto } from './dto/item.dto';
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { ItemEntity } from '../domain/entities/item.entity';
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto';
import { Public } from 'src/core/guards';
import { UpdateItemPriceDto } from './dto/update-item-price.dto';
import { OtpCheckerGuard } from 'src/core/guards/domain/otp-checker.guard';
@ApiTags(`${MODULE_NAME.ITEM.split('-').join(' ')} - data`)
@Controller(`v1/${MODULE_NAME.ITEM}`)
@Public(false)
@ApiBearerAuth('JWT')
export class ItemDataController {
constructor(private orchestrator: ItemDataOrchestrator) {}
@Post()
async create(@Body() data: ItemDto): Promise<ItemEntity> {
return await this.orchestrator.create(data);
}
@Public(true)
@Post('update-price')
async updatePrice(@Body() body: UpdateItemPriceDto): Promise<any> {
return await this.orchestrator.updatePrice(body);
}
@Put('/batch-delete')
async batchDeleted(@Body() body: BatchIdsDto): Promise<BatchResult> {
return await this.orchestrator.batchDelete(body.ids);
}
@Patch(':id/active')
@UseGuards(OtpCheckerGuard)
async active(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.active(dataId);
}
@Put('/batch-active')
async batchActive(@Body() body: BatchIdsDto): Promise<BatchResult> {
return await this.orchestrator.batchActive(body.ids);
}
@Patch(':id/confirm')
@UseGuards(OtpCheckerGuard)
async confirm(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.confirm(dataId);
}
@Put('/batch-confirm')
async batchConfirm(@Body() body: BatchIdsDto): Promise<BatchResult> {
return await this.orchestrator.batchConfirm(body.ids);
}
@Patch(':id/inactive')
async inactive(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.inactive(dataId);
}
@Put('/batch-inactive')
async batchInactive(@Body() body: BatchIdsDto): Promise<BatchResult> {
return await this.orchestrator.batchInactive(body.ids);
}
@Put(':id')
@UseGuards(OtpCheckerGuard)
async update(
@Param('id') dataId: string,
@Body() data: ItemDto,
): Promise<ItemEntity> {
return await this.orchestrator.update(dataId, data);
}
@Delete(':id')
async delete(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.delete(dataId);
}
}