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.

feat(server): add updateEducation mutation

+100
+55
apps/server/src/modules/education/education.service.ts
··· 117 117 return education ?? notFound("Education", "id", id); 118 118 } 119 119 120 + async update( 121 + id: string, 122 + userId: string, 123 + data: { 124 + institutionId?: string; 125 + degree?: string; 126 + fieldOfStudy?: string | null; 127 + startDate?: Date; 128 + endDate?: Date | null; 129 + description?: string | null; 130 + skillIds?: string[]; 131 + }, 132 + ): Promise<Education> { 133 + const education = await this.findById(id); 134 + if (!education || education.userId !== userId) { 135 + throw new Error("Education not found or does not belong to user"); 136 + } 137 + 138 + const updateData: Prisma.EducationUpdateInput = {}; 139 + 140 + if (data.institutionId !== undefined) { 141 + updateData.institution = { connect: { id: data.institutionId } }; 142 + } 143 + if (data.degree !== undefined) { 144 + updateData.degree = data.degree; 145 + } 146 + if (data.fieldOfStudy !== undefined) { 147 + updateData.fieldOfStudy = data.fieldOfStudy; 148 + } 149 + if (data.startDate !== undefined) { 150 + updateData.startDate = data.startDate; 151 + } 152 + if (data.endDate !== undefined) { 153 + updateData.endDate = data.endDate; 154 + } 155 + if (data.description !== undefined) { 156 + updateData.description = data.description; 157 + } 158 + if (data.skillIds !== undefined) { 159 + updateData.skills = { set: data.skillIds.map((sid) => ({ id: sid })) }; 160 + } 161 + 162 + const updated = await this.prisma.education.update({ 163 + where: { id }, 164 + data: updateData, 165 + include: this.educationInclude, 166 + }); 167 + 168 + const domainEducation = this.educationMapper.toDomain(updated); 169 + if (!domainEducation) { 170 + throw new Error("Failed to update education"); 171 + } 172 + return domainEducation; 173 + } 174 + 120 175 async delete(id: string, userId: string): Promise<void> { 121 176 // Verify the education belongs to the user 122 177 const education = await this.findById(id);
+45
apps/server/src/modules/education/graphql/education.resolver.ts
··· 8 8 import { Args, Mutation, Resolver } from "@nestjs/graphql"; 9 9 import { CurrentUser } from "@/modules/current-user/current-user.decorator"; 10 10 import { InstitutionService } from "@/modules/education/institution.service"; 11 + import { SkillService } from "@/modules/job-experience/skill/skill.service"; 11 12 import { Education as EducationEntity } from "../education.entity"; 12 13 import { EducationService } from "../education.service"; 13 14 import { Education } from "./education.type"; ··· 18 19 constructor( 19 20 private readonly educationService: EducationService, 20 21 private readonly institutionService: InstitutionService, 22 + private readonly skillService: SkillService, 21 23 private readonly authorizationService: AuthorizationService, 22 24 ) {} 23 25 ··· 48 50 description: description ?? null, 49 51 ...(skillIds !== undefined && skillIds.length > 0 ? { skillIds } : {}), 50 52 }); 53 + return Education.fromDomain(education); 54 + } 55 + 56 + @Mutation(() => Education) 57 + async updateEducation( 58 + @CurrentUser() user: DomainUser, 59 + @Args("id") id: string, 60 + @Args("institutionId", { nullable: true }) institutionId?: string, 61 + @Args("degree", { nullable: true }) degree?: string, 62 + @Args("fieldOfStudy", { nullable: true }) fieldOfStudy?: string, 63 + @Args("startDate", { nullable: true }) startDate?: Date, 64 + @Args("endDate", { nullable: true }) endDate?: Date, 65 + @Args("description", { nullable: true }) description?: string, 66 + @Args("skillIds", { type: () => [String], nullable: true }) 67 + skillIds?: string[], 68 + ): Promise<Education> { 69 + const existingEducation = 70 + await this.educationService.findByIdOrFail(id); 71 + await this.authorizationService.canUpdate( 72 + user, 73 + existingEducation, 74 + EducationEntity, 75 + ); 76 + 77 + if (institutionId !== undefined) { 78 + await this.institutionService.findByIdOrFail(institutionId); 79 + } 80 + if (skillIds !== undefined) { 81 + await Promise.all( 82 + skillIds.map((sid) => this.skillService.findByIdOrFail(sid)), 83 + ); 84 + } 85 + 86 + const education = await this.educationService.update(id, user.id, { 87 + institutionId, 88 + degree, 89 + fieldOfStudy, 90 + startDate, 91 + endDate, 92 + description, 93 + skillIds, 94 + }); 95 + 51 96 return Education.fromDomain(education); 52 97 } 53 98