All files / platform/modules/salon/src/Services RemoteService.js

63.64% Statements 14/22
50% Branches 4/8
75% Functions 3/4
65% Lines 13/20

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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49    1x   1x 1x       5x       5x             3x 2x 2x 2x 2x 1x     1x                                     1x  
'use strict';
 
const _ = require('lodash');
 
const namespace = use('Config').get('modules.salon.general.namespace');
const CE = use('C2C/Exceptions');
 
class RemoteService {
  static get inject() {
    return ['C2C/Services/QueueService'];
  }
 
  constructor(queueService) {
    this.queue = queueService;
  }
 
  /**
   * @return {Boolean}
   */
  async checkThirdPartyToken(token) {
    if (!token) return true;
    const Job = use(`${namespace}/Jobs/CheckThirdPartyToken`);
    const job = await this.queue.add(Job.key, { token });
    const result = await job.finished();
    if (!_.get(result, 'isValid')) {
      throw CE.BadRequestException.raise('errors.resourceRequireToken');
    }
 
    return true;
  }
 
  /**
   * @return {Boolean}
   */
  async salorizaCheckThirdPartyToken(token) {
    if (!token) return true;
    const Job = use(`${namespace}/Jobs/SalorizaCheckThirdPartyToken`);
    const job = await this.queue.add(Job.key, { token });
    const result = await job.finished();
    if (!_.get(result, 'isValid')) {
      throw CE.BadRequestException.raise('errors.resourceRequireToken');
    }
 
    return true;
  }
}
 
module.exports = RemoteService;