gfw-api/forest-watcher

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

Summary

Maintainability
A
3 hrs
Test Coverage
F
56%
const logger = require('logger');
const { RWAPIMicroservice } = require('rw-api-microservice-node');
const deserializer = require('serializers/deserializer');


class GeostoreService {

    static async getGeostore(geostoreId) {
        logger.info('Getting geostore with id', geostoreId);
        try {
            const geostore = await RWAPIMicroservice.requestToMicroservice({
                uri: `/geostore/${geostoreId}`,
                method: 'GET',
                json: true
            });
            logger.info('Got geostore', geostore);
            return deserializer(geostore);
        } catch (e) {
            logger.error('Error while fetching geostore', e);
            throw e;
        }
    }

    static async createGeostore(geojson) {
        try {
            const geostore = await RWAPIMicroservice.requestToMicroservice({
                uri: '/geostore',
                method: 'POST',
                body: {
                    geojson,
                    lock: true
                },
                json: true
            });
            return deserializer(geostore);
        } catch (e) {
            logger.error('Error while creating geostore', e);
            throw e;
        }
    }

}
module.exports = GeostoreService;