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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | 1x 1x 1x 1x 1x 1x 17x 17x 17x 17x 17x | import { EntryView } from '@logchain/models/views';
import {bind, /* inject, */ BindingScope} from '@loopback/core';
import {EntityNotFoundError, FilterBuilder, Options, repository} from '@loopback/repository';
import {BaseResponses, Entry} from '../models';
import {EntryRecordRepository, EntryRepository, EntryViewRepository} from '../repositories';
import {BaseService} from './base.service';
@bind({scope: BindingScope.TRANSIENT})
export class EntryService extends BaseService<Entry> {
entry_tbl_name = Entry.definition.settings['postgresql'].table;
constructor(
@repository(EntryRepository)
public entry_repo: EntryRepository,
@repository(EntryViewRepository)
public entryview_repo: EntryViewRepository,
@repository(EntryRecordRepository)
public entry_record_repo: EntryRecordRepository,
) {
super();
}
/**
* Ensure get right records.
*/
public ensureRightAccessRecord(): void {
this.filter_builder.impose({
company_id: this.current_user.company_id,
});
}
/**
* Get array Entry based on filter.
* @param filter
*/
async find(): Promise<BaseResponses<EntryView>> {
const entryViewFilter = new FilterBuilder<EntryView>();
entryViewFilter.filter = this.filter_builder.filter;
this.addExtraFilter(entryViewFilter);
return this.entryview_repo.fillRelation(entryViewFilter);
}
/**
* Get reference documents for entries.
* @param id The entry id.
*/
async getReferenceDocuments(id: number) {
this.addWhereIdOrIdentifier(id);
const entries = await this.entry_repo.findOne(this.filter_builder.build(), {
get_reference: true,
});
if (!entries) {
throw new EntityNotFoundError(this.entry_repo.entityClass, id);
}
const {ref_documents} = entries;
return {ref_documents};
}
/**
* Builds the query for entries
* @param q The query string.
*/
async buildSearchQuery(q?: string) {
if (!q) {
return;
}
const ilike_value = this.buildILikeValue(q);
const companies_id = await this.getCompaniesIdByQuery(ilike_value);
// FILTER: Should be a LIKE search
// company_other.name OR
// company_other.identifier OR
// vehicle_no OR
// tank_no OR
// order_no
this.filter_builder.impose({
or: [
{
company_other_id: {
inq: companies_id,
},
},
{
vehicle_no: ilike_value,
},
{
tank_no: ilike_value,
},
{
order_no: ilike_value,
},
{
flow_id: ilike_value as unknown as number,
},
],
});
}
/**
* Add extra filter for Entry
* @param filterBuilder The filter builder instance
* @param options The options
* @return Filter
*/
addExtraFilter(filterBuilder: FilterBuilder, options?: Options) {
super._addIncludeModifier(filterBuilder);
filterBuilder
.include({
relation: 'company_other',
scope: {
fields: {
id: true,
identifier: true,
name: true,
},
},
})
.include({
relation: 'delivered_company',
scope: {
fields: {
id: true,
identifier: true,
name: true,
},
},
})
.include({
relation: 'delivered',
scope: {
fields: {
id: true,
identifier: true,
name: true,
},
},
})
.include({
relation: 'supervise',
scope: {
fields: {
id: true,
identifier: true,
name: true,
},
},
})
.include({
relation: 'entry_records',
scope: {
fields: {
id: true,
entry_id: true,
type: true,
inspection_result: true,
cancelled_action: true,
},
},
});
}
}
|