22 lines
542 B
JavaScript
22 lines
542 B
JavaScript
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();
|
|
}
|
|
};
|