Skip to content

Commit 6b8c797

Browse files
#4025 Data Parameterization and Conditional Review Logic
1 parent f8d4de9 commit 6b8c797

File tree

186 files changed

+13606
-3900
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+13606
-3900
lines changed

api-gateway/src/api/service/policy-statistics.ts

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,4 +605,125 @@ export class PolicyStatisticsApi {
605605
await InternalException(error, this.logger);
606606
}
607607
}
608+
609+
/**
610+
* Import statistic definition
611+
*/
612+
@Post('/:policyId/import/file')
613+
@Auth(Permissions.STATISTICS_STATISTIC_CREATE)
614+
@ApiOperation({
615+
summary: 'Imports new statistic definition from a zip file.',
616+
description: 'Imports new statistic definition from the provided zip file into the local DB.',
617+
})
618+
@ApiParam({
619+
name: 'policyId',
620+
type: String,
621+
description: 'Policy Id',
622+
required: true,
623+
example: Examples.DB_ID
624+
})
625+
@ApiBody({
626+
description: 'A zip file containing statistic definition to be imported.',
627+
required: true
628+
})
629+
@ApiOkResponse({
630+
description: 'Successful operation.',
631+
type: StatisticDefinitionDTO
632+
})
633+
@ApiInternalServerErrorResponse({
634+
description: 'Internal server error.',
635+
type: InternalServerErrorDTO
636+
})
637+
@ApiExtraModels(StatisticDefinitionDTO, InternalServerErrorDTO)
638+
@HttpCode(HttpStatus.CREATED)
639+
async importStatisticDefinition(
640+
@AuthUser() user: IAuthUser,
641+
@Param('policyId') policyId: string,
642+
@Body() zip: any
643+
): Promise<StatisticDefinitionDTO> {
644+
const guardian = new Guardians();
645+
try {
646+
const owner = new EntityOwner(user);
647+
return await guardian.importStatisticDefinition(zip, policyId, owner);
648+
} catch (error) {
649+
await InternalException(error, this.logger);
650+
}
651+
}
652+
653+
/**
654+
* Export statistic definition
655+
*/
656+
@Get('/:definitionId/export/file')
657+
@Auth(Permissions.STATISTICS_STATISTIC_READ)
658+
@ApiOperation({
659+
summary: 'Returns a zip file containing statistic definition.',
660+
description: 'Returns a zip file containing statistic definition.',
661+
})
662+
@ApiParam({
663+
name: 'definitionId',
664+
type: String,
665+
description: 'Statistic Definition Identifier',
666+
required: true,
667+
example: Examples.DB_ID
668+
})
669+
@ApiOkResponse({
670+
description: 'Successful operation. Response zip file.'
671+
})
672+
@ApiInternalServerErrorResponse({
673+
description: 'Internal server error.',
674+
type: InternalServerErrorDTO
675+
})
676+
@ApiExtraModels(InternalServerErrorDTO)
677+
@HttpCode(HttpStatus.OK)
678+
async exportStatisticDefinition(
679+
@AuthUser() user: IAuthUser,
680+
@Param('definitionId') definitionId: string,
681+
@Response() res: any
682+
): Promise<any> {
683+
const guardian = new Guardians();
684+
try {
685+
const owner = new EntityOwner(user);
686+
const file: any = await guardian.exportStatisticDefinition(definitionId, owner);
687+
res.header('Content-disposition', `attachment; filename=theme_${Date.now()}`);
688+
res.header('Content-type', 'application/zip');
689+
return res.send(file);
690+
} catch (error) {
691+
await InternalException(error, this.logger);
692+
}
693+
}
694+
695+
/**
696+
* Preview statistic definition
697+
*/
698+
@Post('/import/file/preview')
699+
@Auth(Permissions.STATISTICS_STATISTIC_CREATE)
700+
@ApiOperation({
701+
summary: 'Imports a zip file containing statistic definition.',
702+
description: 'Imports a zip file containing statistic definition.',
703+
})
704+
@ApiBody({
705+
description: 'File.',
706+
})
707+
@ApiOkResponse({
708+
description: 'Statistic definition preview.',
709+
type: StatisticDefinitionDTO
710+
})
711+
@ApiInternalServerErrorResponse({
712+
description: 'Internal server error.',
713+
type: InternalServerErrorDTO,
714+
})
715+
@ApiExtraModels(StatisticDefinitionDTO, InternalServerErrorDTO)
716+
@HttpCode(HttpStatus.OK)
717+
async previewStatisticDefinition(
718+
@AuthUser() user: IAuthUser,
719+
@Body() body: any
720+
): Promise<any> {
721+
try {
722+
const owner = new EntityOwner(user);
723+
const guardian = new Guardians();
724+
return await guardian.previewStatisticDefinition(body, owner);
725+
} catch (error) {
726+
await InternalException(error, this.logger);
727+
}
728+
}
608729
}

0 commit comments

Comments
 (0)