All files / src/services CheckUniqueService.ts

90% Statements 9/10
100% Branches 0/0
50% Functions 1/2
90% Lines 9/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 281x 1x 1x 1x         1x       3x 3x 1x 1x                        
import checkUnique from '../methods/check-unique';
import ensureHasAllKeys from '../helpers/ensure-has-all-keys';
import { AuthenticationManagementBase } from './AuthenticationManagementBase';
import { makeDefaultOptions } from './index';
 
import type { SetRequired } from 'type-fest';
import type { DataCheckUnique, CheckUniqueOptions } from '../types';
 
export class CheckUniqueService extends AuthenticationManagementBase<DataCheckUnique, unknown> {
  options: CheckUniqueOptions;
 
  constructor (options: SetRequired<Partial<CheckUniqueOptions>, 'app'>) {
    super();
    ensureHasAllKeys(options, ['app'], this.constructor.name);
    const defaultOptions: Omit<CheckUniqueOptions, 'app'> = makeDefaultOptions(['service']);
    this.options = Object.assign(defaultOptions, options);
  }
 
  async _create (data: DataCheckUnique): Promise<unknown> {
    return await checkUnique(
      this.options,
      data.value,
      data.ownId,
      data.meta
    );
  }
}