-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add service, resolver and type for Project
- Loading branch information
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<SoftwareInfo[]> { | ||
return await this.projectService.getProjects(context.models); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Project[]> { | ||
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, | ||
}; | ||
}); | ||
} | ||
} |