/** * This functions gets the default terms of use for a given project id * * @param {Number} projectId The id of the project for which to get the default terms of use * @returns {Promise<Array<Number>>} An array containing the ids of the default project terms of use */ async function getProjectDefaultTerms (projectId) { const token = await getM2MToken() const projectUrl = `${config.PROJECTS_API_URL}/${projectId}` const res = await axios.get(projectUrl, { headers: { Authorization: `Bearer ${token}` } }) return res.data.terms || [] }
/** * Ensure project exist * @param {String} projectId the project id * @param {String} userToken the user token */ async function ensureProjectExist (projectId, userToken) { let token = await getM2MToken() const url = `${config.PROJECTS_API_URL}/${projectId}` try { await axios.get(url, { headers: { Authorization: `Bearer ${token}` } }) } catch (err) { if (_.get(err, 'response.status') === HttpStatus.NOT_FOUND) { throw new errors.BadRequestError(`Project with id: ${projectId} doesn't exist`) } else { // re-throw other error throw err } } }