-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomer.controller.ts
143 lines (133 loc) · 3.92 KB
/
customer.controller.ts
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import {
Controller,
Get,
Post,
Put,
Delete,
Param,
Body,
ValidationPipe,
Query,
} from '@nestjs/common';
import {
ApiTags,
ApiOperation,
ApiResponse,
ApiBearerAuth,
} from '@nestjs/swagger';
import { ResponseDTO } from '../../common/dtos/response.dto';
import { CustomerService } from './customer.service';
import { CreateCustomerDto } from './dtos/create.customer.dto';
import { kycRequirements } from './dtos/kyc.requirements.dto';
import { SkipJwtAuth } from 'src/common/decorators/skip-guard.decorator';
import { SubmitKycDto } from './dtos/submit.kyc.dto';
import { UpdateKycDto } from './dtos/update.kyc.dto';
import { LoadNamesDTO } from '../individual-customer/dtos/load-names.dto';
@ApiBearerAuth('JWT-auth')
@ApiTags('Customer')
@Controller('customer')
export class CustomerController {
constructor(private readonly customerService: CustomerService) {}
@SkipJwtAuth()
@Get()
@ApiOperation({ summary: 'Get all customer' })
@ApiResponse({ status: 200, description: 'Return all customer' })
async getAll(): Promise<ResponseDTO> {
return await this.customerService.getAll({});
}
@SkipJwtAuth()
@Get('/kycRequirements')
@ApiOperation({
summary: 'List KYC Requirements',
})
async getKycRequirements(
@Query(new ValidationPipe({ transform: true }))
kycRequirements: kycRequirements,
): Promise<ResponseDTO> {
return await this.customerService.getKycRequirements(
kycRequirements.country,
);
}
@SkipJwtAuth()
@Get(':id')
@ApiOperation({ summary: 'Get a customer by id' })
@ApiResponse({ status: 200, description: 'Return a customer' })
async getOne(@Param('id') id: string): Promise<ResponseDTO> {
return await this.customerService.findOne({ id });
}
@SkipJwtAuth()
@Post()
@ApiOperation({ summary: 'Create a new customer' })
@ApiResponse({
status: 201,
description: 'The customer has been successfully created.',
})
async create(@Body() Customer: CreateCustomerDto): Promise<ResponseDTO> {
return await this.customerService.save(Customer);
}
@SkipJwtAuth()
@Put(':id')
@ApiOperation({ summary: 'Update a customer' })
@ApiResponse({
status: 200,
description: 'The customer has been successfully updated.',
})
async update(
@Param('id') id: string,
@Body() Customer: CreateCustomerDto,
): Promise<ResponseDTO> {
return await this.customerService.update(id, Customer);
}
@Delete(':id')
@ApiOperation({ summary: 'Delete a customer' })
@ApiResponse({
status: 200,
description: 'The customer has been successfully deleted.',
})
async delete(@Param('id') id: string): Promise<ResponseDTO> {
return await this.customerService.deleteOne({ _id: id });
}
@SkipJwtAuth()
@ApiOperation({
summary: 'Endpoint to submit required KYC information to liquidity partner',
})
@Post(':customerId/kyc')
async submitKyc(
@Body() body: SubmitKycDto,
@Param('customerId') customerId: string,
): Promise<ResponseDTO> {
return await this.customerService.submitKyc(body.kycSubmission, customerId);
}
@SkipJwtAuth()
@ApiOperation({
summary: 'Endpoint to update required KYC information to liquidity partner',
})
@Put(':customerId/kyc')
async updateIndividualCustomer(
@Body() body: UpdateKycDto,
@Param('customerId') customerId: string,
): Promise<ResponseDTO> {
try {
return await this.customerService.updateKyc(
body.kycUpdateSubmission,
customerId,
body.submissionId,
);
} catch (error) {
return error;
}
}
@Put(':id/load-names')
@ApiOperation({ summary: 'Load Names for an individual customer' })
@ApiResponse({
status: 200,
description: 'The names have been successfully loaded.',
})
async updateLoadNames(
@Param('id') id: string,
@Body() loadNamesDTO: LoadNamesDTO,
): Promise<ResponseDTO> {
const data = await this.customerService.updateLoadNames(id, loadNamesDTO);
return { data };
}
}