-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathpartner.controller.ts
More file actions
54 lines (49 loc) · 2.31 KB
/
partner.controller.ts
File metadata and controls
54 lines (49 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { Body, Controller, Get, Param, Patch, Post, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiBody, ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
import { formatPartnerObject } from 'src/utils/serialize';
import { PartnerEntity } from '../entities/partner.entity';
import { SuperAdminAuthGuard } from '../partner-admin/super-admin-auth.guard';
import { ControllerDecorator } from '../utils/controller.decorator';
import { CreatePartnerDto } from './dtos/create-partner.dto';
import { UpdatePartnerDto } from './dtos/update-partner.dto';
import { PartnerParamDto, PartnerIdParamDto } from './dtos/partner-param.dto';
import { IPartner } from './partner.interface';
import { PartnerService } from './partner.service';
@ApiTags('Partner')
@ControllerDecorator()
@Controller('/v1/partner')
export class PartnerController {
constructor(private partnerService: PartnerService) {}
@ApiBearerAuth('access-token')
@ApiOperation({ description: 'Creates basic profile data for a partner' })
@UseGuards(SuperAdminAuthGuard)
@Post()
@ApiBody({ type: CreatePartnerDto })
async createPartner(
@Body() createPartnerDto: CreatePartnerDto,
): Promise<PartnerEntity | unknown> {
return this.partnerService.createPartner(createPartnerDto);
}
@ApiBearerAuth('access-token')
@ApiOperation({ description: 'Returns profile data for all partners' })
@UseGuards(SuperAdminAuthGuard)
@Get()
async getPartners(): Promise<PartnerEntity[]> {
return this.partnerService.getPartners();
}
@Get(':name')
@ApiOperation({ description: 'Returns profile data for a partner (public endpoint)' })
@ApiParam({ name: 'name', description: 'Gets partner by name' })
async getPartner(@Param() params: PartnerParamDto): Promise<IPartner> {
const partnerResponse = await this.partnerService.getPartnerWithPartnerFeaturesByName(params.name);
return formatPartnerObject(partnerResponse);
}
@ApiBearerAuth('access-token')
@UseGuards(SuperAdminAuthGuard)
@Patch(':id')
@ApiOperation({ description: 'Update a partner profile to make partner active or inactive' })
@ApiBody({ type: UpdatePartnerDto })
async updatePartnerActiveStatus(@Param() params: PartnerIdParamDto, @Body() updatePartnerDto: UpdatePartnerDto) {
return this.partnerService.updatePartnerActiveStatus(params.id, updatePartnerDto);
}
}