Repository URL to install this package:
|
Version:
2.0.0-rc.7 ▾
|
'use strict';
var fetch$1 = require('./helpers/fetch.js');
var loginMonolithUser = require('./loginMonolithUser.js');
const fetch = require('fetch-everywhere');
/**
* Delete a mandator from the database.
*
* @note when you call `deleteMandator()` it does a "soft" delete, removing it from
* the list of the user's mandator, but keeps it in the database so other users can't
* use it. This method will remove it permanantly from the database, freeing it up for
* anyone to use it (hence the need for a superuser's credentials).
*
* @param {string} mandatorId - The user's mandator Id
* @returns {Promise<object>}
*/
async function permanentlyDeleteMandator(mandatorId) {
if (typeof mandatorId !== 'number') {
throw new TypeError(`mandatorId param must be a number, got ${typeof mandatorId}`);
}
const {
SUPER_USER_EMAIL,
SUPER_USER_PASSWORD
} = process.env;
if (!SUPER_USER_EMAIL) {
throw new TypeError('You must set process.env.SUPER_USER_EMAIL to use this function.');
}
if (!SUPER_USER_PASSWORD) {
throw new TypeError('You must set process.env.SUPER_USER_PASSWORD to use this function.');
}
const url = `${process.env.MONOLITH_API_BASE_URL}/api/v3.0/mandators/${mandatorId}/permanent`; // We need to log the super user in to get its access token
const superUserInfo = await loginMonolithUser(SUPER_USER_EMAIL, SUPER_USER_PASSWORD); // Now the super's access token can do the permanent delete.
const superUserAccessToken = superUserInfo.accessToken;
const headers = {
'Content-Type': 'application/json',
'Access-Token': superUserAccessToken
};
return fetch(url, {
method: 'DELETE',
headers
}).then(fetch$1.responseHandler).catch(fetch$1.errorHandler);
}
module.exports = permanentlyDeleteMandator;
//# sourceMappingURL=permanentlyDeleteMandator.js.map