rez_core 2.0.88 → 2.0.89
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.
- package/dist/module/layout_preference/controller/layout_preference.controller.d.ts +3 -0
- package/dist/module/layout_preference/controller/layout_preference.controller.js +15 -0
- package/dist/module/layout_preference/controller/layout_preference.controller.js.map +1 -1
- package/dist/module/layout_preference/service/layout_preference.service.d.ts +4 -1
- package/dist/module/layout_preference/service/layout_preference.service.js +38 -2
- package/dist/module/layout_preference/service/layout_preference.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/layout_preference/controller/layout_preference.controller.ts +18 -9
- package/src/module/layout_preference/service/layout_preference.service.ts +59 -1
package/package.json
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Controller,
|
|
3
|
-
Get,
|
|
4
|
-
Inject,
|
|
5
|
-
Param,
|
|
6
|
-
Query,
|
|
7
|
-
Req,
|
|
8
|
-
UseGuards,
|
|
9
|
-
} from '@nestjs/common';
|
|
1
|
+
import { Controller, Get, Inject, Query, Req, UseGuards } from '@nestjs/common';
|
|
10
2
|
import { LayoutPreferenceService } from '../service/layout_preference.service';
|
|
11
3
|
import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
|
|
12
4
|
|
|
@@ -30,4 +22,21 @@ export class LayoutPreferenceController {
|
|
|
30
22
|
entity_type,
|
|
31
23
|
);
|
|
32
24
|
}
|
|
25
|
+
|
|
26
|
+
@Get('column')
|
|
27
|
+
@UseGuards(JwtAuthGuard)
|
|
28
|
+
async getColumnValues(
|
|
29
|
+
@Query('entity_type') entity_type: string,
|
|
30
|
+
@Query('column') column: string,
|
|
31
|
+
@Query('sort_by') sort_by: string,
|
|
32
|
+
@Req() req: Request & { user: any },
|
|
33
|
+
) {
|
|
34
|
+
const userId = req.user.userData.id;
|
|
35
|
+
|
|
36
|
+
return this.layoutPreferenceService.getColumnValue(
|
|
37
|
+
entity_type,
|
|
38
|
+
column,
|
|
39
|
+
sort_by,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
33
42
|
}
|
|
@@ -3,10 +3,14 @@ import { BaseEntity } from 'src/module/meta/entity/base-entity.entity';
|
|
|
3
3
|
import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
|
|
4
4
|
import { UserData } from 'src/module/user/entity/user.entity';
|
|
5
5
|
import { LayoutPreferenceRepository } from '../repository/layout_preference.repository';
|
|
6
|
+
import { DataSource } from 'typeorm';
|
|
6
7
|
|
|
7
8
|
@Injectable()
|
|
8
9
|
export class LayoutPreferenceService extends EntityServiceImpl {
|
|
9
|
-
constructor(
|
|
10
|
+
constructor(
|
|
11
|
+
private layoutPreferenceRepository: LayoutPreferenceRepository,
|
|
12
|
+
private readonly dataSource: DataSource,
|
|
13
|
+
) {
|
|
10
14
|
super();
|
|
11
15
|
}
|
|
12
16
|
|
|
@@ -43,4 +47,58 @@ export class LayoutPreferenceService extends EntityServiceImpl {
|
|
|
43
47
|
user_id,
|
|
44
48
|
);
|
|
45
49
|
}
|
|
50
|
+
|
|
51
|
+
async getColumnValue(
|
|
52
|
+
entity_type: string,
|
|
53
|
+
column: string,
|
|
54
|
+
sort_by: string,
|
|
55
|
+
): Promise<string[]> {
|
|
56
|
+
const getTableMeta =
|
|
57
|
+
await this.entityTableService.findByEntityTypeAndListTypeAndDisplayType(
|
|
58
|
+
entity_type,
|
|
59
|
+
entity_type,
|
|
60
|
+
'LIST',
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const tableName = getTableMeta?.data_source;
|
|
64
|
+
if (!tableName) {
|
|
65
|
+
throw new Error('Invalid or missing table name in metadata');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Query to get counts of distinct values in the column
|
|
69
|
+
const rawData: { column_value: string; count: number }[] =
|
|
70
|
+
await this.dataSource
|
|
71
|
+
.createQueryBuilder()
|
|
72
|
+
.select(`${column} AS column_value`)
|
|
73
|
+
.addSelect(`COUNT(*) AS count`)
|
|
74
|
+
.from(tableName, tableName)
|
|
75
|
+
.groupBy(column)
|
|
76
|
+
.getRawMany();
|
|
77
|
+
|
|
78
|
+
// Convert result to map and sort
|
|
79
|
+
const result = Object.fromEntries(
|
|
80
|
+
rawData.map((row) => [row.column_value, Number(row.count)]),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
let entries = Object.entries(result);
|
|
84
|
+
|
|
85
|
+
switch (sort_by) {
|
|
86
|
+
case 'asc':
|
|
87
|
+
entries.sort(([a], [b]) => a.localeCompare(b));
|
|
88
|
+
break;
|
|
89
|
+
case 'dsc':
|
|
90
|
+
entries.sort(([a], [b]) => b.localeCompare(a));
|
|
91
|
+
break;
|
|
92
|
+
case 'count_asc':
|
|
93
|
+
entries.sort(([, countA], [, countB]) => countA - countB);
|
|
94
|
+
break;
|
|
95
|
+
case 'count_dsc':
|
|
96
|
+
entries.sort(([, countA], [, countB]) => countB - countA);
|
|
97
|
+
break;
|
|
98
|
+
default:
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return entries.map(([value]) => value);
|
|
103
|
+
}
|
|
46
104
|
}
|