2023-11-11 15:06:19 -06:00
|
|
|
import { Body, Controller, Delete, Get, Param, Post, Put, Query } from '@nestjs/common';
|
2024-08-20 08:50:14 -04:00
|
|
|
import { ApiTags } from '@nestjs/swagger';
|
2024-03-20 23:53:07 +01:00
|
|
|
import { AuthDto } from 'src/dtos/auth.dto';
|
2024-07-08 16:41:39 -04:00
|
|
|
import { PartnerResponseDto, PartnerSearchDto, UpdatePartnerDto } from 'src/dtos/partner.dto';
|
2024-08-16 09:48:43 -04:00
|
|
|
import { Permission } from 'src/enum';
|
2024-03-20 15:15:01 -05:00
|
|
|
import { Auth, Authenticated } from 'src/middleware/auth.guard';
|
2024-03-21 00:07:30 +01:00
|
|
|
import { PartnerService } from 'src/services/partner.service';
|
2024-03-20 15:04:03 -05:00
|
|
|
import { UUIDParamDto } from 'src/validation';
|
2023-05-15 20:30:53 +03:00
|
|
|
|
2024-05-30 00:26:57 +02:00
|
|
|
@ApiTags('Partners')
|
2024-05-22 13:24:57 -04:00
|
|
|
@Controller('partners')
|
2023-05-15 20:30:53 +03:00
|
|
|
export class PartnerController {
|
|
|
|
|
constructor(private service: PartnerService) {}
|
|
|
|
|
|
|
|
|
|
@Get()
|
2024-08-16 09:48:43 -04:00
|
|
|
@Authenticated({ permission: Permission.PARTNER_READ })
|
2024-07-08 16:41:39 -04:00
|
|
|
getPartners(@Auth() auth: AuthDto, @Query() dto: PartnerSearchDto): Promise<PartnerResponseDto[]> {
|
|
|
|
|
return this.service.search(auth, dto);
|
2023-05-15 20:30:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post(':id')
|
2024-08-16 09:48:43 -04:00
|
|
|
@Authenticated({ permission: Permission.PARTNER_CREATE })
|
2023-12-09 23:34:12 -05:00
|
|
|
createPartner(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto): Promise<PartnerResponseDto> {
|
|
|
|
|
return this.service.create(auth, id);
|
2023-05-15 20:30:53 +03:00
|
|
|
}
|
|
|
|
|
|
2023-11-11 15:06:19 -06:00
|
|
|
@Put(':id')
|
2024-08-16 09:48:43 -04:00
|
|
|
@Authenticated({ permission: Permission.PARTNER_UPDATE })
|
2023-11-11 15:06:19 -06:00
|
|
|
updatePartner(
|
2023-12-09 23:34:12 -05:00
|
|
|
@Auth() auth: AuthDto,
|
2023-11-11 15:06:19 -06:00
|
|
|
@Param() { id }: UUIDParamDto,
|
|
|
|
|
@Body() dto: UpdatePartnerDto,
|
|
|
|
|
): Promise<PartnerResponseDto> {
|
2023-12-09 23:34:12 -05:00
|
|
|
return this.service.update(auth, id, dto);
|
2023-11-11 15:06:19 -06:00
|
|
|
}
|
|
|
|
|
|
2023-05-15 20:30:53 +03:00
|
|
|
@Delete(':id')
|
2024-08-16 09:48:43 -04:00
|
|
|
@Authenticated({ permission: Permission.PARTNER_DELETE })
|
2023-12-09 23:34:12 -05:00
|
|
|
removePartner(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto): Promise<void> {
|
|
|
|
|
return this.service.remove(auth, id);
|
2023-05-15 20:30:53 +03:00
|
|
|
}
|
|
|
|
|
}
|