diff --git a/services/areas.js b/services/areas.js index fec52f592..4f2538b6b 100644 --- a/services/areas.js +++ b/services/areas.js @@ -5,7 +5,12 @@ import { WRIAPI } from 'utils/axios'; import { logger } from 'utils/logs'; /** - * Get area + * Get area. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#get-area|here} + * @param {String} id Area id. + * @param {Object} params Request paremeters. + * @param {Object} headers Request headers. + * @returns {Object} */ export const fetchArea = (id, params = {}, headers = {}) => { logger.info(`Fetch area ${id}`); @@ -28,7 +33,10 @@ export const fetchArea = (id, params = {}, headers = {}) => { }; /** - * Get user areas + * Get user areas. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#get-user-areas|here} + * @param {String} token user's token. + * @returns {Object} */ export const fetchUserAreas = (token) => { logger.info('Fetch user areas'); @@ -48,8 +56,9 @@ export const fetchUserAreas = (token) => { /** * Deletes an area - * @param {areaId} ID of the area that will be deleted - * @param {token} User token + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#delete-area|here} + * @param {String} areaId - ID of the area that will be deleted + * @param {String} token - User token * @returns {Promise} */ export const deleteArea = (areaId, token) => { @@ -63,7 +72,12 @@ export const deleteArea = (areaId, token) => { }; /** - * Create new area + * Create new area. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#create-area|here} + * @param {String} name + * @param {String} geostore Geostore ID + * @param {String} token user's token + * @returns {Object} */ export const createArea = (name, geostore, token) => { logger.info('Create area'); @@ -84,7 +98,13 @@ export const createArea = (name, geostore, token) => { }; /** - * Update area + * Update area. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#areas|here} + * @param {String} id + * @param {String} name Name of the new area + * @param {String} token user's token. + * @param {String} geostore Geostore ID + * @returns {Object} */ export const updateArea = (id, name, token, geostore) => { logger.info(`Update area ${id}`); diff --git a/services/blog.js b/services/blog.js index b08a3df8f..865e3b353 100644 --- a/services/blog.js +++ b/services/blog.js @@ -4,7 +4,8 @@ import { logger } from 'utils/logs'; /** * Fetchs posts from wordpress API. * - * @param {Object[]} params - params sent to the API. + * @param {Object} params - params sent to the API. + * @param {Object} headers - headers sent to the API. * @returns {Object[]} array of parsed posts. */ export const fetchPosts = (params = {}, headers = {}) => { diff --git a/services/collections.js b/services/collections.js index 32d167234..ac200d060 100644 --- a/services/collections.js +++ b/services/collections.js @@ -6,8 +6,8 @@ import { logger } from 'utils/logs'; /** * Retrieve all collections of the user - * @param {*} token User's token - * @param {*} params Request optional parameters + * @param {String} token User's token + * @param {Object} params Request optional parameters */ export const fetchAllCollections = ( token, @@ -33,9 +33,9 @@ export const fetchAllCollections = ( }; /** * Retrieve data of a specific collection - * @param {*} token User's token - * @param {*} collectionId Id of the collection we are asking for. - * @param {*} params Request parameters + * @param {String} token User's token + * @param {String} collectionId Id of the collection we are asking for. + * @param {Object} params Request parameters */ export const fetchCollection = ( token, @@ -63,8 +63,8 @@ export const fetchCollection = ( /** * Creates a new collection attached to the current user - * @param {*} token User's token - * @param {*} data collection data + * @param {String} token User's token + * @param {Object} data collection data */ export const createCollection = (token, data = {}) => { logger.info('Create collection'); @@ -90,8 +90,8 @@ export const createCollection = (token, data = {}) => { /** * Deletes an existing collection attached to the current user - * @param {*} token User's token - * @param {*} collectionId Id of the collection to be removed + * @param {String} token User's token + * @param {String} collectionId Id of the collection to be removed */ export const deleteCollection = (token, collectionId) => { logger.info(`Delete collection ${collectionId}`); @@ -106,9 +106,9 @@ export const deleteCollection = (token, collectionId) => { /** * Update an existing collection attached to the current user - * @param {*} token User's token - * @param {*} collectionId Id of the collection to be edited - * @param {*} data Data to be updated + * @param {String} token User's token + * @param {String} collectionId Id of the collection to be edited + * @param {Object} data Data to be updated */ export const updateCollection = (token, collectionId, data) => { logger.info(`Update collection ${collectionId}`); @@ -129,10 +129,10 @@ export const updateCollection = (token, collectionId, data) => { /* Resources management */ /** - * - * @param {*} token User's token - * @param {*} collectionId Id of the collection to be edited - * @param {*} resource Resource to be addded to the collection + * Add a resource to the collection + * @param {String} token User's token + * @param {String} collectionId Id of the collection to be edited + * @param {Object} resource Resource to be addded to the collection */ export const addResourceToCollection = (token, collectionId, resource = {}) => { logger.info(`Add resource to collection ${collectionId}`); @@ -157,10 +157,10 @@ export const addResourceToCollection = (token, collectionId, resource = {}) => { }; /** - * - * @param {*} token User's token - * @param {*} collectionId Id of the collection to be edited - * @param {*} resource Resource to be removed from the collection + * Remove resource from collection + * @param {String} token User's token + * @param {String} collectionId Id of the collection to be edited + * @param {Object} resource Resource to be removed from the collection */ export const removeResourceFromCollection = (token, collectionId, resource = {}) => { logger.info(`Remove resource from collection ${collectionId}`); diff --git a/services/contact-us.js b/services/contact-us.js index 26cd3ed9c..37cf554ba 100644 --- a/services/contact-us.js +++ b/services/contact-us.js @@ -2,6 +2,12 @@ import { WRIAPI } from 'utils/axios'; import { logger } from 'utils/logs'; +/** + * Sends a contact form including a topic, email address, and a message. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#contact-us|here} + * @param {Object} params Request paremeters to API. + * @returns {Promise} + */ export const contactUs = (params) => { logger.info('Contact us'); return WRIAPI.post('contact-us', params) diff --git a/services/dashboard.js b/services/dashboard.js index c4c60c08d..a3d9dcfcb 100644 --- a/services/dashboard.js +++ b/services/dashboard.js @@ -8,8 +8,9 @@ import { logger } from 'utils/logs'; /** * Fetchs dashboards according to params. - * - * @param {Object[]} params - params sent to the API. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#getting-all-dashboards|here} + * @param {Object} params Request paremeters to API. + * @param {Object} headers Request headers to API. * @returns {Object[]} array of serialized dashboards. */ export const fetchDashboards = (params = {}, headers = {}) => { @@ -43,7 +44,7 @@ export const fetchDashboards = (params = {}, headers = {}) => { /** * fetchs data for a specific dashboard. - * + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#dashboard|here} * @param {String} id - dashboard id. * @returns {Object} serialized specified dashboard. */ @@ -78,7 +79,7 @@ export const fetchDashboard = (id) => { /** * Creates a dashboard with the provided data. * This fetch needs authentication. - * + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#dashboard|here} * @param {Object} body - data provided to create the new dashboard. * @param {String} token - user's token. * @returns {Object} serialized created dashboard. @@ -115,7 +116,7 @@ export const createDashboard = (body, token) => { /** * Updates a specified dashboard with the provided data. * This fetch needs authentication. - * + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#dashboard|here} * @param {String} id - dashboard ID to be updated. * @param {Object} body - data provided to update the dashboard. * @param {String} token - user's token @@ -149,9 +150,9 @@ export const updateDashboard = (id, body, token) => { /** * Deletes a specified dashboard. * This fetch needs authentication. - * - * @param {*} id - dashboard ID to be deleted. - * @param {string} token - user's token. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#dashboard|here} + * @param {String} id - dashboard ID to be deleted. + * @param {String} token - user's token. * @returns {Object} fetch response. */ export const deleteDashboard = (id, token) => { @@ -180,9 +181,9 @@ export const deleteDashboard = (id, token) => { /** * Clones a topic to convert it into a dashboard based on topic's data. * This fetch needs authentication. - * + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#clone-dashboard216|here} * @param {String} id - topic ID to be cloned. - * @param {string} token - user's token. + * @param {String} token - user's token. * @return {Object} serialized dashboard cloned based on the ID topic. */ export const cloneDashboard = (id, token) => { diff --git a/services/dataset.js b/services/dataset.js index 10c0e5d4b..14955f7ed 100644 --- a/services/dataset.js +++ b/services/dataset.js @@ -62,10 +62,10 @@ export const fetchDatasets = (params = {}, headers = {}, _meta = false) => { /** - * fetches data for a specific dataset. - * + * Fetches a dataset by id. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#how-to-get-a-dataset-by-id|here} * @param {String} id - dataset id. - * @param {Object[]} params - params sent to the API. + * @param {Object} params - params sent to the API. * @returns {Object} serialized specified dataset. */ export const fetchDataset = (id, params = {}) => { @@ -102,8 +102,12 @@ export const fetchDataset = (id, params = {}) => { }; /** -* Get dataset tags -*/ + * Get dataset tags. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#tags-definition|here} + * @param {String} datasetId - dataset id. + * @param {Object} params - params sent to the API. + * @returns {Object} + */ export const fetchDatasetTags = (datasetId, params = {}) => { logger.info(`Fetch dataset tags: ${datasetId}`); return WRIAPI.get(`dataset/${datasetId}/vocabulary`, @@ -122,9 +126,9 @@ export const fetchDatasetTags = (datasetId, params = {}) => { /** * Deletes a specified dataset. * This fetch needs authentication. - * - * @param {*} id - dataset ID to be deleted. - * @param {string} token - user's token. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#deleting-a-dataset|here} + * @param {String} id - dataset ID to be deleted. + * @param {String} token - user's token. * @returns {Object} fetch response. */ export const deleteDataset = (id, token) => { @@ -157,6 +161,14 @@ export const deleteDataset = (id, token) => { }); }; +/** + * Create a Dataset. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#creating-a-dataset|here} + * @param {String} token - user's token. + * @param {Object} params - params sent to the API. + * @param {Object} headers - headers sent to the API. + * @returns {Object} + */ export const createDataset = (token, params = {}, headers) => { logger.info('Create dataset'); @@ -172,6 +184,14 @@ export const createDataset = (token, params = {}, headers) => { }); }; +/** + * Update a Dataset. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#updating-a-dataset|here} + * @param {String} id - dataset id. + * @param {String} token - user's token. + * @param {Object} params - params sent to the API. + * @returns {Object} + */ export const updateDataset = (id, token, params = {}) => { logger.info(`Update dataset: ${id}`); @@ -186,8 +206,14 @@ export const updateDataset = (id, token, params = {}) => { }; /** -* Update dataset tags -*/ + * Update dataset tags. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#updating-tags-of-an-existing-relationship|here} + * @param {String} datasetId - dataset id. + * @param {Object[]} tags - user's token. + * @param {String} token - user's token. + * @param {boolean} usePatch - user's token. + * @returns {Object} + */ export const updateDatasetTags = (datasetId, tags, token, usePatch = false) => { logger.info(`Update dataset tags: ${datasetId}`); @@ -240,12 +266,12 @@ export const updateDatasetTags = (datasetId, tags, token, usePatch = false) => { }; /** - * Creates a metadata object in the specified dataset + * Creates a metadata object in the specified dataset. * This methods requires authentication. - * - * @param {*} datasetId - dataset ID where the metadata will be attached + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#creating-a-metadata-object|here} + * @param {String} datasetId - dataset ID where the metadata will be attached * @param {Object} params - metadata object - * @param {string} token - user's token. + * @param {String} token - user's token. * @returns {Object} serialized metadata object. */ export const createMetadata = (datasetId, params = {}, token, headers = {}) => { @@ -269,12 +295,12 @@ export const createMetadata = (datasetId, params = {}, token, headers = {}) => { }; /** - * Updates a metadata object in the specified dataset + * Updates a metadata object in the specified dataset. * This methods requires authentication. - * - * @param {*} datasetId - dataset ID where the metadata will be attached + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#updating-a-metadata|here} + * @param {String} datasetId - dataset ID where the metadata will be attached * @param {Object} params - metadata object - * @param {string} token - user's token. + * @param {String} token - user's token. * @returns {Object} serialized metadata object. */ export const updateMetadata = (datasetId, params = {}, token, headers = {}) => { diff --git a/services/favourites.js b/services/favourites.js index 0d5dbedd3..a9710001e 100644 --- a/services/favourites.js +++ b/services/favourites.js @@ -6,7 +6,8 @@ import { logger } from 'utils/logs'; /** * Retrieve all favourites items of the user - * @param {*} token User's token + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#get-favorites|here} + * @param {String} token User's token */ export const fetchFavourites = (token) => { logger.info('Fetch favourites'); @@ -31,9 +32,10 @@ export const fetchFavourites = (token) => { /** * Creates a new favourite item attached to the current user - * @param {*} token User's token - * @param {*} resourceId Id of the resource - * @param {*} resourceType Resource's type (can be dataset, layer or widget) + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#create-favorite|here} + * @param {String} token User's token + * @param {Object} options resourceId - Id of the resource, + * resourceType - resource's type (can be dataset, layer or widget) */ export const createFavourite = (token, { resourceId, resourceType }) => { logger.info('Create favourite'); @@ -54,8 +56,9 @@ export const createFavourite = (token, { resourceId, resourceType }) => { /** * Deletes an existing favourite item attached to the current user - * @param {*} token User's token - * @param {*} resourceId Id of the resource + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#delete-favorite|here} + * @param {String} token User's token + * @param {String} resourceId Id of the resource */ export const deleteFavourite = (token, resourceId) => { logger.info(`Delete favourite ${resourceId}`); diff --git a/services/fields.js b/services/fields.js index 5fefa619d..3a2a40b16 100644 --- a/services/fields.js +++ b/services/fields.js @@ -3,11 +3,9 @@ import axios from 'axios'; // utils import { logger } from 'utils/logs'; -// API docs: https://resource-watch.github.io/doc-api/index-rw.html#fields - /** - * fetches fields for a specific dataset. - * + * Fetches fields for a specific dataset. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#fields|here} * @param {String} url - URL to get fields. * @returns {Object} array of dataset fields. */ diff --git a/services/geostore.js b/services/geostore.js index b82b2546a..6eadf8c5f 100644 --- a/services/geostore.js +++ b/services/geostore.js @@ -5,9 +5,10 @@ import { WRIAPI } from 'utils/axios'; import { logger } from 'utils/logs'; /** - * fetches Geostore - * @param {Object[]} id - geostore ID. - * @returns {Object[]} serialized geostore object. + * Fetches Geostore + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#geostore|here} + * @param {String} id - geostore ID. + * @returns {Object} serialized geostore object. */ export const fetchGeostore = (id) => { logger.info(`Fetch geostore ${id}`); @@ -30,6 +31,11 @@ export const fetchGeostore = (id) => { }); }; +/** + * Create a Geostore + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#create-geostore|here} + * @param {Object} geojson Geojson with your geometry + */ export const createGeostore = (geojson) => { logger.info('Create geostore'); return WRIAPI.post('geostore', geojson) @@ -43,6 +49,8 @@ export const createGeostore = (geojson) => { /** * Fetch countries + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#geostore|here} + * @returns {Object[]} */ export const fetchCountries = () => { logger.info('Fetch countries'); @@ -66,6 +74,7 @@ export const fetchCountries = () => { /** * Get country + * @param {String} iso */ export const fetchCountry = (iso) => { logger.info(`Fetch country: ${iso}`); diff --git a/services/graph.js b/services/graph.js index 2c1c14c91..3046b69d3 100644 --- a/services/graph.js +++ b/services/graph.js @@ -5,9 +5,9 @@ import { WRIAPI } from 'utils/axios'; import { logger } from 'utils/logs'; /** - * Get all tags - * @param {Object} params Request parameters - * https://resource-watch.github.io/doc-api/index-rw.html#list-concepts + * Get all tags. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#list-concepts|here} + * @param {Object} params Request parameters to API. */ export const fetchAllTags = (params = {}) => { logger.info('Fetch all tags'); @@ -29,9 +29,9 @@ export const fetchAllTags = (params = {}) => { }; /** - * Get inferred tags - * @param {Object} params Request parameters - * https://resource-watch.github.io/doc-api/index-rw.html#get-inferred-concepts + * Get inferred tags. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#get-inferred-concepts|here} + * @param {Object} params Request parameters to API. */ export const fetchInferredTags = (params = {}) => { logger.info('Fetch inferred tags'); @@ -53,9 +53,10 @@ export const fetchInferredTags = (params = {}) => { }; /** - * Send a request to count a view to the dataset - * @param {string} datasetId Dataset ID - * @param {string} [token] User token + * Send a request to count a view to the dataset. + * @param {String} datasetId Dataset ID + * @param {String} token User token + * @param {Object} params Request parameters to API. * @returns {Promise} */ export const countDatasetView = (datasetId, token, params = {}) => { @@ -78,8 +79,9 @@ export const countDatasetView = (datasetId, token, params = {}) => { }; /** - * Get the list of most viewed datasets - * @param {Object} params Request parameters + * Get the list of most viewed datasets. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#most-liked-datasets|here} + * @param {Object} params Request parameters to API. * @returns {Promise} List of sorted ids */ export const fetchMostViewedDatasets = (params = {}) => { @@ -102,9 +104,9 @@ export const fetchMostViewedDatasets = (params = {}) => { }; /** - * Get the list of most favourited datasets - * @param {Object} params Request parameters - * https://resource-watch.github.io/doc-api/index-rw.html#most-liked-datasets + * Get the list of most favourited datasets. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#most-liked-datasets|here} + * @param {Object} params Request parameters to API. */ export const fetchMostFavoritedDatasets = (params = {}) => { logger.info('Fetch most favorited datasets'); @@ -126,11 +128,11 @@ export const fetchMostFavoritedDatasets = (params = {}) => { }; /** - * Fetch similar datasets - * @param {Object} params Request parameters + * Fetch similar datasets. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#similar-datasets-including-ancestors|here} + * @param {Object} params Request parameters to API. * @param {boolean} withAncestors Flag indicating whether tags' ancestors * should be considered or not - * https://resource-watch.github.io/doc-api/index-rw.html#similar-datasets-including-ancestors */ export const fetchSimilarDatasets = (params = {}, withAncestors = true) => { logger.info('Fetch similar datasets'); diff --git a/services/layer.js b/services/layer.js index b22a01c08..4440bfea8 100644 --- a/services/layer.js +++ b/services/layer.js @@ -1,5 +1,4 @@ -import 'isomorphic-fetch'; -import { get, post } from 'utils/request'; +import { post } from 'utils/request'; import WRISerializer from 'wri-json-api-serializer'; // utils @@ -14,6 +13,7 @@ export default class LayersService { // getColumns({ dataset }) { // return new Promise((resolve, reject) => { // get({ + // eslint-disable-next-line max-len // url: `${process.env.WRI_API_URL}/fields/${dataset}?application=${process.env.APPLICATIONS}&env=${process.env.API_ENV}`, // headers: [{ // key: 'Content-Type', @@ -73,8 +73,10 @@ export default class LayersService { /** * Fetchs layers according to params. - * - * @param {Object[]} params - params sent to the API. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#how-obtain-all-layers|here} + * @param {Object} params - params sent to the API. + * @param {Object} headers - headers sent to the API. + * @param {boolean} _meta - should meta be in response or not * @returns {Object[]} array of serialized layers. */ export const fetchLayers = (params = {}, headers = {}, _meta = false) => { @@ -125,12 +127,11 @@ export const fetchLayers = (params = {}, headers = {}, _meta = false) => { /** * Fetches a layer according to widget id and params. - * + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#how-obtain-specific-layers|here} * @param {String} id - layer id. - * @param {Object[]} params - params sent to the API. + * @param {Object} params - params sent to the API. * @returns {Object[]} - serialized specific layer. */ - export const fetchLayer = (id, params = {}) => { if (!id) throw Error('layer id is mandatory to perform this fetching.'); logger.info(`Fetches layer: ${id}`); @@ -172,9 +173,10 @@ export const fetchLayer = (id, params = {}) => { /** * Deletes a specified layer. * This fetch needs authentication. - * - * @param {*} id - layer ID to be deleted. - * @param {string} token - user's token. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#delete-a-layer|here} + * @param {String} layerId - layer ID to be deleted. + * @param {String} datasetId - dataset ID to be deleted. + * @param {String} token - user's token. * @returns {Object} fetch response. */ export const deleteLayer = (layerId, datasetId, token) => { diff --git a/services/pages.js b/services/pages.js index 5f142728d..f9a2b77a7 100644 --- a/services/pages.js +++ b/services/pages.js @@ -26,7 +26,7 @@ export default class PagesService { value: 1 }], onSuccess: (response) => { - new Deserializer({keyForAttribute: 'underscore_case'}).deserialize(response, (err, pages) => { + new Deserializer({ keyForAttribute: 'underscore_case' }).deserialize(response, (err, pages) => { resolve(sortBy(pages, 'name')); }); }, @@ -53,7 +53,7 @@ export default class PagesService { value: 1 }], onSuccess: (response) => { - new Deserializer({keyForAttribute: 'underscore_case'}).deserialize(response, (err, page) => { + new Deserializer({ keyForAttribute: 'underscore_case' }).deserialize(response, (err, page) => { resolve(page); }); }, @@ -82,7 +82,7 @@ export default class PagesService { value: this.opts.authorization }], onSuccess: (response) => { - new Deserializer({keyForAttribute: 'underscore_case'}).deserialize(response, (err, page) => { + new Deserializer({ keyForAttribute: 'underscore_case' }).deserialize(response, (err, page) => { resolve(page); }); }, diff --git a/services/partners.js b/services/partners.js index 28a313e16..093c45ca5 100644 --- a/services/partners.js +++ b/services/partners.js @@ -60,7 +60,7 @@ export default class PartnersService { value: this.opts.authorization }], onSuccess: (response) => { - new Deserializer({keyForAttribute: 'underscore_case'}).deserialize(response, (err, partner) => { + new Deserializer({ keyForAttribute: 'underscore_case' }).deserialize(response, (err, partner) => { resolve(partner); }); }, @@ -93,7 +93,7 @@ export default class PartnersService { /** * Fetchs partners according to params. * - * @param {Object[]} params - params sent to the API. + * @param {Object} params - params sent to the API. * @returns {Object[]} array of serialized partners. */ export const fetchPartners = (params = {}) => diff --git a/services/query.js b/services/query.js index 18b88cb4f..421ba6c43 100644 --- a/services/query.js +++ b/services/query.js @@ -1,5 +1,11 @@ import { WRIAPI } from 'utils/axios'; +/** + * Send GET request to /query + * @param {String} token token User's token + * @param {*} sql mandatory parameter + * @param {Object} params request paremeters to API. + */ export const fetchQuery = (token, sql, params = {}) => { if (!token) { console.error('This is an authorized endpoint. A token need to be provided.'); diff --git a/services/subscriptions.js b/services/subscriptions.js index 163543b19..44e509ee1 100644 --- a/services/subscriptions.js +++ b/services/subscriptions.js @@ -5,7 +5,10 @@ import { WRIAPI } from 'utils/axios'; import { logger } from 'utils/logs'; /** - * Get Subscriptions + * Get Subscriptions + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#obtain-the-subscriptions-for-a-user|here} + * @param {String} token User's token + * @param {Object} params request paremeters to API. */ export const fetchSubscriptions = (token, params) => { logger.info('Fetch subscriptions'); @@ -39,6 +42,8 @@ export const fetchSubscriptions = (token, params) => { /** * Creates a subscription for an area + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#create-subscription|here} + * @param {Object} options */ export const createSubscriptionToArea = ({ areaId, @@ -74,7 +79,14 @@ export const createSubscriptionToArea = ({ }; /** - * Update Subscription + * Update Subscription + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#modify-subscription|here} + * @param {String} subscriptionId + * @param {*} datasets + * @param {*} datasetsQuery + * @param {Object} user + * @param {String} language + * @param {String} areaId */ export const updateSubscriptionToArea = ( subscriptionId, @@ -109,7 +121,10 @@ export const updateSubscriptionToArea = ( }; /** - * Get Subscription + * Get Subscription + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#subscribable-datasets|here} + * @param {String} subscriptionId + * @param {String} token User's token */ export const fetchSubscription = (subscriptionId, token) => { logger.info(`Fetch subscription: ${subscriptionId}`); @@ -125,8 +140,9 @@ export const fetchSubscription = (subscriptionId, token) => { /** * Deletes a subscription - * @param {subscriptionId} ID of the subscription that will be deleted - * @param {token} User token + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#delete-subscription|here} + * @param {String} subscriptionId of the subscription that will be deleted + * @param {Strign} token User's token * @returns {Promise} */ export const deleteSubscription = (subscriptionId, token) => { diff --git a/services/topics.js b/services/topics.js index 7a4d1551f..1f4a589f7 100644 --- a/services/topics.js +++ b/services/topics.js @@ -6,8 +6,9 @@ import { logger } from 'utils/logs'; /** * Fetches topics according to params. - * - * @param {Object[]} params - params sent to the API. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#getting-all-topics|here} + * @param {Object} params - params sent to the API. + * @param {Object} headers- headers sent to the API. * @returns {Object[]} array of serialized topics. */ export const fetchTopics = (params = {}, headers = {}) => { @@ -41,8 +42,8 @@ export const fetchTopics = (params = {}, headers = {}) => { }; /** - * fetches data for a specific topic. - * + * Fetches data for a specific topic. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#getting-all-topics|here} * @param {String} id - topic id. * @returns {Object} serialized specified topic. */ @@ -71,7 +72,7 @@ export const fetchTopic = (id) => { /** * Creates a topic with the provided data. * This fetch needs authentication. - * + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#topic|here} * @param {Object} body - data provided to create the new topic. * @param {String} token - user's token. * @returns {Object} serialized created topic. @@ -103,7 +104,7 @@ export const createTopic = (body, token) => { /** * Updates a specified topic with the provided data. * This fetch needs authentication. - * + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#topic|here} * @param {String} id - topic ID to be updated. * @param {Object} body - data provided to update the topic. * @param {String} token - user's token @@ -136,9 +137,9 @@ export const updateTopic = (id, body, token) => { /** * Deletes a specified topic. * This fetch needs authentication. - * - * @param {*} id - topic ID to be deleted. - * @param {string} token - user's token. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#topic|here} + * @param {String} id - topic ID to be deleted. + * @param {String} token - user's token. * @returns {Object} fetch response. */ export const deleteTopic = (id, token) => { diff --git a/services/user.js b/services/user.js index 7caba4fa5..2fd27890e 100644 --- a/services/user.js +++ b/services/user.js @@ -4,6 +4,9 @@ import { localAPI, controlTowerAPI } from 'utils/axios'; /** * Logs in a user based on the email + password combination + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#login-email-password|here} + * @param {Object} options + * @returns {Object} */ export const loginUser = ({ email, password }) => { logger.info('Login user'); @@ -15,6 +18,9 @@ export const loginUser = ({ email, password }) => { /** * This function sends a request to reset the user's password. * It generates a token to be used in resetPassword + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#password-recovery|here} + * @param {Object} options + * @returns {Object} */ export const forgotPassword = ({ email }) => { logger.info('Forgot password'); @@ -33,6 +39,9 @@ export const forgotPassword = ({ email }) => { /** * Register a new user based on the email + password combination + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#registration|here} + * @param {Object} options + * @returns {Object} */ export const registerUser = ({ email, password, repeatPassword }) => { logger.info('Register user'); @@ -59,6 +68,9 @@ export const registerUser = ({ email, password, repeatPassword }) => { * Needs the token hosted in the email sent in forgotPassword * NOTE:this is NOT implemented in the API to be done from the app. * right now the only way it's through the email link pointing to Control Tower. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#password-recovery|here} + * @param {Object} options + * @returns {Object} */ export const resetPassword = ({ tokenEmail, password, repeatPassword }) => { logger.info('Reset password'); @@ -75,7 +87,11 @@ export const resetPassword = ({ tokenEmail, password, repeatPassword }) => { }); }; - +/** + * Upload user photo + * @param {Blob} file file data + * @param {Object} user + */ export const uploadPhoto = (file, user) => new Promise((resolve, reject) => { const reader = new FileReader(); diff --git a/services/widget.js b/services/widget.js index f7bcaa00f..3128dc3b0 100644 --- a/services/widget.js +++ b/services/widget.js @@ -59,8 +59,8 @@ export const fetchWidgets = (params = {}, headers = {}, _meta = false) => { /** - * fetches data for a specific widget. - * + * Fetches data for a specific widget. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#how-obtain-a-single-widget|here} * @param {String} id - widget id. * @param {Object} params - params sent to the API. * @returns {Object} serialized specified widget. @@ -103,13 +103,13 @@ export const fetchWidget = (id, params = {}) => { }; /** - * Deletes the specified widget. - * This method requires authentication. - * - * @param {*} widgetId - widget ID to be deleted. - * @param {string} datasetId - dataset ID the widget belongs to - * @param {string} token - user's token. - * @returns {Object} response. + * Deletes a specified widget. + * This fetch needs authentication. + * Check out the API docs for this endpoint {@link https://resource-watch.github.io/doc-api/index-rw.html#delete-a-widget|here} + * @param {String} widgetId - widget ID to be deleted. + * @param {String} datasetId - dataset ID. + * @param {String} token - user's token. + * @returns {Object} fetch response. */ export const deleteWidget = (widgetId, datasetId, token) => { logger.info(`Delete widget: ${widgetId}`);