salix/services/client/common/models/address-observation.js

26 lines
655 B
JavaScript
Raw Normal View History

2018-02-06 14:09:31 +00:00
module.exports = function(Self) {
Self.validatesPresenceOf('observationTypeFk', {
message: 'Observation type cannot be blank'
});
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
};