Skip to content

Instantly share code, notes, and snippets.

@slaveofcode
Last active July 25, 2018 03:01
Show Gist options
  • Save slaveofcode/c99bbbad3bb982e438569be6835abfd5 to your computer and use it in GitHub Desktop.
Save slaveofcode/c99bbbad3bb982e438569be6835abfd5 to your computer and use it in GitHub Desktop.
Podeng Example to Use in ExpressJs
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