215 lines
11 KiB
TypeScript
215 lines
11 KiB
TypeScript
import { Body, Controller, Get, Param, Post, Put, Query } from '@nestjs/common';
|
|
import { ApiTags } from '@nestjs/swagger';
|
|
import { RequireRecentAuthentication } from '../auth/require-recent-authentication.decorator';
|
|
import { CurrentSessionUserId } from '../auth/current-session-user.decorator';
|
|
import { ReviewDecisionDto, ReviewGovernanceService } from './review-governance.service';
|
|
import { DeleteTargetDto, DeletionGovernanceService } from '../deletion-governance/deletion-governance.service';
|
|
import { SmsConfigService } from './sms-config.service';
|
|
import { CreateSmsApplicationDto, CreateSmsDrainageInfoDto, CreateSmsSignatureDto, CreateSmsTemplateDto, ReplaceApplicationRouteRulesDto, ReviewDto, StatusChangeDto, UpdateSmsApplicationDto, UpdateSmsDrainageInfoDto, UpdateSmsSignatureDto, UpdateSmsTemplateDto } from './sms-config.contracts';
|
|
|
|
@ApiTags('admin-sms-config')
|
|
@Controller('admin')
|
|
export class AdminSmsConfigController {
|
|
constructor(private readonly smsConfig: SmsConfigService, private readonly reviewGovernance: ReviewGovernanceService, private readonly deletions: DeletionGovernanceService) {}
|
|
|
|
@Get('enterprise-applications')
|
|
listApplications(@Query('tenantId') tenantId?: string, @Query('keyword') keyword?: string, @Query('enterpriseKeyword') enterpriseKeyword?: string, @Query('applicationKeyword') applicationKeyword?: string, @Query('status') status?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string) {
|
|
const query = { tenantId, keyword, enterpriseKeyword, applicationKeyword, status, includeConnections: true, page: Number(page), pageSize: Number(pageSize) };
|
|
return page || pageSize ? this.smsConfig.listApplicationsPage(query) : this.smsConfig.listApplications(query);
|
|
}
|
|
|
|
@Get('enterprise-application-options')
|
|
listApplicationOptions(@Query('tenantId') tenantId?: string) {
|
|
return this.smsConfig.listApplicationOptions(tenantId);
|
|
}
|
|
|
|
@Get('enterprise-applications/:id')
|
|
getApplication(@Param('id') applicationId: string) {
|
|
return this.smsConfig.getApplication(applicationId);
|
|
}
|
|
|
|
@Get('enterprise-applications/:id/report-fields')
|
|
getApplicationReportFields(@Param('id') applicationId: string, @Query('reportType') reportType?: 'signature' | 'drainage') {
|
|
return this.smsConfig.getApplicationReportFields(applicationId, reportType);
|
|
}
|
|
|
|
@Get('report-fields/common')
|
|
getCommonReportFields(@Query('reportType') reportType?: 'signature' | 'drainage') {
|
|
return this.smsConfig.getApplicationReportFields(undefined, reportType);
|
|
}
|
|
|
|
@Post('enterprise-applications')
|
|
@RequireRecentAuthentication()
|
|
createApplication(@Body() body: CreateSmsApplicationDto) {
|
|
return this.smsConfig.createApplication(body);
|
|
}
|
|
|
|
@Put('enterprise-applications/:id')
|
|
@RequireRecentAuthentication()
|
|
updateApplication(@Param('id') applicationId: string, @Body() body: UpdateSmsApplicationDto) {
|
|
return this.smsConfig.updateApplication(applicationId, body);
|
|
}
|
|
|
|
@Put('enterprise-applications/:id/route-rules')
|
|
@RequireRecentAuthentication()
|
|
replaceApplicationRouteRules(@Param('id') applicationId: string, @Body() body: ReplaceApplicationRouteRulesDto) {
|
|
return this.smsConfig.replaceApplicationRouteRules(applicationId, body);
|
|
}
|
|
|
|
@Get('enterprise-applications/:id/connections')
|
|
listApplicationConnections(@Param('id') applicationId: string) {
|
|
return this.smsConfig.listApplicationConnections(applicationId);
|
|
}
|
|
|
|
@Get('enterprise-applications/:id/deactivation-preview')
|
|
getApplicationDeactivationPreview(@Param('id') applicationId: string) {
|
|
return this.smsConfig.getApplicationDeactivationPreview(applicationId);
|
|
}
|
|
|
|
@Get('enterprise-applications/:id/cmpp-params')
|
|
getApplicationCmppParams(@Param('id') applicationId: string) {
|
|
return this.smsConfig.getApplicationCmppParams(applicationId);
|
|
}
|
|
|
|
@Get('enterprise-signatures')
|
|
listSignatures(@Query('tenantId') tenantId?: string, @Query('keyword') keyword?: string, @Query('status') status?: string, @Query('enterpriseKeyword') enterpriseKeyword?: string, @Query('applicationKeyword') applicationKeyword?: string, @Query('signatureKeyword') signatureKeyword?: string, @Query('drainageKeyword') drainageKeyword?: string, @Query('submittedAtFrom') submittedAtFrom?: string, @Query('submittedAtTo') submittedAtTo?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string) {
|
|
const query = { tenantId, keyword, status, enterpriseKeyword, applicationKeyword, signatureKeyword, drainageKeyword, submittedAtFrom, submittedAtTo, page: Number(page), pageSize: Number(pageSize) };
|
|
return page || pageSize ? this.smsConfig.listSignaturesPage(query) : this.smsConfig.listSignatures(query);
|
|
}
|
|
|
|
@Get('enterprise-signature-options')
|
|
listSignatureOptions(@Query('tenantId') tenantId?: string) {
|
|
return this.smsConfig.listSignatureOptions(tenantId);
|
|
}
|
|
|
|
@Get('enterprise-signatures/:id')
|
|
getSignature(@Param('id') id: string) {
|
|
return this.smsConfig.getSignature(id);
|
|
}
|
|
|
|
@Get('enterprise-signatures/:id/report-targets')
|
|
getSignatureReportTargets(@Param('id') id: string) {
|
|
return this.smsConfig.getSignatureReportTargets(id);
|
|
}
|
|
|
|
@Get('drainage-infos/:id/report-targets')
|
|
getDrainageReportTargets(@Param('id') id: string) {
|
|
return this.smsConfig.getDrainageReportTargets(id);
|
|
}
|
|
|
|
@Post('enterprise-signatures')
|
|
createSignature(@Body() body: CreateSmsSignatureDto) {
|
|
return this.smsConfig.createSignature(body, { initialAuditStatus: 'approved' });
|
|
}
|
|
|
|
@Put('enterprise-signatures/:id')
|
|
updateSignature(
|
|
@Param('id') signatureId: string,
|
|
@Body() body: UpdateSmsSignatureDto,
|
|
@CurrentSessionUserId() reviewerId?: string,
|
|
) {
|
|
return this.smsConfig.updateSignature(signatureId, body, undefined, {
|
|
initialAuditStatus: 'approved',
|
|
reviewerId,
|
|
});
|
|
}
|
|
|
|
@Get('drainage-infos')
|
|
listDrainageInfos(@Query('tenantId') tenantId?: string, @Query('signatureId') signatureId?: string, @Query('status') status?: string, @Query('keyword') keyword?: string, @Query('submittedAtFrom') submittedAtFrom?: string, @Query('submittedAtTo') submittedAtTo?: string) {
|
|
return this.smsConfig.listDrainageInfos({ tenantId, signatureId, status, keyword, submittedAtFrom, submittedAtTo });
|
|
}
|
|
|
|
@Post('enterprise-signatures/:id/drainage-infos')
|
|
createDrainageInfo(@Param('id') signatureId: string, @Body() body: CreateSmsDrainageInfoDto) {
|
|
return this.smsConfig.createDrainageInfo(signatureId, body, { initialAuditStatus: 'approved' });
|
|
}
|
|
|
|
@Put('drainage-infos/:id')
|
|
updateDrainageInfo(@Param('id') itemId: string, @Body() body: UpdateSmsDrainageInfoDto) {
|
|
return this.smsConfig.updateDrainageInfo(itemId, body, { initialAuditStatus: 'approved' });
|
|
}
|
|
|
|
@Post('drainage-infos/:id/approve')
|
|
@RequireRecentAuthentication()
|
|
approveDrainageInfo(@Param('id') itemId: string, @Body() body: ReviewDto, @CurrentSessionUserId() reviewerId?: string) {
|
|
return this.smsConfig.approveDrainageInfo(itemId, { ...body, reviewerId });
|
|
}
|
|
|
|
@Post('drainage-infos/:id/reject')
|
|
@RequireRecentAuthentication()
|
|
rejectDrainageInfo(@Param('id') itemId: string, @Body() body: ReviewDto, @CurrentSessionUserId() reviewerId?: string) {
|
|
return this.smsConfig.rejectDrainageInfo(itemId, { ...body, reviewerId });
|
|
}
|
|
|
|
@Post('drainage-infos/:id/status')
|
|
@RequireRecentAuthentication()
|
|
changeDrainageInfoStatus(@Param('id') itemId: string, @Body() body: StatusChangeDto) {
|
|
return this.smsConfig.changeDrainageInfoStatus(itemId, body);
|
|
}
|
|
|
|
@Get('enterprise-templates')
|
|
listTemplates(@Query('tenantId') tenantId?: string, @Query('status') status?: string, @Query('keyword') keyword?: string, @Query('enterpriseKeyword') enterpriseKeyword?: string, @Query('applicationKeyword') applicationKeyword?: string, @Query('nameKeyword') nameKeyword?: string, @Query('contentKeyword') contentKeyword?: string, @Query('submittedAtFrom') submittedAtFrom?: string, @Query('submittedAtTo') submittedAtTo?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string) {
|
|
const query = { tenantId, status, keyword, enterpriseKeyword, applicationKeyword, nameKeyword, contentKeyword, submittedAtFrom, submittedAtTo, page: Number(page), pageSize: Number(pageSize) };
|
|
return page || pageSize ? this.smsConfig.listTemplatesPage(query) : this.smsConfig.listTemplates(query);
|
|
}
|
|
|
|
@Post('enterprise-templates')
|
|
createTemplate(@Body() body: CreateSmsTemplateDto) {
|
|
return this.smsConfig.createTemplate(body, { initialAuditStatus: 'approved' });
|
|
}
|
|
|
|
@Put('enterprise-templates/:id')
|
|
updateTemplate(@Param('id') templateId: string, @Body() body: UpdateSmsTemplateDto) {
|
|
return this.smsConfig.updateTemplate(templateId, body);
|
|
}
|
|
|
|
@Get('audit-records')
|
|
listAuditRecords(@Query('targetType') targetType?: string, @Query('targetId') targetId?: string) {
|
|
return this.smsConfig.listAuditRecords(targetType, targetId);
|
|
}
|
|
|
|
@Post('signatures/:id/approve')
|
|
@RequireRecentAuthentication()
|
|
approveSignature(@Param('id') signatureId: string, @Body() body: ReviewDecisionDto, @CurrentSessionUserId() reviewerId?: string) {
|
|
return this.reviewGovernance.decide('signature', signatureId, { ...body, decision: 'approve', reviewerId });
|
|
}
|
|
|
|
@Post('signatures/:id/reject')
|
|
@RequireRecentAuthentication()
|
|
rejectSignature(@Param('id') signatureId: string, @Body() body: ReviewDto, @CurrentSessionUserId() reviewerId?: string) {
|
|
return this.smsConfig.rejectSignature(signatureId, { ...body, reviewerId });
|
|
}
|
|
|
|
@Post('templates/:id/approve')
|
|
@RequireRecentAuthentication()
|
|
approveTemplate(@Param('id') templateId: string, @Body() body: ReviewDecisionDto, @CurrentSessionUserId() reviewerId?: string) {
|
|
return this.reviewGovernance.decide('template', templateId, { ...body, decision: 'approve', reviewerId });
|
|
}
|
|
|
|
@Post('templates/:id/reject')
|
|
@RequireRecentAuthentication()
|
|
rejectTemplate(@Param('id') templateId: string, @Body() body: ReviewDto, @CurrentSessionUserId() reviewerId?: string) {
|
|
return this.smsConfig.rejectTemplate(templateId, { ...body, reviewerId });
|
|
}
|
|
|
|
@Post('enterprise-applications/:id/status')
|
|
@RequireRecentAuthentication()
|
|
changeApplicationStatus(@Param('id') applicationId: string, @Body() body: StatusChangeDto) {
|
|
return this.smsConfig.changeApplicationStatus(applicationId, body);
|
|
}
|
|
|
|
@Post('enterprise-signatures/:id/status')
|
|
@RequireRecentAuthentication()
|
|
changeSignatureStatus(@Param('id') signatureId: string, @Body() body: StatusChangeDto & DeleteTargetDto, @CurrentSessionUserId() operatorId?: string) {
|
|
if (body.status === 'deleted') return this.deletions.delete('signature', signatureId, { ...body, operatorId });
|
|
return this.smsConfig.changeSignatureStatus(signatureId, body);
|
|
}
|
|
|
|
@Post('enterprise-templates/:id/status')
|
|
@RequireRecentAuthentication()
|
|
changeTemplateStatus(@Param('id') templateId: string, @Body() body: StatusChangeDto & DeleteTargetDto, @CurrentSessionUserId() operatorId?: string) {
|
|
if (body.status === 'deleted') return this.deletions.delete('template', templateId, { ...body, operatorId });
|
|
return this.smsConfig.changeTemplateStatus(templateId, body);
|
|
}
|
|
}
|