resource-watch/graph-client

View on GitHub
app/src/services/dataset.service.js

Summary

Maintainability
A
0 mins
Test Coverage
A
93%
const logger = require('logger');
const { RWAPIMicroservice } = require('rw-api-microservice-node');

class DatasetService {

    static async checkDatasets(datasets, query = {}, apiKey) {
        logger.info('Checking published and other fields of dataset', datasets);

        const body = {
            ids: datasets
        };
        if (query.env) {
            body.env = query.env;
        }

        const requestQuery = { ...query };
        delete requestQuery.dataset;
        delete requestQuery.loggedUser;
        delete requestQuery.env;

        const result = await RWAPIMicroservice.requestToMicroservice({
            uri: '/v1/dataset/find-by-ids',
            method: 'POST',
            body,
            qs: requestQuery,
            headers: {
                'x-api-key': apiKey,
            }
        });
        logger.debug('Returning ', result);
        if (result && result.data) {
            return result.data.map((el) => el.id);
        }
        return [];

    }

}

module.exports = DatasetService;