40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { AuthDto, PartnerDirection, PartnerService } from '@app/domain';
|
|
import { PartnerResponseDto, UpdatePartnerDto } from '@app/domain/partner/partner.dto';
|
|
import { Body, Controller, Delete, Get, Param, Post, Put, Query } from '@nestjs/common';
|
|
import { ApiQuery, ApiTags } from '@nestjs/swagger';
|
|
import { Auth, Authenticated } from '../app.guard';
|
|
import { UUIDParamDto } from './dto/uuid-param.dto';
|
|
|
|
@ApiTags('Partner')
|
|
@Controller('partner')
|
|
@Authenticated()
|
|
export class PartnerController {
|
|
constructor(private service: PartnerService) {}
|
|
|
|
@Get()
|
|
@ApiQuery({ name: 'direction', type: 'string', enum: PartnerDirection, required: true })
|
|
// TODO: remove 'direction' and convert to full query dto
|
|
getPartners(@Auth() auth: AuthDto, @Query('direction') direction: PartnerDirection): Promise<PartnerResponseDto[]> {
|
|
return this.service.getAll(auth, direction);
|
|
}
|
|
|
|
@Post(':id')
|
|
createPartner(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto): Promise<PartnerResponseDto> {
|
|
return this.service.create(auth, id);
|
|
}
|
|
|
|
@Put(':id')
|
|
updatePartner(
|
|
@Auth() auth: AuthDto,
|
|
@Param() { id }: UUIDParamDto,
|
|
@Body() dto: UpdatePartnerDto,
|
|
): Promise<PartnerResponseDto> {
|
|
return this.service.update(auth, id, dto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
removePartner(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto): Promise<void> {
|
|
return this.service.remove(auth, id);
|
|
}
|
|
}
|