UNPKG

blow-data

Version:
16 lines (15 loc) 488 B
'use strict'; const blow_query_1 = require('blow-query'); function uniqueFactory(model) { return function unique(propertyName) { const query = new blow_query_1.Query(); query.equal(propertyName, this[propertyName]); return model.count(query.toJSON().where).map(c => { if (c === 0) { return; } return `'${propertyName}' does not have unique value`; }); }; } exports.uniqueFactory = uniqueFactory;