import { inject, Injectable } from '@angular/core'; import { Automation, AutomationInput, AutomationsGateway, } from '@task-stream/web/tracker/domain'; import { map, Observable } from 'rxjs'; import { AutomationsDocument, CreateAutomationDocument, DeleteAutomationDocument, UpdateAutomationDocument, } from '../graphql/generated'; import { GraphqlOperations } from './graphql-operations'; @Injectable() export class GraphqlAutomationsGateway extends AutomationsGateway { private readonly gql = inject(GraphqlOperations); list(projectId: string): Observable { return this.gql .query(AutomationsDocument, { projectId }) .pipe(map((d) => d.automations as Automation[])); } create(projectId: string, rule: AutomationInput): Observable { return this.gql .mutate(CreateAutomationDocument, { input: { projectId, ...rule } as never, }) .pipe(map((d) => d.createAutomation as Automation)); } update( automationId: string, changes: { name?: string; active?: boolean }, ): Observable { return this.gql .mutate(UpdateAutomationDocument, { automationId, name: changes.name ?? null, active: changes.active ?? null, }) .pipe(map((d) => d.updateAutomation as Automation)); } remove(automationId: string): Observable { return this.gql .mutate(DeleteAutomationDocument, { automationId }) .pipe(map(() => undefined)); } }