Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
proofs.service.ts 2.49 KiB
import type {
  EventAnonCredsProofsDeleteByIdInput,
  EventAnonCredsProofsGetAllInput,
  EventAnonCredsProofsGetByIdInput,
  EventDidcommAnonCredsProofsRequestInput,
} from '@ocm/shared';

import { Inject, Injectable } from '@nestjs/common';
import { ClientProxy } from '@nestjs/microservices';
import {
  EventAnonCredsProofsDeleteById,
  EventAnonCredsProofsGetById,
  EventDidcommAnonCredsProofsRequest,
  EventAnonCredsProofsGetAll,
} from '@ocm/shared';
import { map, type Observable } from 'rxjs';

import { NATS_CLIENT } from '../common/constants.js';

@Injectable()
export class ProofsService {
  public constructor(
    @Inject(NATS_CLIENT) private readonly natsClient: ClientProxy,
  ) {}

  public find(
    tenantId: string,
  ): Observable<EventAnonCredsProofsGetAll['data']> {
    return this.natsClient
      .send<
        EventAnonCredsProofsGetAll,
        EventAnonCredsProofsGetAllInput
      >(EventAnonCredsProofsGetAll.token, { tenantId })
      .pipe(map((result) => result.data));
  }

  public getById(
    tenantId: string,
    proofRecordId: string,
  ): Observable<EventAnonCredsProofsGetById['data']> {
    return this.natsClient
      .send<EventAnonCredsProofsGetById, EventAnonCredsProofsGetByIdInput>(
        EventAnonCredsProofsGetById.token,
        {
          tenantId,
          proofRecordId,
        },
      )
      .pipe(map((results) => results.data));
  }

  public request(
    tenantId: string,
    name: EventDidcommAnonCredsProofsRequestInput['name'],
    connectionId: EventDidcommAnonCredsProofsRequestInput['connectionId'],
    requestedAttributes: EventDidcommAnonCredsProofsRequestInput['requestedAttributes'],
    requestedPredicates: EventDidcommAnonCredsProofsRequestInput['requestedPredicates'],
  ): Observable<EventDidcommAnonCredsProofsRequest['data']> {
    return this.natsClient
      .send<
        EventDidcommAnonCredsProofsRequest,
        EventDidcommAnonCredsProofsRequestInput
      >(EventDidcommAnonCredsProofsRequest.token, {
        tenantId,
        name,
        connectionId,
        requestedAttributes,
        requestedPredicates,
      })
      .pipe(map((results) => results.data));
  }

  public delete(
    tenantId: string,
    proofRecordId: string,
  ): Observable<EventAnonCredsProofsDeleteById['data']> {
    return this.natsClient
      .send<
        EventAnonCredsProofsDeleteById,
        EventAnonCredsProofsDeleteByIdInput
      >(EventAnonCredsProofsDeleteById.token, { tenantId, proofRecordId })
      .pipe(map((results) => results.data));
  }
}