2018-02-06 14:09:31 +00:00
|
|
|
module.exports = function(Self) {
|
2018-05-31 09:52:39 +00:00
|
|
|
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
|
|
|
};
|