src/services/AgreementService.js
import Client from '../Client';
import Agreement from '../helpers/agreement/Agreement';
// import { validate, hasToken, isRequired, hasAttribute } from '../utilities/ValidationUtility';
import {
hasToken,
isRequired,
validate,
} from '../utilities/ValidationUtility';
import JsonApiService from './JsonApiService';
/**
* Service handling System Utility calls.
*
*/
// class AgreementService {
class AgreementService extends JsonApiService {
/**
* Sends a request to create an Adobe Sign document, if a document
* exists for the given recipients, that same document its returned.
*
* @param {Number} id - The id of the document to be signed
* @param {String[]} recipients - The list of users that will sign the document with
* the given email and user role.
* @param {Object} options - A hash of key values, to indicate custom attribues for the
* pdf values.
* @return {Promise<Agreement>} - Returns the agreement in a promise
*/
get(id, recipients, options) {
validate('AgreementService.get',
hasToken(),
isRequired({ id, recipients }));
const body = {
agreement_template_id: id,
recipients,
options
};
return new Promise((resolve, reject) => {
Client.instance.fetch('/api/v2/agreements/request_sign', 'POST', body)
.then(response => resolve(new Agreement(response)))
.catch(reason => reject(reason));
});
}
}
export default AgreementService;