1.0.0 • Published 10 years ago
wadofgum-uuid v1.0.0
wadofgum-uuid 
A mixin to make sure your models have an 'id' field configured to be a uuid string. This mixin does nothing if you don't have a validation mixin loaded.
When using this mixin an id property will be added to your class schema and defined as Joi.string().guid(). When calling validate if the instance's id property is blank, a uuid will be assigned for you.
const Wadofgum = require('wadofgum');
const Validation = require('wadofgum-validation');
const UUID = require('wadofgum-uuid');
const Joi = require('joi');
class Model extends Wadofgum.mixin(Validation, UUID) {};
Model.schema = { name: Joi.string() };
let model = new Model({ name: 'test' });
model.id; // undefined
model.validate().then(function () {
model.id; // some randomly generated uuid
});1.0.0
10 years ago
1.0.0-beta1
11 years ago