UNPKG

mir-client

Version:
51 lines (46 loc) 1.57 kB
import * as R from 'ramda' /** * @function CreatePatchFactory - Creates PatchFactory instance for a certain Mir API. * @param {Object} axios - Initialized Axios instance. * @param {string} resource - The target collection. * @returns {PatchFactory} - A factory functiom that accepts a Mir API resource name. */ function CreatePatchFactory(axios, resource) { /** * @typedef PatchFactory * @type {function} * @param {string} id - The id of the object to be patched. * @param {Object} document - The partial document with which to patch the existing resource. * @returns {QueryBuilder} * A note on QueryBuilder--PATCH currently allows no queries but retains the QueryBuilder structure for future development. */ const PatchFactory = (id, document) => { /** * A Query Builder object * @typedef QueryBuilder * @type {Object} * @property {Object} headers - Stores headers for the request. * @property {function} send - Sends a request with the current stored headers. */ const QueryBuilder = { headers: {}, /** * @function send * @param {function} hook - TODO: not implemented * @this QueryBuilder * @returns {Promise} - Axios promise */ send(hook) { const headers = this.headers return axios.patch(`${resource}/${id}`, document, { headers }).then((result) => { return result }) } } return QueryBuilder } return PatchFactory } export default CreatePatchFactory