All files / src/repositories flow-default-reference.repository.ts

80% Statements 8/10
100% Branches 0/0
50% Functions 1/2
75% Lines 6/8

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 461x 1x 1x 1x   1x           18x                                                                    
import {inject} from '@loopback/core';
import {LogChainDataSource} from '../datasources';
import {FlowDefaultReference, FlowDefaultReferenceRelations} from '../models';
import {BaseCrudRepository} from './base-crud.repository.base';
 
export class FlowDefaultReferenceRepository extends BaseCrudRepository<
  FlowDefaultReference,
  typeof FlowDefaultReference.prototype.id,
  FlowDefaultReferenceRelations
> {
  constructor(@inject('datasources.logchain') dataSource: LogChainDataSource) {
    super(FlowDefaultReference, dataSource);
  }
 
  /**
   * Find reference documents by journey id.
   * @param flow_id The flow id.
   * @param step_id The step id.
   */
  async findRefDocumentsByJourneyId(
    flow_id: number,
    step_id: number,
  ): Promise<FlowDefaultReference[]> {
    const docs = await this.execute(
      `SELECT
        fdr.flow_default_action_id as action_id,
        CASE
          WHEN fdc.title IS NOT NULL THEN
            fdc.title
          WHEN fdc.title IS NULL THEN
            CASE
              WHEN fdc.form_id IS NOT NULL THEN
                f."name"
            END
          END as name
      FROM
        flows_default_reference as fdr
      INNER JOIN flows_default_action AS fdc ON fdr.flow_default_action_id = fdc.id
      LEFT JOIN forms AS f ON fdc.form_id = f.ID
      WHERE fdr.flow_default_id = $1 AND fdr.flow_default_journey_point_id = $2;`,
      [flow_id, step_id],
    );
    return docs as FlowDefaultReference[];
  }
}