All files / src/services flow-persona.service.ts

47.37% Statements 9/19
0% Branches 0/2
25% Functions 1/4
41.18% Lines 7/17

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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 671x 1x   1x 1x     1x     17x   17x                                                                                                            
import {bind, /* inject, */ BindingScope} from '@loopback/core';
import {repository} from '@loopback/repository';
import {BaseResponses, FlowPersona} from '../models';
import {FlowPersonaRepository} from '../repositories';
import {BaseService} from './base.service';
 
@bind({scope: BindingScope.TRANSIENT})
export class FlowPersonaService extends BaseService<FlowPersona> {
  constructor(
    @repository(FlowPersonaRepository)
    public flow_persona_repo: FlowPersonaRepository,
  ) {
    super();
  }
 
  /**
   * Ensure get right records.
   */
  public ensureRightAccessRecord(): void {}
 
  /**
   * Builds the query.
   * @param q The query string.
   */
  async buildSearchQuery(q?: string) {
    if (!q) {
      return;
    }
 
    const ilike_value = this.buildILikeValue(q);
    this.filter_builder.impose({
      or: [
        {
          name: ilike_value,
        },
      ],
    });
  }
 
  /**
   * Get list reference personas.
   * @param filter
   */
  async findPersonas(id: number): Promise<BaseResponses<FlowPersona>> {
    this.filter_builder.impose({flow_id: id});
    this.filter_builder.include({
      relation: 'persona',
      scope: {
        fields: ['id', 'title'],
      },
    });
 
    this.filter_builder.include({
      relation: 'company',
      scope: {
        fields: ['id', 'identifier', 'name', 'privacy_status'],
      },
    });
 
    this.filter_builder.fields(['id', 'name', 'persona_id', 'company_id']);
    // allow get all persona
    this.filter_builder.limit(Number.MAX_SAFE_INTEGER);
 
    return this.flow_persona_repo.findWithPaging(this.filter_builder.build());
  }
}