@nathapp/nestjs-data 1.0.0-rc.11 → 1.0.0-rc.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -11,6 +11,7 @@ export declare abstract class BaseSpRepository extends BaseRepository {
|
|
|
11
11
|
readonly executeCommand: string;
|
|
12
12
|
constructor(dataSource: DataSource, executeCommand?: string);
|
|
13
13
|
callQuery(spName: string, formatOrValue?: any, params?: any, rename?: (key: string, depth: number, object: any) => string, objectifyForSignleRecord?: boolean): Promise<any>;
|
|
14
|
+
private resolveRecordsets;
|
|
14
15
|
private prepare;
|
|
15
16
|
private renameKey;
|
|
16
17
|
private changeKey;
|
|
@@ -15,50 +15,52 @@ class BaseSpRepository extends BaseRepository {
|
|
|
15
15
|
}
|
|
16
16
|
async callQuery(spName, formatOrValue, params, rename, objectifyForSignleRecord = false) {
|
|
17
17
|
const { formattedSP, paramaters } = await this.prepare(spName, formatOrValue, params);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
const results = await this.dataSource.query(formattedSP, paramaters);
|
|
19
|
+
return this.resolveRecordsets(results, rename, objectifyForSignleRecord);
|
|
20
|
+
}
|
|
21
|
+
resolveRecordsets(results, rename, objectifyForSignleRecord = false) {
|
|
22
|
+
if (!Array.isArray(results)) {
|
|
23
|
+
if (objectifyForSignleRecord) {
|
|
24
|
+
return {};
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const result = [];
|
|
35
|
-
for (let i = 0; recordset.length > i; i++) {
|
|
36
|
-
const record = recordset[i];
|
|
37
|
-
result.push(this.renameKey(record, rename));
|
|
38
|
-
}
|
|
39
|
-
recordsets.push(result);
|
|
40
|
-
}
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
const status = results.pop();
|
|
29
|
+
if (1 < results.length) {
|
|
30
|
+
const recordsets = [];
|
|
31
|
+
for (let i = 0; results.length > i; i++) {
|
|
32
|
+
const recordset = results[i];
|
|
33
|
+
if (!rename) {
|
|
34
|
+
recordsets.push(recordset);
|
|
41
35
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (rename) {
|
|
48
|
-
return this.renameKey(recordset[0], rename);
|
|
36
|
+
else {
|
|
37
|
+
const result = [];
|
|
38
|
+
for (let i = 0; recordset.length > i; i++) {
|
|
39
|
+
const record = recordset[i];
|
|
40
|
+
result.push(this.renameKey(record, rename));
|
|
49
41
|
}
|
|
50
|
-
|
|
42
|
+
recordsets.push(result);
|
|
51
43
|
}
|
|
52
44
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
45
|
+
return recordsets;
|
|
46
|
+
}
|
|
47
|
+
const recordset = results[0];
|
|
48
|
+
if (objectifyForSignleRecord) {
|
|
49
|
+
if (1 == recordset.length) {
|
|
50
|
+
if (rename) {
|
|
51
|
+
return this.renameKey(recordset[0], rename);
|
|
57
52
|
}
|
|
58
|
-
return
|
|
53
|
+
return recordset[0];
|
|
59
54
|
}
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
}
|
|
56
|
+
if (rename) {
|
|
57
|
+
const result = [];
|
|
58
|
+
for (let i = 0; recordset.length > i; i++) {
|
|
59
|
+
result.push(this.renameKey(recordset[i], rename));
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
return recordset;
|
|
62
64
|
}
|
|
63
65
|
async prepare(spName, formatOrValue, params) {
|
|
64
66
|
let paramaters = [];
|
|
@@ -31,7 +31,7 @@ class TypeOrmExModule {
|
|
|
31
31
|
inject: [(0, typeorm_1.getDataSourceToken)(dataSource)],
|
|
32
32
|
provide: repository,
|
|
33
33
|
useFactory: (dataSource) => {
|
|
34
|
-
if (repository instanceof repository_1.BaseRepository) {
|
|
34
|
+
if (repository.prototype instanceof repository_1.BaseRepository) {
|
|
35
35
|
return new repository(dataSource);
|
|
36
36
|
}
|
|
37
37
|
const baseRepository = dataSource.getRepository(entity);
|