import { Injectable } from '@angular/core' ; import { HttpClient } from '@angular/common/http' ; import { IApprovalPolicy , IApprovalPolicyFindInput , IApprovalPolicyCreateInput , IPagination } from '@gauzy/contracts' ; import { firstValueFrom } from 'rxjs' ; import { API_PREFIX } from '../constants/app.constants' ; @ Injectable ( ) export class ApprovalPolicyService { APPROVAL_POLICY_URL = `${ API_PREFIX }/approval-policy` ; constructor ( private http ) { } getAll ( relations ? , findInput ? ) { const data = JSON . stringify ( { relations , findInput } ) ; return firstValueFrom ( this . http . get < IPagination < IApprovalPolicy > > ( `${ this . APPROVAL_POLICY_URL }` , { params : { data } } ) ) ; } getForRequestApproval ( relations ? , findInput ? ) { const data = JSON . stringify ( { relations , findInput } ) ; return firstValueFrom ( this . http . get < IPagination < IApprovalPolicy > > ( `${ this . APPROVAL_POLICY_URL }/request-approval` , { params : { data } } ) ) ; } delete ( id ) { return firstValueFrom ( this . http . delete ( `${ this . APPROVAL_POLICY_URL }/${ id }` ) ) ; } save ( approvalPolicy ) { if ( ! approvalPolicy . id ) { return firstValueFrom ( this . http . post < IApprovalPolicy > ( this . APPROVAL_POLICY_URL , approvalPolicy ) ) ; } else { return firstValueFrom ( this . http . put < IApprovalPolicy > ( `${ this . APPROVAL_POLICY_URL }/${ approvalPolicy . id }` , approvalPolicy ) ) ; } } }