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 | 1x 1x 1x 1x 1x 17x 17x | import {bind, /* inject, */ BindingScope} from '@loopback/core';
import {OrClause, repository} from '@loopback/repository';
import {BaseService} from '.';
import {BaseResponses, Persona} from '../models';
import {PersonaRepository} from '../repositories';
@bind({scope: BindingScope.TRANSIENT})
export class PersonaService extends BaseService<Persona> {
constructor(
@repository(PersonaRepository)
public persona_repo: PersonaRepository,
) {
super();
}
/**
* Get array personas based on filter.
*/
async find(): Promise<BaseResponses<Persona>> {
this.filter_builder.order(['id ASC']);
return this.persona_repo.findWithPaging(this.filter_builder.build());
}
/**
* Add ensure get active record while getting personas (privacy_status as false)
*/
ensureRightAccessRecord() {
this.filter_builder.impose({
privacy_status: false,
});
}
/**
* Get list of actions of personas
*/
async getActionsByPersona() {
const actions = await this.action_repo.findByActionsByPersonas();
return {
total: actions.length,
data: actions,
has_more: false,
};
}
/**
* Get list of actions by personas and cargos
*/
async getActionsByPersonaAndCargo(cargo_type = 0) {
const actions = await this.action_repo.findByActionsByPersonaAndCargo(cargo_type);
return {
total: actions.length,
data: actions,
has_more: false,
};
}
/**
* Builds the query for personas
* @param q The query string.
*/
async buildSearchQuery(q?: string) {
if (!q) {
return;
}
// FILTER: Should be a LIKE search
// OR title
// OR description
const ilike_value = this.buildILikeValue(q);
const or_clause: OrClause<Persona> = {
or: [
{
title: ilike_value,
},
{
description: ilike_value,
},
],
};
this.filter_builder.impose(or_clause);
}
}
|