apps/recallassess/recallassess-api/src/api/client/company-profile/company-profile.service.ts
Methods |
|
constructor(prisma: BNestPrismaService, companyTimezoneService: CompanyTimezoneService)
|
|||||||||
|
Parameters :
|
| Async getCompanyProfile | ||||||
getCompanyProfile(companyId: number)
|
||||||
|
Get company profile for the authenticated participant's company
Parameters :
Returns :
Promise<CompanyProfileDto>
|
| Async updateCompanyProfile | |||||||||
updateCompanyProfile(companyId: number, updateDto: UpdateCompanyProfileDto)
|
|||||||||
|
Update company profile
Parameters :
Returns :
Promise<CompanyProfileDto>
|
import { CompanyTimezoneService } from "@api/shared/timezone/company-timezone.service";
import { bnestPlainToDto } from "@bish-nest/core";
import { BNestPrismaService } from "@bish-nest/core/services";
import { Injectable } from "@nestjs/common";
import { CompanyProfileDto, UpdateCompanyProfileDto } from "./dto";
@Injectable()
export class CLCompanyProfileService {
constructor(
private prisma: BNestPrismaService,
private companyTimezoneService: CompanyTimezoneService,
) {}
/**
* Get company profile for the authenticated participant's company
*/
async getCompanyProfile(companyId: number): Promise<CompanyProfileDto> {
const company = await this.prisma.client.company.findUnique({
where: { id: companyId },
select: {
id: true,
name: true,
email: true,
phone: true,
industry: true,
address: true,
city: true,
country: true,
preferred_timezone: true,
website: true,
},
});
if (!company) {
throw new Error("Company not found");
}
const timezone = this.companyTimezoneService.resolve({
country: company.country,
preferred_timezone: company.preferred_timezone,
});
return bnestPlainToDto(
{
id: company.id,
companyName: company.name,
industry: company.industry,
address: company.address || "",
city: company.city || "",
country: company.country || "",
phone: company.phone || "",
website: company.website || "",
timezone,
},
CompanyProfileDto,
);
}
/**
* Update company profile
*/
async updateCompanyProfile(companyId: number, updateDto: UpdateCompanyProfileDto): Promise<CompanyProfileDto> {
const updatedCompany = await this.prisma.client.company.update({
where: { id: companyId },
data: {
name: updateDto.companyName,
industry: updateDto.industry,
address: updateDto.address,
city: updateDto.city,
country: updateDto.country,
phone: updateDto.phone,
website: updateDto.website,
},
select: {
id: true,
name: true,
email: true,
phone: true,
industry: true,
address: true,
city: true,
country: true,
preferred_timezone: true,
website: true,
},
});
const timezone = this.companyTimezoneService.resolve({
country: updatedCompany.country,
preferred_timezone: updatedCompany.preferred_timezone,
});
return bnestPlainToDto(
{
id: updatedCompany.id,
companyName: updatedCompany.name,
industry: updatedCompany.industry,
address: updatedCompany.address || "",
city: updatedCompany.city || "",
country: updatedCompany.country || "",
phone: updatedCompany.phone || "",
website: updatedCompany.website || "",
timezone,
},
CompanyProfileDto,
);
}
}