From 2f3559e70aaf768fa5bf474d4b67c53d1bd359ad Mon Sep 17 00:00:00 2001 From: manelcecs Date: Mon, 30 Oct 2023 12:50:03 +0100 Subject: [PATCH] Add service, resolver and type for Project --- .../projects/graphql/resolver.ts | 17 ++++++ src/domain-services/projects/graphql/types.ts | 54 +++++++++++++++++++ .../projects/project-service.ts | 37 +++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 src/domain-services/projects/graphql/resolver.ts create mode 100644 src/domain-services/projects/graphql/types.ts create mode 100644 src/domain-services/projects/project-service.ts diff --git a/src/domain-services/projects/graphql/resolver.ts b/src/domain-services/projects/graphql/resolver.ts new file mode 100644 index 00000000..837d2bd0 --- /dev/null +++ b/src/domain-services/projects/graphql/resolver.ts @@ -0,0 +1,17 @@ +import SoftwareInfo from './types'; +import { Service } from 'typedi'; +import { Ctx, Query, Resolver } from 'type-graphql'; +import { ProjectService } from '../project-service'; +import Project from './types'; +import Context from '../../Context'; + +@Service() +@Resolver(Project) +export default class ProjectsResolver { + constructor(private projectService: ProjectService) {} + + @Query(() => [Project]) + async softwareInfo(@Ctx() context: Context): Promise { + return await this.projectService.getProjects(context.models); + } +} diff --git a/src/domain-services/projects/graphql/types.ts b/src/domain-services/projects/graphql/types.ts new file mode 100644 index 00000000..91bb19c8 --- /dev/null +++ b/src/domain-services/projects/graphql/types.ts @@ -0,0 +1,54 @@ +import { Field, ObjectType } from 'type-graphql'; + +@ObjectType() +export default class Project { + @Field() + id: number; + + @Field() + createdAt: string; + + @Field() + updatedAt: string; + + @Field() + code: string; + + @Field() + currentPublishedVersionId: number; + + @Field() + creatorParticipantId: number; + + @Field() + latestVersionId: number; + + @Field(() => String) + implementationStatus: ImplementationStatus; + + @Field() + pdf: string; + + @Field() + sourceProjectId: number; + + @Field() + name: string; + + @Field() + version: number; + + @Field() + projectVersionCode: string; + + @Field() + visible: boolean; +} + +export type ImplementationStatus = + | 'Planning' + | 'Implementing' + | 'Ended - Completed' + | 'Ended - Terminated' + | 'Ended - Not started and abandoned' + | null; diff --git a/src/domain-services/projects/project-service.ts b/src/domain-services/projects/project-service.ts new file mode 100644 index 00000000..710ff0cd --- /dev/null +++ b/src/domain-services/projects/project-service.ts @@ -0,0 +1,37 @@ +import { Database } from '@unocha/hpc-api-core/src/db'; +import { Service } from 'typedi'; +import Project from './graphql/types'; + +@Service() +export class ProjectService { + public async getProjects(models: Database): Promise { + const projects = await models.project.find(); + + return projects.map((project) => { + return { + id: project.id.valueOf(), + createdAt: project.createdAt.toString(), + updatedAt: project.updatedAt.toString(), + code: project.code ?? '', + currentPublishedVersionId: project.currentPublishedVersionId + ? project.currentPublishedVersionId.valueOf() + : 0, + creatorParticipantId: project.creatorParticipantId + ? project.creatorParticipantId.valueOf() + : 0, + latestVersionId: project.latestVersionId + ? project.latestVersionId.valueOf() + : 0, + implementationStatus: project.implementationStatus, + pdf: 'null', // TODO: implement + sourceProjectId: project.sourceProjectId + ? project.sourceProjectId.valueOf() + : 0, + name: 'placeholder', + version: 0, + projectVersionCode: 'project version code placeholder', + visible: true, + }; + }); + } +}