mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
9bcd25fe5e
no-issue Shuffling files to give a better idea of what the files concern, as well as to add some structure.
33 lines
855 B
JavaScript
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;
|