salix/modules/client/back/models/address-observation.js

22 lines
542 B
JavaScript
Raw Normal View History

2018-02-06 14:09:31 +00:00
module.exports = function(Self) {
Self.validateAsync('typeUnique', typeIsUnique, {
message: 'Observation type must be unique'
});
async function typeIsUnique(err, done) {
let filter = {
fields: ['id'],
where: {
observationTypeFk: this.observationTypeFk,
addressFk: this.addressFk
}
};
if (this.id)
filter.where.id = {neq: this.id};
if (await Self.findOne(filter))
err();
done();
}
2018-02-06 14:09:31 +00:00
};