gfw-api/gfw-area

View on GitHub
app/src/validators/download.validator.js

Summary

Maintainability
A
1 hr
Test Coverage
D
66%
const logger = require('logger');
const ErrorSerializer = require('serializers/error.serializer');

class DownloadValidator {

    static async get(ctx, next) {
        logger.debug('Validating request to download layer');
        ctx.checkParams('geostoreId').len(24, 36);
        ctx.checkParams('minZoom').gt(0).isNumeric().toInt();
        ctx.checkParams('maxZoom').lt(18).isNumeric().toInt();
        ctx.checkQuery('layerUrl');

        if (ctx.errors) {
            ctx.body = ErrorSerializer.serializeValidationParamsErrors(ctx.errors);
            ctx.status = 400;
            return;
        }
        ctx.checkParams('maxZoom').ge(ctx.params.minZoom);
        if (ctx.errors) {
            ctx.body = ErrorSerializer.serializeValidationParamsErrors(ctx.errors);
            ctx.status = 400;
            return;
        }

        await next();
    }

}

module.exports = DownloadValidator;