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 | 1x 1x 1x 1x 1x 1x 59x 59x 59x 59x | import {Getter, inject} from '@loopback/core';
import {HasOneRepositoryFactory, repository} from '@loopback/repository';
import {FormRepository} from '.';
import {LogChainDataSource} from '../datasources';
import {Action, ActionRelations, Form} from '../models';
import {BaseCrudRepository} from './base-crud.repository.base';
export class ActionRepository extends BaseCrudRepository<
Action,
typeof Action.prototype.id,
ActionRelations
> {
public readonly form: HasOneRepositoryFactory<
Form,
typeof Action.prototype.id
>;
constructor(
@inject('datasources.logchain') dataSource: LogChainDataSource,
@repository.getter('FormRepository')
protected form_repo_getter: Getter<FormRepository>,
) {
super(Action, dataSource);
this.form = this.createHasOneRepositoryFactoryFor('form', form_repo_getter);
this.registerInclusionResolver('form', this.form.inclusionResolver);
}
/**
* Find action by id and personas.
* @param id The action id.
* @param persona_id The persona id.
*/
async findByActionByPersonas(
id: number,
persona_id: number,
): Promise<Action[]> {
const actions = await this.execute(
`SELECT * FROM actions WHERE $1=ANY(personas) AND id=$2`,
[persona_id, id],
);
return actions as Action[];
}
/**
* Find actions match with personas.
*/
async findByActionsByPersonas(): Promise<Action[]> {
const actions = await this.execute(
`SELECT * FROM get_actions_for_persona()`,
);
return actions as Action[];
}
/**
* Find actions match with persona and cargo_type.
*/
async findByActionsByPersonaAndCargo(cargo_type = 0): Promise<Action[]> {
const actions = await this.execute(
`SELECT * FROM get_actions_for_persona_and_cargo(${cargo_type})`,
);
return actions as Action[];
}
}
|