Ghost/ghost/offers/lib/application/UniqueChecker.js
Fabien O'Carroll 9bcd25fe5e Moved application concerns to an application dir
no-issue

Shuffling files to give a better idea of what the files concern, as well
as to add some structure.
2021-10-08 12:27:17 +02:00

33 lines
855 B
JavaScript

class UniqueChecker {
/**
* @param {import('./OfferRepository')} repository
* @param {import('knex').Transaction} transaction
*/
constructor(repository, transaction) {
this.repository = repository;
this.options = {
transacting: transaction
};
}
/**
* @param {import('../domain/models/OfferCode')} code
* @returns {Promise<boolean>}
*/
async isUniqueCode(code) {
const exists = await this.repository.existsByCode(code.value, this.options);
return !exists;
}
/**
* @param {import('../domain/models/OfferName')} name
* @returns {Promise<boolean>}
*/
async isUniqueName(name) {
const exists = await this.repository.existsByName(name.value, this.options);
return !exists;
}
}
module.exports = UniqueChecker;