first commit
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import {
|
||||
CommandResult,
|
||||
CreateProjectInput,
|
||||
MemberInput,
|
||||
Project,
|
||||
ProjectsGateway,
|
||||
ProjectStats,
|
||||
} from '@task-stream/web/tracker/domain';
|
||||
import { map, Observable } from 'rxjs';
|
||||
import {
|
||||
AddProjectMemberDocument,
|
||||
ChangeProjectMemberRoleDocument,
|
||||
CreateProjectDocument,
|
||||
MyProjectsDocument,
|
||||
ProjectDocument,
|
||||
ProjectStatsDocument,
|
||||
RemoveProjectMemberDocument,
|
||||
} from '../graphql/generated';
|
||||
import { GraphqlOperations } from './graphql-operations';
|
||||
import { toCommandResult, toProject, toStats } from './mappers';
|
||||
|
||||
@Injectable()
|
||||
export class GraphqlProjectsGateway extends ProjectsGateway {
|
||||
private readonly gql = inject(GraphqlOperations);
|
||||
|
||||
myProjects(): Observable<Project[]> {
|
||||
return this.gql
|
||||
.query(MyProjectsDocument)
|
||||
.pipe(map((d) => d.myProjects.map(toProject)));
|
||||
}
|
||||
|
||||
project(idOrKey: string): Observable<Project> {
|
||||
return this.gql
|
||||
.query(ProjectDocument, { idOrKey })
|
||||
.pipe(map((d) => toProject(d.project)));
|
||||
}
|
||||
|
||||
stats(projectId: string): Observable<ProjectStats> {
|
||||
return this.gql
|
||||
.query(ProjectStatsDocument, { idOrKey: projectId })
|
||||
.pipe(map((d) => toStats(d.project.stats)));
|
||||
}
|
||||
|
||||
create(input: CreateProjectInput): Observable<CommandResult> {
|
||||
return this.gql
|
||||
.mutate(CreateProjectDocument, { input })
|
||||
.pipe(map((d) => toCommandResult(d.createProject)));
|
||||
}
|
||||
|
||||
addMember(input: MemberInput): Observable<CommandResult> {
|
||||
return this.gql
|
||||
.mutate(AddProjectMemberDocument, { input: input as never })
|
||||
.pipe(map((d) => toCommandResult(d.addProjectMember)));
|
||||
}
|
||||
|
||||
changeMemberRole(input: MemberInput): Observable<CommandResult> {
|
||||
return this.gql
|
||||
.mutate(ChangeProjectMemberRoleDocument, { input: input as never })
|
||||
.pipe(map((d) => toCommandResult(d.changeProjectMemberRole)));
|
||||
}
|
||||
|
||||
removeMember(projectId: string, userId: string): Observable<CommandResult> {
|
||||
return this.gql
|
||||
.mutate(RemoveProjectMemberDocument, { projectId, userId })
|
||||
.pipe(map((d) => toCommandResult(d.removeProjectMember)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user