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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | 1x 1x 1x 1x 1x 48x | import {inject} from '@loopback/core';
import {LogChainDataSource} from '../datasources';
import {FlowGroup, FlowGroupRelations} from '../models';
import {BaseCrudRepository} from './base-crud.repository.base';
export class FlowGroupRepository extends BaseCrudRepository<
FlowGroup,
typeof FlowGroup.prototype.id,
FlowGroupRelations
> {
constructor(@inject('datasources.logchain') dataSource: LogChainDataSource) {
super(FlowGroup, dataSource);
}
/**
* Find group by journey id.
* @param flow_id The flow id.
* @param step_id The step id.
*/
async findGroupsByJourneyId(
flow_id: number,
step_id: number,
): Promise<FlowGroup[]> {
const groups = await this.execute(
`SELECT
fg.*,
json_agg(json_build_object(
'id', fp.id,
'name',
CASE
WHEN fp.name IS NOT NULL THEN
fp.name
ELSE comp.name
END,
'icon', get_icon_name(p.title),
'persona_title', p.title,
'persona_id', p.id
)
) as company_personas
FROM
flows_group as fg
LEFT JOIN flows_persona as fp ON fp.id = ANY(fg.flow_personas)
LEFT JOIN companies as comp ON fp.company_id =comp.id
LEFT JOIN personas as p ON fp.persona_id = p.id
WHERE
$1=ANY(fg.journey_points) AND
fg.flow_id=$2
GROUP BY fg.id
ORDER BY fg."order";`,
[step_id, flow_id],
);
return groups as FlowGroup[];
}
/**
* Find group by flow id.
* @param flow_id The flow id.
*/
async findGroupsByFlowId(flow_id: number): Promise<FlowGroup[]> {
const groups = await this.execute(
`SELECT
fg.* ,
json_agg(json_build_object(
'id', fp.id,
'name',
CASE
WHEN fp.name IS NOT NULL THEN
fp.name
ELSE comp.name
END,
'icon', get_icon_name(p.title),
'persona_title', p.title
)
) as company_personas,
(SELECT ARRAY_AGG(id) FROM flows_journey_point AS fjp WHERE fjp.flow_persona_id = ANY(fg.flow_personas)) AS journey_points_forced
FROM
flows_group as fg
LEFT JOIN flows_persona as fp ON fp.id =ANY(fg.flow_personas)
LEFT JOIN companies as comp ON fp.company_id =comp.id
LEFT JOIN personas as p ON fp.persona_id = p.id
WHERE
fg.flow_id=$1
GROUP BY fg.id
ORDER BY fg."order";`,
[flow_id],
);
return groups as FlowGroup[];
}
}
|