apps/recallassess/recallassess-api/src/api/admin/participant-group/participant-group.service.ts
ParticipantGroupService
Admin API — Participant Group (Participant Group). Business Logic Service for RecallAssess.
BNestBaseModuleService
Methods |
| Async add | ||||||
add(data: any)
|
||||||
|
Override add method to validate required fields and remove foreign key fields before passing to Prisma Prisma only accepts relation objects (company, createdBy), not raw foreign keys (company_id, participant_id_created_by)
Parameters :
Returns :
Promise<any>
|
| Async save |
save(id: number, data: any)
|
|
Override save method to handle optional foreign key fields for updates Prisma only accepts relation objects (company, createdBy), not raw foreign keys
Returns :
Promise<any>
|
import { BNestBaseModuleService } from "@bish-nest/core/data/module-service/base-module.service";
import { BNestPrismaService } from "@bish-nest/core/services";
import { Injectable, UnprocessableEntityException } from "@nestjs/common";
/**
* ParticipantGroupService
*
* Admin API — Participant Group (Participant Group). Business Logic Service for RecallAssess.
*/
@Injectable()
export class ParticipantGroupService extends BNestBaseModuleService {
/**
* Override add method to validate required fields and remove foreign key fields before passing to Prisma
* Prisma only accepts relation objects (company, createdBy), not raw foreign keys (company_id, participant_id_created_by)
*/
async add(data: any): Promise<any> {
// Validate required fields for creation
if (!data.company_id) {
throw new UnprocessableEntityException({
message: [
{
colName: "company_id",
errorMessage: "Company is required. Please select a company.",
},
],
code: "FORM_VALIDATION_ERROR",
});
}
if (!data.participant_id_created_by) {
throw new UnprocessableEntityException({
message: [
{
colName: "participant_id_created_by",
errorMessage: "Created by participant is required. Please select a participant.",
},
],
code: "FORM_VALIDATION_ERROR",
});
}
// Create a copy of data without the foreign key fields
// The transformed relation fields (company, createdBy) are already present
const { company_id, participant_id_created_by, ...prismaData } = data;
// Call parent add method with cleaned data
return super.add(prismaData);
}
/**
* Override save method to handle optional foreign key fields for updates
* Prisma only accepts relation objects (company, createdBy), not raw foreign keys
*/
async save(id: number, data: any): Promise<any> {
const { company_id, participant_id_created_by, ...prismaData } = data;
return super.save(id, prismaData);
}
}