-
Notifications
You must be signed in to change notification settings - Fork 46
/
service.ts.mst
55 lines (47 loc) · 1.45 KB
/
service.ts.mst
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
import { Service } from 'typedi';
import { Repository } from 'typeorm';
import { InjectRepository } from 'typeorm-typedi-extensions';
import { BaseService, WhereInput } from 'warthog';
import { {{className}} } from './{{kebabName}}.model';
import { {{#variantNames}} {{.}}, {{/variantNames}} } from '../variants/variants.model'
@Service('{{className}}Service')
export class {{className}}Service extends BaseService<{{className}}> {
constructor(
@InjectRepository({{className}}) protected readonly repository: Repository<{{className}}>
) {
super({{className}}, repository);
}
async find<W extends WhereInput>(
where?: any,
orderBy?: string,
limit?: number,
offset?: number,
fields?: string[]
): Promise<{{className}}[]> {
let f = fields;
if (f == undefined) {
f = [];
}
{{#fields}}
{{#is.union}}
if (!f.includes('{{camelName}}')) {
f = [...f, '{{camelName}}'];
}
{{/is.union}}
{{/fields}}
{{#has.union}}
let records = await super.find<W>(where, orderBy, limit, offset, f);
if (records.length) {
{{#fields}}
{{#is.union}}
{{#fieldVariantMap}}
records = await {{type}}.fetchData{{field}}(records, '{{camelName}}')
{{/fieldVariantMap}}
{{/is.union}}
{{/fields}}
}
return records;
{{/has.union}}
{{^has.union}} return super.find<W>(where, orderBy, limit, offset, f); {{/has.union}}
}
}