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

89 lines
2.7 KiB
TypeScript

import {
Body,
Controller,
Delete,
Param,
Patch,
Post,
Put,
} from '@nestjs/common';
import { UserDataOrchestrator } from '../domain/usecases/user-data.orchestrator';
import { UserDto } from './dto/user.dto';
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { UserEntity } from '../domain/entities/user.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 { UpdateUserDto } from './dto/update-user.dto';
import { UpdatePasswordUserDto } from './dto/update-password-user.dto';
@ApiTags(`${MODULE_NAME.USER.split('-').join(' ')} - data`)
@Controller(MODULE_NAME.USER)
@Public(false)
@ApiBearerAuth('JWT')
export class UserDataController {
constructor(private orchestrator: UserDataOrchestrator) {}
@Post()
async create(@Body() data: UserDto): Promise<UserEntity> {
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: UpdateUserDto,
): Promise<UserEntity> {
return await this.orchestrator.update(dataId, data);
}
@Put(':id/change-password')
async updatePassword(
@Param('id') dataId: string,
@Body() data: UpdatePasswordUserDto,
): Promise<UserEntity> {
return await this.orchestrator.updatePassword(dataId, data);
}
@Delete(':id')
async delete(@Param('id') dataId: string): Promise<String> {
return await this.orchestrator.delete(dataId);
}
}