apps/recallassess/recallassess-api/src/api/client/profile/profile.service.ts
Properties |
|
Methods |
|
constructor(prisma: BNestPrismaService)
|
||||||
|
Parameters :
|
| Async getProfile | ||||||
getProfile(participantId: number)
|
||||||
|
Get current participant profile
Parameters :
Returns :
Promise<ProfileDto>
|
| Async updateProfile | |||||||||
updateProfile(participantId: number, updateDto: UpdateProfileDto)
|
|||||||||
|
Update current participant profile Note: Email cannot be updated through this endpoint for security reasons
Parameters :
Returns :
Promise<ProfileDto>
|
| Private Readonly logger |
Type : unknown
|
Default value : new Logger(CLProfileService.name)
|
import { BNestPrismaService } from "@bish-nest/core/services/database/prisma/prisma.service";
import { Injectable, Logger, NotFoundException } from "@nestjs/common";
import { ProfileDto, UpdateProfileDto } from "./dto";
@Injectable()
export class CLProfileService {
private readonly logger = new Logger(CLProfileService.name);
constructor(private prisma: BNestPrismaService) {}
/**
* Get current participant profile
*/
async getProfile(participantId: number): Promise<ProfileDto> {
const participant = await this.prisma.client.participant.findUnique({
where: {
id: participantId,
},
select: {
id: true,
company_id: true,
first_name: true,
last_name: true,
email: true,
phone: true,
email_verified: true,
role: true,
is_active: true,
is_dev: true,
use_system_timezone: true,
preferred_timezone: true,
created_at: true,
updated_at: true,
company: {
select: { name: true, country: true },
},
},
});
if (!participant) {
throw new NotFoundException("Participant not found");
}
return {
id: participant.id,
company_id: participant.company_id,
company_name: participant.company?.name ?? null,
first_name: participant.first_name,
last_name: participant.last_name,
email: participant.email,
phone: participant.phone,
email_verified: participant.email_verified,
role: participant.role,
is_active: participant.is_active,
is_dev: participant.is_dev,
use_system_timezone: participant.use_system_timezone,
preferred_timezone: participant.preferred_timezone,
company_country: participant.company?.country ?? null,
created_at: participant.created_at,
updated_at: participant.updated_at,
};
}
/**
* Update current participant profile
* Note: Email cannot be updated through this endpoint for security reasons
*/
async updateProfile(participantId: number, updateDto: UpdateProfileDto): Promise<ProfileDto> {
const participant = await this.prisma.client.participant.findUnique({
where: {
id: participantId,
},
});
if (!participant) {
throw new NotFoundException("Participant not found");
}
// Build update data - explicitly exclude email for security
const updateData: {
first_name?: string;
last_name?: string;
phone?: string | null;
use_system_timezone?: boolean;
preferred_timezone?: string | null;
updated_at: Date;
} = {
updated_at: new Date(),
};
// Only include fields that are allowed to be updated
if (updateDto.first_name !== undefined) {
updateData.first_name = updateDto.first_name;
}
if (updateDto.last_name !== undefined) {
updateData.last_name = updateDto.last_name;
}
if (updateDto.phone !== undefined) {
updateData.phone = updateDto.phone;
}
if (updateDto.use_system_timezone !== undefined) {
updateData.use_system_timezone = updateDto.use_system_timezone;
}
if (updateDto.preferred_timezone !== undefined) {
updateData.preferred_timezone = updateDto.preferred_timezone;
}
const updated = await this.prisma.client.participant.update({
where: {
id: participantId,
},
data: updateData,
select: {
id: true,
company_id: true,
first_name: true,
last_name: true,
email: true,
phone: true,
email_verified: true,
role: true,
is_active: true,
is_dev: true,
use_system_timezone: true,
preferred_timezone: true,
created_at: true,
updated_at: true,
company: {
select: { name: true, country: true },
},
},
});
this.logger.log(`Profile updated for participant ${participantId}`);
return {
id: updated.id,
company_id: updated.company_id,
company_name: updated.company?.name ?? null,
first_name: updated.first_name,
last_name: updated.last_name,
email: updated.email,
phone: updated.phone,
email_verified: updated.email_verified,
role: updated.role,
is_active: updated.is_active,
is_dev: updated.is_dev,
use_system_timezone: updated.use_system_timezone,
preferred_timezone: updated.preferred_timezone,
company_country: updated.company?.country ?? null,
created_at: updated.created_at,
updated_at: updated.updated_at,
};
}
}