0.0.7 • Published 8 years ago

z-validator-initializer v0.0.7

Weekly downloads
29
License
-
Repository
-
Last release
8 years ago

z-data-validator-initializer

rules example - using validate.js

validators/api/example/hello/js

module.exports = function (app) {
    return {
        body: {
            "data": {
                presence: {
                    message: "^REQUIRED"
                }
            },
            "data.name": {
                presence: {
                    message: "^REQUIRED"
                },
                inclusion: {
                    within : ['VALUE1', 'VALUE2'],
                    message: "^INVALID_VALUE"
                }
            }
        },
        params: {
            "id": {
                presence: {
                    message: "^REQUIRED"
                }
            },
            "type": {
                presence: {
                    message: "^REQUIRED"
                }
            }
        },
        query: {
            "orderBy": {
                presence: {
                    message: "^REQUIRED"
                }
            }
        }
    };
};

routes/api/example.js

'use strict';

module.exports = function (app) {

    var router = require('express').Router();

    router.post(
        '/hello/:id/:type',
        app.zValidator.validate(app.zValidator.api.example.hello),
        function (req, res, next) {
            app.service.example.hello(req, function (error, data) {
                error ? next(error) : res.json(data);
            });
        });

    return router;
};
0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago