2021-10-05 12:15:57 +03:00
|
|
|
class UniqueChecker {
|
|
|
|
/**
|
|
|
|
* @param {import('./OfferRepository')} repository
|
|
|
|
* @param {import('knex').Transaction} transaction
|
|
|
|
*/
|
|
|
|
constructor(repository, transaction) {
|
|
|
|
this.repository = repository;
|
|
|
|
this.options = {
|
|
|
|
transacting: transaction
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-10-08 13:27:17 +03:00
|
|
|
* @param {import('../domain/models/OfferCode')} code
|
2021-10-05 12:15:57 +03:00
|
|
|
* @returns {Promise<boolean>}
|
|
|
|
*/
|
|
|
|
async isUniqueCode(code) {
|
2021-10-07 17:42:56 +03:00
|
|
|
const exists = await this.repository.existsByCode(code.value, this.options);
|
2021-10-05 12:43:38 +03:00
|
|
|
return !exists;
|
2021-10-05 12:15:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-10-08 13:27:17 +03:00
|
|
|
* @param {import('../domain/models/OfferName')} name
|
2021-10-05 12:15:57 +03:00
|
|
|
* @returns {Promise<boolean>}
|
|
|
|
*/
|
|
|
|
async isUniqueName(name) {
|
2021-10-07 17:42:56 +03:00
|
|
|
const exists = await this.repository.existsByName(name.value, this.options);
|
2021-10-05 12:43:38 +03:00
|
|
|
return !exists;
|
2021-10-05 12:15:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = UniqueChecker;
|