first commit
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import {
|
||||
Activity,
|
||||
ActivityGateway,
|
||||
CommandResult,
|
||||
Comment,
|
||||
CommentsGateway,
|
||||
CreateReleaseInput,
|
||||
Release,
|
||||
ReleasesGateway,
|
||||
UserDirectoryEntry,
|
||||
UsersGateway,
|
||||
} from '@task-stream/web/tracker/domain';
|
||||
import { map, Observable } from 'rxjs';
|
||||
import {
|
||||
ActivityDocument,
|
||||
AddCommentDocument,
|
||||
ArchiveReleaseDocument,
|
||||
CreateReleaseDocument,
|
||||
DeleteCommentDocument,
|
||||
EditCommentDocument,
|
||||
IssueCommentsDocument,
|
||||
PublishReleaseDocument,
|
||||
ReleasesDocument,
|
||||
SearchUsersDocument,
|
||||
} from '../graphql/generated';
|
||||
import { GraphqlOperations } from './graphql-operations';
|
||||
import { toActivity, toCommandResult, toComment, toRelease } from './mappers';
|
||||
|
||||
@Injectable()
|
||||
export class GraphqlCommentsGateway extends CommentsGateway {
|
||||
private readonly gql = inject(GraphqlOperations);
|
||||
|
||||
list(issueId: string): Observable<Comment[]> {
|
||||
return this.gql
|
||||
.query(IssueCommentsDocument, { idOrKey: issueId })
|
||||
.pipe(map((d) => d.issue.comments.items.map(toComment)));
|
||||
}
|
||||
|
||||
add(issueId: string, body: string): Observable<CommandResult> {
|
||||
return this.gql
|
||||
.mutate(AddCommentDocument, { issueId, body })
|
||||
.pipe(map((d) => toCommandResult(d.addComment)));
|
||||
}
|
||||
|
||||
edit(commentId: string, body: string): Observable<CommandResult> {
|
||||
return this.gql
|
||||
.mutate(EditCommentDocument, { commentId, body })
|
||||
.pipe(map((d) => toCommandResult(d.editComment)));
|
||||
}
|
||||
|
||||
remove(commentId: string): Observable<CommandResult> {
|
||||
return this.gql
|
||||
.mutate(DeleteCommentDocument, { commentId })
|
||||
.pipe(map((d) => toCommandResult(d.deleteComment)));
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class GraphqlReleasesGateway extends ReleasesGateway {
|
||||
private readonly gql = inject(GraphqlOperations);
|
||||
|
||||
list(projectId: string): Observable<Release[]> {
|
||||
return this.gql
|
||||
.query(ReleasesDocument, { idOrKey: projectId })
|
||||
.pipe(map((d) => d.project.releases.map(toRelease)));
|
||||
}
|
||||
|
||||
create(input: CreateReleaseInput): Observable<CommandResult> {
|
||||
return this.gql
|
||||
.mutate(CreateReleaseDocument, { input })
|
||||
.pipe(map((d) => toCommandResult(d.createRelease)));
|
||||
}
|
||||
|
||||
publish(releaseId: string, force: boolean): Observable<CommandResult> {
|
||||
return this.gql
|
||||
.mutate(PublishReleaseDocument, { releaseId, force })
|
||||
.pipe(map((d) => toCommandResult(d.publishRelease)));
|
||||
}
|
||||
|
||||
archive(releaseId: string): Observable<CommandResult> {
|
||||
return this.gql
|
||||
.mutate(ArchiveReleaseDocument, { releaseId })
|
||||
.pipe(map((d) => toCommandResult(d.archiveRelease)));
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class GraphqlActivityGateway extends ActivityGateway {
|
||||
private readonly gql = inject(GraphqlOperations);
|
||||
|
||||
list(projectId: string, issueId?: string): Observable<Activity[]> {
|
||||
return this.gql
|
||||
.query(ActivityDocument, { projectId, issueId: issueId ?? null })
|
||||
.pipe(map((d) => d.activity.map(toActivity)));
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class GraphqlUsersGateway extends UsersGateway {
|
||||
private readonly gql = inject(GraphqlOperations);
|
||||
|
||||
search(term: string): Observable<UserDirectoryEntry[]> {
|
||||
return this.gql
|
||||
.query(SearchUsersDocument, { search: term })
|
||||
.pipe(map((d) => d.users));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user