All files / libs/payout-calculation/badge-awards/core/src/lib badgeAwards.controller.ts

100% Statements 46/46
50% Branches 3/6
100% Functions 2/2
100% Lines 46/46

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 471x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import { Controller, Get, Inject, Query, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
 
import { Company } from '@amalia/core/models';
import { UuidPipe } from '@amalia/kernel/api';
import {
  AmaliaAuthGuard,
  CheckPolicies,
  CurrentAuthenticatedContext,
  CurrentUserCompany,
  PoliciesGuard,
} from '@amalia/kernel/auth/core';
import { canViewStatements } from '@amalia/kernel/auth/shared';
import { type AuthenticatedContext } from '@amalia/kernel/auth/types';
import { type BadgeAward } from '@amalia/payout-definition/plans/types';
 
import { BadgeAwardsService } from './badgeAwards.service';
 
@UseGuards(AmaliaAuthGuard, PoliciesGuard)
@ApiTags('badges')
@Controller('badges')
@ApiBearerAuth()
export class BadgeAwardsController {
  public constructor(
    @Inject(BadgeAwardsService)
    private readonly badgeAwardService: BadgeAwardsService,
  ) {}
 
  @Get('awards')
  @CheckPolicies((ability) => canViewStatements(ability))
  public async find(
    @CurrentAuthenticatedContext() authenticatedContext: AuthenticatedContext,
    @CurrentUserCompany() company: Company,
    @Query('planIds', new UuidPipe({ multiple: true, optional: true })) planIds?: string[] | null,
    @Query('periodId', new UuidPipe({ optional: true })) periodId?: string,
    @Query('userIds', new UuidPipe({ multiple: true, optional: true })) userIds?: string[] | null,
  ): Promise<BadgeAward[]> {
    return this.badgeAwardService.getForConditions(
      company,
      authenticatedContext,
      planIds ?? null,
      periodId ?? null,
      userIds ?? null,
    );
  }
}