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(server): improve separation of concerns in GraphQL resolvers

- Move organization field resolver from auth module to organization module
- Update AuthModule to remove dependencies on EmploymentModule and OrganizationModule
- Add UserFieldResolver to EmploymentModule for user experience field
- Update seed service to include organization role assignments
- Improve modularity and separation of concerns between modules

+26 -24
+4
apps/server/src/modules/auth/auth.type.ts
··· 13 13 this.access_token = access_token; 14 14 this.user = user; 15 15 } 16 + 17 + static fromDomain(domainAuth: { access_token: string; user: User }): AuthResponse { 18 + return new AuthResponse(domainAuth.access_token, domainAuth.user); 19 + } 16 20 }
+4 -20
apps/server/src/modules/auth/me.resolver.ts
··· 1 1 import { UseGuards } from "@nestjs/common"; 2 - import { Parent, Query, ResolveField, Resolver } from "@nestjs/graphql"; 3 - import type { Organization as PrismaOrganization } from "@prisma/client"; 4 - import { Organization } from "../organization/organization.entity"; 2 + import { Query, Resolver } from "@nestjs/graphql"; 5 3 import { CurrentUser } from "./current-user.decorator"; 6 4 import { JwtAuthGuard } from "./jwt-auth.guard"; 7 5 import { UserService } from "./user.service"; ··· 10 8 @Resolver(() => User) 11 9 @UseGuards(JwtAuthGuard) 12 10 export class MeResolver { 13 - constructor(private readonly userService: UserService) {} 11 + constructor( 12 + private readonly userService: UserService, 13 + ) {} 14 14 15 15 @Query(() => User) 16 16 async me(@CurrentUser() user: User): Promise<User> { 17 17 const domainUser = await this.userService.findByIdOrFail(user.id); 18 18 return User.fromDomain(domainUser); 19 - } 20 - 21 - @ResolveField(() => [Organization]) 22 - async organizations(@Parent() user: User): Promise<Organization[]> { 23 - const userWithOrganizations = await this.userService.findByIdWithOrganizations(user.id); 24 - return ( 25 - userWithOrganizations.organizations?.map((org: PrismaOrganization) => 26 - new Organization({ 27 - id: org.id, 28 - name: org.name, 29 - description: org.description, 30 - createdAt: org.createdAt, 31 - updatedAt: org.updatedAt, 32 - }), 33 - ) || [] 34 - ); 35 19 } 36 20 }
+15 -3
apps/server/src/modules/auth/user.type.ts
··· 1 1 import { Field, ID, ObjectType } from "@nestjs/graphql"; 2 2 import { Organization } from "../organization/organization.entity"; 3 + import { UserJobExperience } from "../job-experience/employment/user-job-experience.type"; 3 4 import type { User as DomainUser } from "./user.entity"; 4 5 5 6 @ObjectType() ··· 19 20 @Field(() => [Organization], { nullable: true }) 20 21 organizations?: Organization[] | undefined; 21 22 22 - constructor(id: string, email: string, name: string, createdAt: Date, organizations?: Organization[] | undefined) { 23 + @Field(() => [UserJobExperience], { nullable: true }) 24 + experience?: UserJobExperience[] | undefined; 25 + 26 + constructor( 27 + id: string, 28 + email: string, 29 + name: string, 30 + createdAt: Date, 31 + organizations?: Organization[] | undefined, 32 + experience?: UserJobExperience[] | undefined 33 + ) { 23 34 this.id = id; 24 35 this.email = email; 25 36 this.name = name; 26 37 this.createdAt = createdAt; 27 38 this.organizations = organizations ?? undefined; 39 + this.experience = experience ?? undefined; 28 40 } 29 41 30 - static fromDomain(domainUser: DomainUser, organizations?: Organization[]): User { 31 - return new User(domainUser.id, domainUser.email, domainUser.name, domainUser.createdAt, organizations); 42 + static fromDomain(domainUser: DomainUser, organizations?: Organization[], experience?: UserJobExperience[]): User { 43 + return new User(domainUser.id, domainUser.email, domainUser.name, domainUser.createdAt, organizations, experience); 32 44 } 33 45 }
+2 -1
apps/server/src/modules/job-experience/employment/employment.module.ts
··· 5 5 import { RoleModule } from "../role/role.module"; 6 6 import { SkillModule } from "../skill/skill.module"; 7 7 import { EmploymentResolver } from "./employment.resolver"; 8 + import { UserFieldResolver } from "./user-field.resolver"; 8 9 import { UserJobExperienceMapper } from "./user-job-experience.mapper"; 9 10 import { UserJobExperienceService } from "./user-job-experience.service"; 10 11 11 12 @Module({ 12 13 imports: [DatabaseModule, CompanyModule, RoleModule, LevelModule, SkillModule], 13 - providers: [UserJobExperienceService, EmploymentResolver, UserJobExperienceMapper], 14 + providers: [UserJobExperienceService, EmploymentResolver, UserFieldResolver, UserJobExperienceMapper], 14 15 exports: [UserJobExperienceService, UserJobExperienceMapper], 15 16 }) 16 17 export class EmploymentModule {}
+1
apps/server/src/modules/seed/seed.service.ts
··· 359 359 data: { 360 360 userId: user.id, 361 361 organizationId: org.id, 362 + organizationRoleId: 'member_role_id', 362 363 }, 363 364 }); 364 365 }