apps/recallassess/recallassess-api/src/api/client/reports/participant-reports.controller.ts
api/client/reports/participant
Methods |
| Async addParticipantForReports | |||||||||
addParticipantForReports(data: AddParticipantDto, auth: CLAuthData)
|
|||||||||
Decorators :
@HttpCode(HttpStatus.CREATED)
|
|||||||||
|
Add a new participant via reports alias POST /api/reports/client/participant
Parameters :
Returns :
Promise<CLParticipantDto>
|
| Async checkParticipantActiveWorkForReports | |||||||||
checkParticipantActiveWorkForReports(id: number, auth: CLAuthData)
|
|||||||||
Decorators :
@HttpCode(HttpStatus.OK)
|
|||||||||
|
Check participant active work before deactivation (reports alias) GET /api/client/reports/participant/:id/active-work
Parameters :
Returns :
Promise<ParticipantActiveWorkDto>
|
| Async deleteParticipantForReports | |||||||||
deleteParticipantForReports(id: number, auth: CLAuthData)
|
|||||||||
Decorators :
@HttpCode(HttpStatus.NO_CONTENT)
|
|||||||||
|
Delete a company contact (reports alias). Participant administrator only; blocked when an active course allocation exists. DELETE /api/client/reports/participant/:id
Parameters :
Returns :
Promise<void>
|
| Async getAllParticipantsForReports | |||||||||
getAllParticipantsForReports(query: ParticipantQueryDto, auth: CLAuthData)
|
|||||||||
Decorators :
@HttpCode(HttpStatus.OK)
|
|||||||||
|
Get all participants for client reports with optional filtering and pagination GET /api/reports/client/participant?page=1&limit=20&sq=john&status=active&participantGroup=Sales
Parameters :
Returns :
Promise<CLParticipantListResponse>
|
| Async getLicenseAvailabilityForReports | ||||||
getLicenseAvailabilityForReports(auth: CLAuthData)
|
||||||
Decorators :
@HttpCode(HttpStatus.OK)
|
||||||
|
Get license availability for adding participants (reports alias) GET /api/reports/client/participant/license-availability
Parameters :
Returns :
Promise<literal type>
|
| Async getParticipantByIdForReports | |||||||||
getParticipantByIdForReports(id: number, auth: CLAuthData)
|
|||||||||
Decorators :
@HttpCode(HttpStatus.OK)
|
|||||||||
|
Get a single participant by ID (reports alias) GET /api/reports/client/participant/:id
Parameters :
Returns :
Promise<CLParticipantDto>
|
| Async saveParticipantForReports | ||||||||||||
saveParticipantForReports(id: number, data: SaveParticipantDto, auth: CLAuthData)
|
||||||||||||
Decorators :
@HttpCode(HttpStatus.OK)
|
||||||||||||
|
Save (update) a participant (reports alias) PUT /api/reports/client/participant/:id
Parameters :
Returns :
Promise<CLParticipantDto>
|
import { CLAuthData, ClientAuth } from "@api/shared/decorators";
import {
Body,
Controller,
Delete,
Get,
HttpCode,
HttpStatus,
NotFoundException,
Param,
ParseIntPipe,
Post,
Put,
Query,
} from "@nestjs/common";
import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
import {
AddParticipantDto,
CLParticipantDto,
CLParticipantListResponse,
ParticipantActiveWorkDto,
ParticipantQueryDto,
SaveParticipantDto,
} from "../participant/dto";
import { CLParticipantService } from "../participant/participant.service";
@ApiTags("Client - Reports - Participants")
@Controller("api/client/reports/participant")
export class CLParticipantReportsController {
constructor(private participantService: CLParticipantService) {}
/**
* Get all participants for client reports with optional filtering and pagination
* GET /api/reports/client/participant?page=1&limit=20&sq=john&status=active&participantGroup=Sales
*/
@HttpCode(HttpStatus.OK)
@Get()
@ApiOperation({
summary: "Get all participants with pagination, search and filters (reports)",
description:
"Returns paginated participants filtered by search query, status, and participant group with metadata under the reports namespace",
})
@ApiResponse({
status: 200,
description:
"Returns paginated list of participants with metadata (page, limit, totalCount, totalPages, etc.)",
})
async getAllParticipantsForReports(
@Query() query: ParticipantQueryDto,
@ClientAuth() auth: CLAuthData,
): Promise<CLParticipantListResponse> {
return this.participantService.getFilteredParticipants(
auth.companyId,
query.page || 1,
query.limit || 20,
query.sq,
query.status,
query.participantGroup,
auth.participantId,
auth.role,
);
}
/**
* Add a new participant via reports alias
* POST /api/reports/client/participant
*/
@HttpCode(HttpStatus.CREATED)
@Post()
@ApiOperation({ summary: "Add a new participant (reports alias)" })
@ApiResponse({
status: 201,
description: "Participant added successfully",
type: CLParticipantDto,
})
@ApiResponse({
status: 409,
description: "A contact with this email already exists",
})
async addParticipantForReports(
@Body() data: AddParticipantDto,
@ClientAuth() auth: CLAuthData,
): Promise<CLParticipantDto> {
return this.participantService.addParticipant(data, auth.companyId, auth.participantId);
}
/**
* Get license availability for adding participants (reports alias)
* GET /api/reports/client/participant/license-availability
*/
@HttpCode(HttpStatus.OK)
@Get("license-availability")
@ApiOperation({ summary: "Get license availability information (reports)" })
@ApiResponse({
status: 200,
description: "Returns license availability information",
})
async getLicenseAvailabilityForReports(@ClientAuth() auth: CLAuthData): Promise<{
totalLicenses: number;
currentActiveParticipants: number;
availableSlots: number;
canAddMore: boolean;
}> {
return this.participantService.getParticipantLicenseAvailability(auth.companyId);
}
/**
* Check participant active work before deactivation (reports alias)
* GET /api/client/reports/participant/:id/active-work
*/
@HttpCode(HttpStatus.OK)
@Get(":id/active-work")
@ApiOperation({
summary: "Check if participant has active work (reports)",
description: "Returns information about incomplete courses and pending assessments",
})
@ApiResponse({
status: 200,
description: "Returns active work information",
type: ParticipantActiveWorkDto,
})
@ApiResponse({
status: 400,
description: "Participant not found",
})
async checkParticipantActiveWorkForReports(
@Param("id", ParseIntPipe) id: number,
@ClientAuth() auth: CLAuthData,
): Promise<ParticipantActiveWorkDto> {
return this.participantService.checkParticipantActiveWork(id, auth.companyId);
}
/**
* Get a single participant by ID (reports alias)
* GET /api/reports/client/participant/:id
*/
@HttpCode(HttpStatus.OK)
@Get(":id")
@ApiOperation({ summary: "Get a participant by ID (reports)" })
@ApiResponse({
status: 200,
description: "Returns a single participant with enriched data",
type: CLParticipantDto,
})
@ApiResponse({
status: 404,
description: "Participant not found",
})
async getParticipantByIdForReports(
@Param("id", ParseIntPipe) id: number,
@ClientAuth() auth: CLAuthData,
): Promise<CLParticipantDto> {
const participant = await this.participantService.getParticipantById(id, auth.companyId);
if (!participant) {
throw new NotFoundException(`Participant with ID ${id} not found`);
}
return participant;
}
/**
* Save (update) a participant (reports alias)
* PUT /api/reports/client/participant/:id
*/
@HttpCode(HttpStatus.OK)
@Put(":id")
@ApiOperation({ summary: "Save a participant (reports)" })
@ApiResponse({
status: 200,
description: "Participant saved successfully",
type: CLParticipantDto,
})
@ApiResponse({
status: 404,
description: "Participant not found",
})
async saveParticipantForReports(
@Param("id", ParseIntPipe) id: number,
@Body() data: SaveParticipantDto,
@ClientAuth() auth: CLAuthData,
): Promise<CLParticipantDto> {
const participant = await this.participantService.saveParticipant(
id,
auth.companyId,
data,
auth.participantId,
);
if (!participant) {
throw new NotFoundException(`Participant with ID ${id} not found`);
}
return participant;
}
/**
* Delete a company contact (reports alias). Participant administrator only; blocked when an active
* course allocation exists.
* DELETE /api/client/reports/participant/:id
*/
@HttpCode(HttpStatus.NO_CONTENT)
@Delete(":id")
@ApiOperation({ summary: "Delete a participant contact (reports)" })
@ApiResponse({ status: 204, description: "Participant deleted successfully" })
@ApiResponse({ status: 403, description: "Forbidden — not a participant administrator" })
@ApiResponse({
status: 422,
description: "Contact has an active course allocation and cannot be deleted",
})
async deleteParticipantForReports(
@Param("id", ParseIntPipe) id: number,
@ClientAuth() auth: CLAuthData,
): Promise<void> {
await this.participantService.deleteParticipantForParticipantAdmin(
id,
auth.companyId,
auth.participantId,
auth.role,
);
}
}