All files / libs/assignments/quotas/state/src/lib/api-client quotas-assignments.api-client.ts

0% Statements 0/53
0% Branches 0/1
0% Functions 0/1
0% Lines 0/53

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54                                                                                                           
import { type Quota } from '@amalia/amalia-lang/tokens/types';
import {
  type DeleteQuotaAssignmentRequest,
  type DeleteQuotaAssignmentsRequest,
  type QuotaPlanAssignments,
  type QuotaTeamAssignments,
  type QuotaUserAssignments,
  type SearchQuotaAssignmentsRequest,
  type UpsertQuotaAssignmentRequest,
  type UpsertQuotasAssignmentsRequest,
} from '@amalia/assignments/quotas/types';
import { http } from '@amalia/core/http/client';

export class QuotasAssignmentsApiClient {
  public static async getQuotaAssignments<
    TQuotaAssignments extends QuotaPlanAssignments | QuotaTeamAssignments | QuotaUserAssignments,
  >(quotaId: Quota['id'], searchQuotaAssignmentsRequest: SearchQuotaAssignmentsRequest) {
    return (
      await http.post<TQuotaAssignments[]>(
        `/quotas/${encodeURIComponent(quotaId)}/assignments/searches`,
        searchQuotaAssignmentsRequest,
      )
    ).data;
  }

  public static async getQuotaPlanAssignments(
    quotaId: Quota['id'],
    { startDate, endDate }: SearchQuotaAssignmentsRequest,
  ) {
    return (
      await http.post<QuotaPlanAssignments[]>(`/quotas/${encodeURIComponent(quotaId)}/assignments/searches`, {
        startDate,
        endDate,
      })
    ).data;
  }

  public static async upsertQuotaAssignment(upsertQuotaAssignmentRequest: UpsertQuotaAssignmentRequest) {
    await http.post('/quotas-assignments', upsertQuotaAssignmentRequest);
  }

  public static async upsertQuotasAssignments(upsertQuotasAssignmentsRequest: UpsertQuotasAssignmentsRequest) {
    await http.post('/quotas-assignments/bulk', upsertQuotasAssignmentsRequest);
  }

  public static async deleteQuotaAssignments(deleteQuotaAssignmentsRequest: DeleteQuotaAssignmentsRequest) {
    await http.delete('/quotas-assignments', { data: deleteQuotaAssignmentsRequest });
  }

  public static async deleteQuotaAssignment({ id }: DeleteQuotaAssignmentRequest) {
    await http.delete(`/quotas-assignments/${encodeURIComponent(id)}`);
  }
}