Something went wrong. Try again.
because I got bored of customising my CV for every job
Something went wrong. Try again.
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121import { PrismaService } from "@cv/core";import { Injectable } from "@nestjs/common";
/** * Draft entity representation - ID is null if no match found */export interface DraftEntity { id: string | null; name: string;}
/** * Resolved job experience with draft entities */export interface ResolvedJobExperience { company: DraftEntity; role: DraftEntity; level: DraftEntity; skills: DraftEntity[]; startDate: Date; endDate: Date | null; description: string | null;}
/** * Resolved education with draft entities */export interface ResolvedEducation { institution: DraftEntity; degree: string; fieldOfStudy: string | null; skills: DraftEntity[]; startDate: Date; endDate: Date | null; description: string | null;}
/** * Service for resolving entity names to existing database entities * Returns stubs with null IDs for unmatched names */@Injectable()export class EntityResolverService { constructor(private readonly prisma: PrismaService) {}
/** * Resolve a company name to an existing entity */ async resolveCompany(name: string): Promise<DraftEntity> { const match = await this.prisma.company.findFirst({ where: { name: { equals: name, mode: "insensitive" } }, });
return match ? { id: match.id, name: match.name } : { id: null, name }; }
/** * Resolve a role name to an existing entity */ async resolveRole(name: string): Promise<DraftEntity> { const match = await this.prisma.role.findFirst({ where: { name: { equals: name, mode: "insensitive" } }, });
return match ? { id: match.id, name: match.name } : { id: null, name }; }
/** * Resolve a level name to an existing entity * Falls back to "Mid-level" if not provided */ async resolveLevel(name?: string): Promise<DraftEntity> { const searchName = name || "Mid-level"; const match = await this.prisma.level.findFirst({ where: { name: { equals: searchName, mode: "insensitive" } }, });
return match ? { id: match.id, name: match.name } : { id: null, name: searchName }; }
/** * Resolve a skill name to an existing entity */ async resolveSkill(name: string): Promise<DraftEntity> { const trimmed = name.trim(); if (!trimmed) { return { id: null, name: "" }; }
const match = await this.prisma.skill.findFirst({ where: { name: { equals: trimmed, mode: "insensitive" } }, });
return match ? { id: match.id, name: match.name } : { id: null, name: trimmed }; }
/** * Resolve an institution name to an existing entity */ async resolveInstitution(name: string): Promise<DraftEntity> { const match = await this.prisma.institution.findFirst({ where: { name: { equals: name, mode: "insensitive" } }, });
return match ? { id: match.id, name: match.name } : { id: null, name }; }
/** * Resolve multiple skills in parallel */ async resolveSkills(names: string[]): Promise<DraftEntity[]> { const uniqueNames = [...new Set(names.filter((s) => s?.trim()))];
return Promise.all(uniqueNames.map((name) => this.resolveSkill(name))); }}