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

79 lines
2.4 KiB
TypeScript

import {
Body,
Controller,
Delete,
Param,
Patch,
Post,
Put,
} from '@nestjs/common';
import { TimeGroupDataOrchestrator } from '../domain/usecases/time-group-data.orchestrator';
import { CreateTimeGroupDto, EditTimeGroupDto } from './dto/time-group.dto';
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { TimeGroupEntity } from '../domain/entities/time-group.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';
@ApiTags(`${MODULE_NAME.TIME_GROUPS.split('-').join(' ')} - data`)
@Controller(`v1/${MODULE_NAME.TIME_GROUPS}`)
@Public(false)
@ApiBearerAuth('JWT')
export class TimeGroupDataController {
constructor(private orchestrator: TimeGroupDataOrchestrator) {}
@Post()
async create(@Body() data: CreateTimeGroupDto): Promise<TimeGroupEntity> {
return await this.orchestrator.create(data);
}
@Put('/batch-delete')
async batchDeleted(@Body() body: BatchIdsDto): Promise<BatchResult> {
return await this.orchestrator.batchDelete(body.ids);
}
@Patch(':id/active')
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')
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')
async update(
@Param('id') dataId: string,
@Body() data: EditTimeGroupDto,
): Promise<TimeGroupEntity> {
return await this.orchestrator.update(dataId, data);
}
@Delete(':id')
async delete(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.delete(dataId);
}
}