Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 10x 10x 10x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { Body, Controller, Param, Post, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { Plan, Rule } from '@amalia/core/models';
import { UuidPipe } from '@amalia/kernel/api';
import { AmaliaAuthGuard, CheckPolicies, CurrentAuthenticatedContext, PoliciesGuard } from '@amalia/kernel/auth/core';
import { canModifyPlans } from '@amalia/kernel/auth/shared';
import { type AuthenticatedContext } from '@amalia/kernel/auth/types';
import {
type RuleTemplatePerformanceSharePlanResponse,
type RuleTemplateSingleRateCommissionResponse,
} from '@amalia/payout-definition/plans/types';
import { RuleTemplatePerformanceSharePlanDTO } from './dto/templates/performance-share-plan.dto';
import { RuleTemplateSingleRateCommissionDTO } from './dto/templates/single-rate-commission.dto';
import { ApplyPerformanceSharePlanTemplateUseCase } from './use-cases/templates/performance-share-plan/apply-performance-share-plan-template.use-case';
import { ApplySingleRateCommissionTemplateUseCase } from './use-cases/templates/single-rate-commission/apply-single-rate-commission-template.use-case';
@UseGuards(AmaliaAuthGuard, PoliciesGuard)
@ApiBearerAuth()
@ApiTags('rules')
@Controller('plans/:planId/rules/:ruleId/templates')
export class RuleTemplatesController {
public constructor(
private readonly applySingleRateCommissionTemplateUseCase: ApplySingleRateCommissionTemplateUseCase,
private readonly applyPerformanceSharePlanTemplateUseCase: ApplyPerformanceSharePlanTemplateUseCase,
) {}
@Post('/single-rate-commission')
@CheckPolicies((ability) => canModifyPlans(ability))
public async applySingleRateCommissionTemplateToRule(
@CurrentAuthenticatedContext() authenticatedContext: AuthenticatedContext,
@Param('planId', new UuidPipe()) planId: Plan['id'],
@Param('ruleId', new UuidPipe()) ruleId: Rule['id'],
@Body() singleRateCommissionTemplate: RuleTemplateSingleRateCommissionDTO,
): Promise<RuleTemplateSingleRateCommissionResponse> {
return this.applySingleRateCommissionTemplateUseCase.execute({
authenticatedContext,
planId,
ruleId,
singleRateCommissionTemplate,
});
}
@Post('/performance-share-plan')
@CheckPolicies((ability) => canModifyPlans(ability))
public async applyPerformanceSharePlanTemplateToRule(
@CurrentAuthenticatedContext() authenticatedContext: AuthenticatedContext,
@Param('planId', new UuidPipe()) planId: Plan['id'],
@Param('ruleId', new UuidPipe()) ruleId: Rule['id'],
@Body() performanceSharePlanTemplate: RuleTemplatePerformanceSharePlanDTO,
): Promise<RuleTemplatePerformanceSharePlanResponse> {
return this.applyPerformanceSharePlanTemplateUseCase.execute({
authenticatedContext,
planId,
ruleId,
performanceSharePlanTemplate,
});
}
}
|