Last active
July 25, 2018 03:01
-
-
Save slaveofcode/c99bbbad3bb982e438569be6835abfd5 to your computer and use it in GitHub Desktop.
Podeng Example to Use in ExpressJs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { blueprint, types, validator } = require('podeng'); | |
async function handler(req, res, next) { | |
const UserShema = blueprint.object({ | |
name: types.string({ serialize: { to: 'username' }}), | |
age: types.integer | |
}); | |
const params = req.params; | |
const UserValidator = validator(UserSchema, { deserialization: true }); // accepting { username, age } | |
const [err, errDetails] = UserValidator.validate(params); | |
let results = {}; | |
if (!err) | |
results = await db.User.create(UserSchema.deserialize(params)); // User { name, age } | |
res.json(UserSchema.serialize(results)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment