because I got bored of customising my CV for every job
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(resolvers): update resolvers to use full entities

- Update EmploymentResolver to fetch full entities before creating/updating
- Inject CompanyService, RoleService, LevelService, SkillService for entity fetching
- Update UserFieldResolver to use findForUser method
- Remove user field from UserJobExperience GraphQL type
- Update fromDomain static method to handle new entity structure
- Implement proper domain-driven design in GraphQL layer

+32 -21
+30 -12
apps/server/src/modules/job-experience/employment/employment.resolver.ts
··· 3 3 import { CurrentUser } from "../../auth/current-user.decorator"; 4 4 import { JwtAuthGuard } from "../../auth/jwt-auth.guard"; 5 5 import type { User } from "../../auth/user.type"; 6 + import { CompanyService } from "../company/company.service"; 7 + import { LevelService } from "../level/level.service"; 8 + import { RoleService } from "../role/role.service"; 9 + import { SkillService } from "../skill/skill.service"; 6 10 import type { 7 11 CreateUserJobExperienceDto, 8 12 UpdateUserJobExperienceDto, ··· 15 19 export class EmploymentResolver { 16 20 constructor( 17 21 private readonly userJobExperienceService: UserJobExperienceService, 22 + private readonly companyService: CompanyService, 23 + private readonly roleService: RoleService, 24 + private readonly levelService: LevelService, 25 + private readonly skillService: SkillService, 18 26 ) {} 19 27 20 28 @Query(() => [UserJobExperience]) 21 29 async myEmploymentHistory( 22 - @CurrentUser() { id }: User, 30 + @CurrentUser() user: User, 23 31 ): Promise<UserJobExperience[]> { 24 32 const domainExperiences = 25 - await this.userJobExperienceService.findByUserId(id); 33 + await this.userJobExperienceService.findForUser(user); 26 34 return domainExperiences.map((exp) => UserJobExperience.fromDomain(exp)); 27 35 } 28 36 ··· 38 46 @Args("skillIds", { type: () => [String], nullable: true }) 39 47 skillIds?: string[], 40 48 ): Promise<UserJobExperience> { 49 + // Fetch full entities 50 + const company = await this.companyService.findByIdOrFail(companyId); 51 + const role = await this.roleService.findByIdOrFail(roleId); 52 + const level = await this.levelService.findByIdOrFail(levelId); 53 + const skills = skillIds ? await Promise.all( 54 + skillIds.map(id => this.skillService.findByIdOrFail(id)) 55 + ) : undefined; 56 + 41 57 const createData: CreateUserJobExperienceDto = { 42 - userId: user.id, 43 - companyId, 44 - roleId, 45 - levelId, 58 + user, 59 + company, 60 + role, 61 + level, 46 62 startDate, 47 63 }; 48 64 ··· 52 68 if (description !== undefined) { 53 69 createData.description = description; 54 70 } 55 - if (skillIds !== undefined) { 56 - createData.skillIds = skillIds; 71 + if (skills !== undefined) { 72 + createData.skills = skills; 57 73 } 58 74 59 75 const domainExperience = ··· 77 93 const updateData: UpdateUserJobExperienceDto = {}; 78 94 79 95 if (companyId !== undefined) { 80 - updateData.companyId = companyId; 96 + updateData.company = await this.companyService.findByIdOrFail(companyId); 81 97 } 82 98 if (roleId !== undefined) { 83 - updateData.roleId = roleId; 99 + updateData.role = await this.roleService.findByIdOrFail(roleId); 84 100 } 85 101 if (levelId !== undefined) { 86 - updateData.levelId = levelId; 102 + updateData.level = await this.levelService.findByIdOrFail(levelId); 87 103 } 88 104 if (startDate !== undefined) { 89 105 updateData.startDate = startDate; ··· 95 111 updateData.description = description; 96 112 } 97 113 if (skillIds !== undefined) { 98 - updateData.skillIds = skillIds; 114 + updateData.skills = await Promise.all( 115 + skillIds.map(id => this.skillService.findByIdOrFail(id)) 116 + ); 99 117 } 100 118 101 119 const domainExperience = await this.userJobExperienceService.update(
+2 -2
apps/server/src/modules/job-experience/employment/user-field.resolver.ts
··· 8 8 constructor(private readonly userJobExperienceService: UserJobExperienceService) {} 9 9 10 10 @ResolveField(() => [UserJobExperience], { nullable: true }) 11 - async experience(@Parent() user: { id: string }): Promise<UserJobExperience[]> { 12 - const domainExperiences = await this.userJobExperienceService.findByUserId(user.id); 11 + async experience(@Parent() user: User): Promise<UserJobExperience[]> { 12 + const domainExperiences = await this.userJobExperienceService.findForUser(user); 13 13 return domainExperiences.map((exp) => UserJobExperience.fromDomain(exp)); 14 14 } 15 15 }
-7
apps/server/src/modules/job-experience/employment/user-job-experience.type.ts
··· 1 1 import { Field, ID, ObjectType } from "@nestjs/graphql"; 2 - import { User } from "../../auth/user.type"; 3 2 import { Company } from "../company/company.type"; 4 3 import { Level } from "../level/level.type"; 5 4 import { Role } from "../role/role.type"; ··· 10 9 export class UserJobExperience { 11 10 @Field(() => ID) 12 11 id: string; 13 - 14 - @Field(() => User) 15 - user: User; 16 12 17 13 @Field(() => Company) 18 14 company: Company; ··· 43 39 44 40 constructor( 45 41 id: string, 46 - user: User, 47 42 company: Company, 48 43 role: Role, 49 44 level: Level, ··· 55 50 description?: string, 56 51 ) { 57 52 this.id = id; 58 - this.user = user; 59 53 this.company = company; 60 54 this.role = role; 61 55 this.level = level; ··· 74 68 static fromDomain(domainExperience: DomainUserJobExperience): UserJobExperience { 75 69 return new UserJobExperience( 76 70 domainExperience.id, 77 - new User(domainExperience.user.id, domainExperience.user.email, domainExperience.user.name, domainExperience.user.createdAt), 78 71 Company.fromDomain(domainExperience.company), 79 72 Role.fromDomain(domainExperience.role), 80 73 Level.fromDomain(domainExperience.level),