@trafficgroup/knex-rel 0.1.21 → 0.1.23-rc.0
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/.claude/settings.local.json +5 -2
- package/CLAUDE.md +2 -11
- package/dist/constants/folder.constants.d.ts +2 -2
- package/dist/constants/folder.constants.js +6 -15
- package/dist/constants/folder.constants.js.map +1 -1
- package/dist/constants/study.constants.d.ts +1 -1
- package/dist/constants/study.constants.js +1 -1
- package/dist/constants/video.constants.d.ts +2 -2
- package/dist/constants/video.constants.js +5 -9
- package/dist/constants/video.constants.js.map +1 -1
- package/dist/dao/VideoMinuteResultDAO.d.ts +19 -2
- package/dist/dao/VideoMinuteResultDAO.js +75 -29
- package/dist/dao/VideoMinuteResultDAO.js.map +1 -1
- package/dist/dao/auth/auth.dao.js +1 -4
- package/dist/dao/auth/auth.dao.js.map +1 -1
- package/dist/dao/batch/batch.dao.d.ts +0 -10
- package/dist/dao/batch/batch.dao.js +14 -51
- package/dist/dao/batch/batch.dao.js.map +1 -1
- package/dist/dao/camera/camera.dao.js +7 -10
- package/dist/dao/camera/camera.dao.js.map +1 -1
- package/dist/dao/chat/chat.dao.d.ts +1 -1
- package/dist/dao/chat/chat.dao.js +40 -27
- package/dist/dao/chat/chat.dao.js.map +1 -1
- package/dist/dao/folder/folder.dao.js +7 -18
- package/dist/dao/folder/folder.dao.js.map +1 -1
- package/dist/dao/location/location.dao.js +9 -16
- package/dist/dao/location/location.dao.js.map +1 -1
- package/dist/dao/message/message.dao.d.ts +1 -1
- package/dist/dao/message/message.dao.js +26 -18
- package/dist/dao/message/message.dao.js.map +1 -1
- package/dist/dao/report-configuration/report-configuration.dao.js +68 -39
- package/dist/dao/report-configuration/report-configuration.dao.js.map +1 -1
- package/dist/dao/study/study.dao.d.ts +8 -1
- package/dist/dao/study/study.dao.js +20 -15
- package/dist/dao/study/study.dao.js.map +1 -1
- package/dist/dao/systemConfiguration/SystemConfigurationDAO.d.ts +2 -2
- package/dist/dao/systemConfiguration/SystemConfigurationDAO.js +26 -26
- package/dist/dao/systemConfiguration/SystemConfigurationDAO.js.map +1 -1
- package/dist/dao/user/user.dao.js +1 -4
- package/dist/dao/user/user.dao.js.map +1 -1
- package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js +8 -26
- package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js.map +1 -1
- package/dist/dao/video/video.dao.js +28 -30
- package/dist/dao/video/video.dao.js.map +1 -1
- package/dist/index.d.ts +10 -9
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/interfaces/batch/batch.interfaces.d.ts +1 -1
- package/dist/interfaces/camera/camera.interfaces.d.ts +1 -1
- package/dist/interfaces/chat/chat.interfaces.d.ts +3 -3
- package/dist/interfaces/folder/folder.interfaces.d.ts +1 -1
- package/dist/interfaces/message/message.interfaces.d.ts +2 -2
- package/dist/interfaces/report-configuration/report-configuration.interfaces.d.ts +1 -0
- package/dist/interfaces/study/study.interfaces.d.ts +2 -8
- package/dist/interfaces/user/user.interfaces.d.ts +1 -1
- package/dist/interfaces/user-push-notification-token/user-push-notification-token.interfaces.d.ts +1 -1
- package/dist/interfaces/video/video.interfaces.d.ts +2 -2
- package/migrations/20250717160737_migration.ts +1 -1
- package/migrations/20250717160908_migration.ts +2 -5
- package/migrations/20250717161310_migration.ts +1 -1
- package/migrations/20250717161406_migration.ts +3 -3
- package/migrations/20250717162431_migration.ts +1 -1
- package/migrations/20250717173228_migration.ts +2 -2
- package/migrations/20250717204731_migration.ts +1 -1
- package/migrations/20250722210109_migration.ts +4 -8
- package/migrations/20250722211019_migration.ts +1 -1
- package/migrations/20250723153852_migration.ts +10 -13
- package/migrations/20250723162257_migration.ts +7 -4
- package/migrations/20250723171109_migration.ts +7 -4
- package/migrations/20250723205331_migration.ts +9 -6
- package/migrations/20250724191345_migration.ts +11 -8
- package/migrations/20250730180932_migration.ts +13 -14
- package/migrations/20250730213625_migration.ts +11 -8
- package/migrations/20250804124509_migration.ts +21 -26
- package/migrations/20250804132053_migration.ts +8 -5
- package/migrations/20250804164518_migration.ts +7 -7
- package/migrations/20250823223016_migration.ts +21 -32
- package/migrations/20250910015452_migration.ts +6 -18
- package/migrations/20250911000000_migration.ts +4 -18
- package/migrations/20250917144153_migration.ts +7 -14
- package/migrations/20250930200521_migration.ts +4 -8
- package/migrations/20251010143500_migration.ts +6 -27
- package/migrations/20251020225758_migration.ts +15 -51
- package/migrations/20251112120000_migration.ts +2 -10
- package/migrations/20251112120200_migration.ts +7 -19
- package/migrations/20251112120300_migration.ts +2 -7
- package/migrations/20260109140000_migration.ts +2 -7
- package/package.json +3 -3
- package/src/constants/folder.constants.ts +8 -17
- package/src/constants/study.constants.ts +1 -1
- package/src/constants/video.constants.ts +7 -11
- package/src/d.types.ts +14 -18
- package/src/dao/VideoMinuteResultDAO.ts +127 -83
- package/src/dao/auth/auth.dao.ts +55 -58
- package/src/dao/batch/batch.dao.ts +100 -145
- package/src/dao/camera/camera.dao.ts +121 -124
- package/src/dao/chat/chat.dao.ts +45 -45
- package/src/dao/folder/folder.dao.ts +90 -105
- package/src/dao/location/location.dao.ts +87 -109
- package/src/dao/message/message.dao.ts +32 -32
- package/src/dao/reconciliation-log/reconciliation-log.dao.ts +1 -1
- package/src/dao/report-configuration/report-configuration.dao.ts +381 -370
- package/src/dao/study/study.dao.ts +83 -94
- package/src/dao/systemConfiguration/SystemConfigurationDAO.ts +35 -41
- package/src/dao/user/user.dao.ts +50 -52
- package/src/dao/user-push-notification-token/user-push-notification-token.dao.ts +48 -80
- package/src/dao/video/video.dao.ts +345 -396
- package/src/entities/BaseEntity.ts +1 -1
- package/src/index.ts +30 -43
- package/src/interfaces/auth/auth.interfaces.ts +10 -10
- package/src/interfaces/batch/batch.interfaces.ts +1 -1
- package/src/interfaces/camera/camera.interfaces.ts +9 -9
- package/src/interfaces/chat/chat.interfaces.ts +4 -4
- package/src/interfaces/folder/folder.interfaces.ts +2 -2
- package/src/interfaces/location/location.interfaces.ts +7 -7
- package/src/interfaces/message/message.interfaces.ts +3 -3
- package/src/interfaces/report-configuration/report-configuration.interfaces.ts +17 -16
- package/src/interfaces/study/study.interfaces.ts +3 -10
- package/src/interfaces/user/user.interfaces.ts +9 -9
- package/src/interfaces/user-push-notification-token/user-push-notification-token.interfaces.ts +9 -9
- package/src/interfaces/video/video.interfaces.ts +34 -34
|
@@ -1,113 +1,102 @@
|
|
|
1
1
|
import { Knex } from "knex";
|
|
2
2
|
import { IBaseDAO, IDataPaginator } from "../../d.types";
|
|
3
|
-
import { IStudy
|
|
4
|
-
import { STUDY_SORT_COLUMN_MAP } from "../../constants/study.constants";
|
|
3
|
+
import { IStudy } from "../../interfaces/study/study.interfaces";
|
|
5
4
|
import KnexManager from "../../KnexConnection";
|
|
5
|
+
import { StudySortField, STUDY_SORT_COLUMN_MAP } from "../../constants/study.constants";
|
|
6
|
+
import { SortOrder } from "../../constants/video.constants";
|
|
7
|
+
|
|
8
|
+
export interface IStudyFilters {
|
|
9
|
+
createdBy?: number | null;
|
|
10
|
+
sortBy?: StudySortField;
|
|
11
|
+
sortOrder?: SortOrder;
|
|
12
|
+
}
|
|
6
13
|
|
|
7
14
|
export class StudyDAO implements IBaseDAO<IStudy> {
|
|
8
|
-
|
|
15
|
+
private _knex: Knex<any, unknown[]> = KnexManager.getConnection();
|
|
9
16
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return createdStudy;
|
|
15
|
-
}
|
|
17
|
+
async create(item: IStudy): Promise<IStudy> {
|
|
18
|
+
const [createdStudy] = await this._knex("study").insert(item).returning("*");
|
|
19
|
+
return createdStudy;
|
|
20
|
+
}
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
.where("s.id", id)
|
|
27
|
-
.first();
|
|
28
|
-
return study || null;
|
|
29
|
-
}
|
|
22
|
+
async getById(id: number): Promise<IStudy | null> {
|
|
23
|
+
const study = await this._knex("study as s")
|
|
24
|
+
.innerJoin("users as u", "s.createdBy", "u.id")
|
|
25
|
+
.leftJoin("locations as l", "s.locationId", "l.id")
|
|
26
|
+
.select("s.*", this._knex.raw("to_jsonb(u.*) as user"), this._knex.raw("to_jsonb(l.*) as location"))
|
|
27
|
+
.where("s.id", id)
|
|
28
|
+
.first();
|
|
29
|
+
return study || null;
|
|
30
|
+
}
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
.where("s.uuid", uuid)
|
|
41
|
-
.first();
|
|
42
|
-
return study || null;
|
|
43
|
-
}
|
|
32
|
+
async getByUuid(uuid: string): Promise<IStudy | null> {
|
|
33
|
+
const study = await this._knex("study as s")
|
|
34
|
+
.innerJoin("users as u", "s.createdBy", "u.id")
|
|
35
|
+
.leftJoin("locations as l", "s.locationId", "l.id")
|
|
36
|
+
.select("s.*", this._knex.raw("to_jsonb(u.*) as user"), this._knex.raw("to_jsonb(l.*) as location"))
|
|
37
|
+
.where("s.uuid", uuid)
|
|
38
|
+
.first();
|
|
39
|
+
return study || null;
|
|
40
|
+
}
|
|
44
41
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
.returning("*");
|
|
50
|
-
return updatedStudy || null;
|
|
51
|
-
}
|
|
42
|
+
async update(id: number, item: Partial<IStudy>): Promise<IStudy | null> {
|
|
43
|
+
const [updatedStudy] = await this._knex("study").where({ id }).update(item).returning("*");
|
|
44
|
+
return updatedStudy || null;
|
|
45
|
+
}
|
|
52
46
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
47
|
+
async delete(id: number): Promise<boolean> {
|
|
48
|
+
const result = await this._knex("study").where({ id }).del();
|
|
49
|
+
return result > 0;
|
|
50
|
+
}
|
|
57
51
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
limit: number,
|
|
61
|
-
filters?: IStudyFilters,
|
|
62
|
-
): Promise<IDataPaginator<IStudy>> {
|
|
63
|
-
const offset = (page - 1) * limit;
|
|
52
|
+
async getAll(page: number, limit: number, filters?: IStudyFilters): Promise<IDataPaginator<IStudy>> {
|
|
53
|
+
const offset = (page - 1) * limit;
|
|
64
54
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
"s.*",
|
|
70
|
-
this._knex.raw("to_jsonb(u.*) as user"),
|
|
71
|
-
this._knex.raw("to_jsonb(l.*) as location"),
|
|
72
|
-
);
|
|
55
|
+
const query = this._knex("study as s")
|
|
56
|
+
.innerJoin("users as u", "s.createdBy", "u.id")
|
|
57
|
+
.leftJoin("locations as l", "s.locationId", "l.id")
|
|
58
|
+
.select("s.*", this._knex.raw("to_jsonb(u.*) as user"), this._knex.raw("to_jsonb(l.*) as location"));
|
|
73
59
|
|
|
74
|
-
|
|
75
|
-
|
|
60
|
+
if (filters) {
|
|
61
|
+
if (filters.createdBy !== undefined && filters.createdBy !== null) {
|
|
62
|
+
query.where("s.createdBy", filters.createdBy);
|
|
63
|
+
}
|
|
76
64
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
65
|
+
if (filters.sortBy) {
|
|
66
|
+
const columnName = STUDY_SORT_COLUMN_MAP[filters.sortBy];
|
|
67
|
+
const order = filters.sortOrder || "DESC";
|
|
68
|
+
query.orderBy(columnName, order);
|
|
69
|
+
} else {
|
|
70
|
+
query.orderBy("s.created_at", "DESC");
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
query.orderBy("s.created_at", "DESC");
|
|
74
|
+
}
|
|
84
75
|
|
|
85
|
-
|
|
76
|
+
const [countResult] = await query.clone().clearSelect().clearOrder().count("* as count");
|
|
77
|
+
const totalCount = +countResult.count;
|
|
78
|
+
const studies = await query.clone().limit(limit).offset(offset);
|
|
86
79
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
80
|
+
return {
|
|
81
|
+
success: true,
|
|
82
|
+
data: studies,
|
|
83
|
+
page,
|
|
84
|
+
limit,
|
|
85
|
+
count: studies.length,
|
|
86
|
+
totalCount,
|
|
87
|
+
totalPages: Math.ceil(totalCount / limit),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
97
90
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
)
|
|
107
|
-
.where("s.locationId", locationId)
|
|
108
|
-
.orderBy("s.created_at", "desc")
|
|
109
|
-
.limit(10);
|
|
91
|
+
async getStudiesByLocation(locationId: number): Promise<IStudy[]> {
|
|
92
|
+
const studies = await this._knex("study as s")
|
|
93
|
+
.innerJoin("users as u", "s.createdBy", "u.id")
|
|
94
|
+
.leftJoin("locations as l", "s.locationId", "l.id")
|
|
95
|
+
.select("s.*", this._knex.raw("to_jsonb(u.*) as user"), this._knex.raw("to_jsonb(l.*) as location"))
|
|
96
|
+
.where("s.locationId", locationId)
|
|
97
|
+
.orderBy("s.created_at", "desc")
|
|
98
|
+
.limit(10);
|
|
110
99
|
|
|
111
|
-
|
|
112
|
-
|
|
100
|
+
return studies;
|
|
101
|
+
}
|
|
113
102
|
}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import type { Knex } from
|
|
2
|
-
import { v4 as uuidv4 } from
|
|
3
|
-
import { ISystemConfiguration } from
|
|
4
|
-
import KnexManager from
|
|
1
|
+
import type { Knex } from 'knex';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
import { ISystemConfiguration } from '../../interfaces/systemConfiguration/ISystemConfiguration';
|
|
4
|
+
import KnexManager from '../../KnexConnection';
|
|
5
5
|
|
|
6
6
|
export class SystemConfigurationDAO {
|
|
7
7
|
private knex: Knex = KnexManager.getConnection();
|
|
8
8
|
|
|
9
|
-
public async create(
|
|
10
|
-
config: Omit<ISystemConfiguration, "id">,
|
|
11
|
-
): Promise<ISystemConfiguration> {
|
|
9
|
+
public async create(config: Omit<ISystemConfiguration, 'id'>): Promise<ISystemConfiguration> {
|
|
12
10
|
const toInsert = {
|
|
13
11
|
configUuid: config.configUuid ?? uuidv4(),
|
|
14
12
|
key: config.key,
|
|
@@ -17,52 +15,48 @@ export class SystemConfigurationDAO {
|
|
|
17
15
|
description: config.description,
|
|
18
16
|
};
|
|
19
17
|
|
|
20
|
-
const [inserted] = await this.knex<ISystemConfiguration>(
|
|
21
|
-
"system_configuration",
|
|
22
|
-
)
|
|
18
|
+
const [inserted] = await this.knex<ISystemConfiguration>('system_configuration')
|
|
23
19
|
.insert(toInsert)
|
|
24
|
-
.returning(
|
|
20
|
+
.returning('*');
|
|
25
21
|
|
|
26
22
|
return this.getById(inserted.id!);
|
|
27
23
|
}
|
|
28
24
|
|
|
29
25
|
public async getById(id: number): Promise<ISystemConfiguration | null> {
|
|
30
|
-
const rec = await this.knex<ISystemConfiguration>(
|
|
31
|
-
.where(
|
|
26
|
+
const rec = await this.knex<ISystemConfiguration>('system_configuration')
|
|
27
|
+
.where('id', id)
|
|
32
28
|
.first();
|
|
33
29
|
return rec ?? null;
|
|
34
30
|
}
|
|
35
31
|
|
|
36
32
|
public async getByUuid(uuid: string): Promise<ISystemConfiguration | null> {
|
|
37
|
-
const rec = await this.knex<ISystemConfiguration>(
|
|
38
|
-
.where(
|
|
33
|
+
const rec = await this.knex<ISystemConfiguration>('system_configuration')
|
|
34
|
+
.where('configUuid', uuid)
|
|
39
35
|
.first();
|
|
40
36
|
return rec ?? null;
|
|
41
37
|
}
|
|
42
38
|
|
|
43
39
|
public async getByKey(key: string): Promise<ISystemConfiguration | null> {
|
|
44
|
-
const rec = await this.knex<ISystemConfiguration>(
|
|
45
|
-
.where(
|
|
40
|
+
const rec = await this.knex<ISystemConfiguration>('system_configuration')
|
|
41
|
+
.where('key', key)
|
|
46
42
|
.first();
|
|
47
43
|
return rec ?? null;
|
|
48
44
|
}
|
|
49
45
|
|
|
50
|
-
public async getMultipleByKeys(
|
|
51
|
-
keys: string[],
|
|
52
|
-
): Promise<ISystemConfiguration[]> {
|
|
46
|
+
public async getMultipleByKeys(keys: string[]): Promise<ISystemConfiguration[]> {
|
|
53
47
|
if (keys.length === 0) {
|
|
54
48
|
return [];
|
|
55
49
|
}
|
|
56
50
|
|
|
57
|
-
return this.knex<ISystemConfiguration>(
|
|
58
|
-
.whereIn(
|
|
59
|
-
.select(
|
|
51
|
+
return this.knex<ISystemConfiguration>('system_configuration')
|
|
52
|
+
.whereIn('key', keys)
|
|
53
|
+
.select('*');
|
|
60
54
|
}
|
|
61
55
|
|
|
62
56
|
public async getAllConfigs(): Promise<ISystemConfiguration[]> {
|
|
63
|
-
return this.knex<ISystemConfiguration>(
|
|
64
|
-
.select(
|
|
65
|
-
.orderBy(
|
|
57
|
+
return this.knex<ISystemConfiguration>('system_configuration')
|
|
58
|
+
.select('*')
|
|
59
|
+
.orderBy('key', 'asc');
|
|
66
60
|
}
|
|
67
61
|
|
|
68
62
|
public async getAll(): Promise<ISystemConfiguration[]> {
|
|
@@ -71,49 +65,49 @@ export class SystemConfigurationDAO {
|
|
|
71
65
|
|
|
72
66
|
public async update(
|
|
73
67
|
id: number,
|
|
74
|
-
updates: Partial<ISystemConfiguration
|
|
68
|
+
updates: Partial<ISystemConfiguration>
|
|
75
69
|
): Promise<ISystemConfiguration | null> {
|
|
76
|
-
await this.knex<ISystemConfiguration>(
|
|
77
|
-
.where(
|
|
70
|
+
await this.knex<ISystemConfiguration>('system_configuration')
|
|
71
|
+
.where('id', id)
|
|
78
72
|
.update(updates);
|
|
79
73
|
return this.getById(id);
|
|
80
74
|
}
|
|
81
75
|
|
|
82
76
|
public async updateByKey(
|
|
83
77
|
key: string,
|
|
84
|
-
updates: Partial<ISystemConfiguration
|
|
78
|
+
updates: Partial<ISystemConfiguration>
|
|
85
79
|
): Promise<ISystemConfiguration | null> {
|
|
86
|
-
await this.knex<ISystemConfiguration>(
|
|
87
|
-
.where(
|
|
80
|
+
await this.knex<ISystemConfiguration>('system_configuration')
|
|
81
|
+
.where('key', key)
|
|
88
82
|
.update(updates);
|
|
89
83
|
return this.getByKey(key);
|
|
90
84
|
}
|
|
91
85
|
|
|
92
86
|
public async updateByUuid(
|
|
93
87
|
uuid: string,
|
|
94
|
-
updates: Partial<ISystemConfiguration
|
|
88
|
+
updates: Partial<ISystemConfiguration>
|
|
95
89
|
): Promise<ISystemConfiguration | null> {
|
|
96
|
-
await this.knex<ISystemConfiguration>(
|
|
97
|
-
.where(
|
|
90
|
+
await this.knex<ISystemConfiguration>('system_configuration')
|
|
91
|
+
.where('configUuid', uuid)
|
|
98
92
|
.update(updates);
|
|
99
93
|
return this.getByUuid(uuid);
|
|
100
94
|
}
|
|
101
95
|
|
|
102
96
|
public async delete(id: number): Promise<void> {
|
|
103
|
-
await this.knex<ISystemConfiguration>(
|
|
104
|
-
.where(
|
|
97
|
+
await this.knex<ISystemConfiguration>('system_configuration')
|
|
98
|
+
.where('id', id)
|
|
105
99
|
.del();
|
|
106
100
|
}
|
|
107
101
|
|
|
108
102
|
public async deleteByKey(key: string): Promise<void> {
|
|
109
|
-
await this.knex<ISystemConfiguration>(
|
|
110
|
-
.where(
|
|
103
|
+
await this.knex<ISystemConfiguration>('system_configuration')
|
|
104
|
+
.where('key', key)
|
|
111
105
|
.del();
|
|
112
106
|
}
|
|
113
107
|
|
|
114
108
|
public async deleteByUuid(uuid: string): Promise<void> {
|
|
115
|
-
await this.knex<ISystemConfiguration>(
|
|
116
|
-
.where(
|
|
109
|
+
await this.knex<ISystemConfiguration>('system_configuration')
|
|
110
|
+
.where('configUuid', uuid)
|
|
117
111
|
.del();
|
|
118
112
|
}
|
|
119
113
|
}
|
package/src/dao/user/user.dao.ts
CHANGED
|
@@ -4,56 +4,54 @@ import { IUser } from "../../interfaces/user/user.interfaces";
|
|
|
4
4
|
import KnexManager from "../../KnexConnection";
|
|
5
5
|
|
|
6
6
|
export class UserDAO implements IBaseDAO<IUser> {
|
|
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
|
-
}
|
|
7
|
+
private _knex: Knex<any, unknown[]> = KnexManager.getConnection();
|
|
8
|
+
|
|
9
|
+
async create(item: IUser): Promise<IUser> {
|
|
10
|
+
const [createdUser] = await this._knex("users").insert(item).returning("*");
|
|
11
|
+
return createdUser;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async getById(id: number): Promise<IUser | null> {
|
|
15
|
+
const user = await this._knex("users").where({ id }).first();
|
|
16
|
+
return user || null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async getByUuid(uuid: string): Promise<IUser | null> {
|
|
20
|
+
const user = await this._knex("users").where({ uuid }).first();
|
|
21
|
+
return user || null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
async getByEmail(email: string): Promise<IUser | null> {
|
|
26
|
+
const user = await this._knex("users").where({ email }).first();
|
|
27
|
+
return user || null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async update(id: number, item: Partial<IUser>): Promise<IUser | null> {
|
|
31
|
+
const [updatedUser] = await this._knex("users").where({ id }).update(item).returning("*");
|
|
32
|
+
return updatedUser || null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async delete(id: number): Promise<boolean> {
|
|
36
|
+
const result = await this._knex("users").where({ id }).del();
|
|
37
|
+
return result > 0;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async getAll(page: number, limit: number): Promise<IDataPaginator<IUser>> {
|
|
41
|
+
const offset = (page - 1) * limit;
|
|
42
|
+
|
|
43
|
+
const [countResult] = await this._knex("users").count("* as count");
|
|
44
|
+
const totalCount = +countResult.count;
|
|
45
|
+
const users = await this._knex("users").limit(limit).offset(offset);
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
success: true,
|
|
49
|
+
data: users,
|
|
50
|
+
page,
|
|
51
|
+
limit,
|
|
52
|
+
count: users.length,
|
|
53
|
+
totalCount,
|
|
54
|
+
totalPages: Math.ceil(totalCount / limit),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
59
57
|
}
|
|
@@ -4,94 +4,62 @@ import { IUserPushNotificationToken } from "../../interfaces/user-push-notificat
|
|
|
4
4
|
import KnexManager from "../../KnexConnection";
|
|
5
5
|
|
|
6
6
|
export class UserPushNotificationTokenDAO implements IBaseDAO<IUserPushNotificationToken> {
|
|
7
|
-
|
|
7
|
+
private _knex: Knex<any, unknown[]> = KnexManager.getConnection();
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
.insert(item)
|
|
14
|
-
.returning("*");
|
|
15
|
-
return createdToken;
|
|
16
|
-
}
|
|
9
|
+
async create(item: IUserPushNotificationToken): Promise<IUserPushNotificationToken> {
|
|
10
|
+
const [createdToken] = await this._knex("user_push_notification_token").insert(item).returning("*");
|
|
11
|
+
return createdToken;
|
|
12
|
+
}
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return token || null;
|
|
23
|
-
}
|
|
14
|
+
async getById(id: number): Promise<IUserPushNotificationToken | null> {
|
|
15
|
+
const token = await this._knex("user_push_notification_token").where({ id }).first();
|
|
16
|
+
return token || null;
|
|
17
|
+
}
|
|
24
18
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
);
|
|
29
|
-
}
|
|
19
|
+
async getByUuid(uuid: string): Promise<IUserPushNotificationToken | null> {
|
|
20
|
+
throw new Error("Method not implemented. UserPushNotificationToken does not have UUID field.");
|
|
21
|
+
}
|
|
30
22
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
return tokens;
|
|
36
|
-
}
|
|
23
|
+
async getByUserId(userId: number): Promise<IUserPushNotificationToken[]> {
|
|
24
|
+
const tokens = await this._knex("user_push_notification_token").where({ userId });
|
|
25
|
+
return tokens;
|
|
26
|
+
}
|
|
37
27
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return tokenRecord || null;
|
|
43
|
-
}
|
|
28
|
+
async getByToken(token: string): Promise<IUserPushNotificationToken | null> {
|
|
29
|
+
const tokenRecord = await this._knex("user_push_notification_token").where({ token }).first();
|
|
30
|
+
return tokenRecord || null;
|
|
31
|
+
}
|
|
44
32
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
userId,
|
|
50
|
-
available: true,
|
|
51
|
-
});
|
|
52
|
-
return tokens;
|
|
53
|
-
}
|
|
33
|
+
async getAvailableByUserId(userId: number): Promise<IUserPushNotificationToken[]> {
|
|
34
|
+
const tokens = await this._knex("user_push_notification_token").where({ userId, available: true });
|
|
35
|
+
return tokens;
|
|
36
|
+
}
|
|
54
37
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const [updatedToken] = await this._knex("user_push_notification_token")
|
|
60
|
-
.where({ id })
|
|
61
|
-
.update(item)
|
|
62
|
-
.returning("*");
|
|
63
|
-
return updatedToken || null;
|
|
64
|
-
}
|
|
38
|
+
async update(id: number, item: Partial<IUserPushNotificationToken>): Promise<IUserPushNotificationToken | null> {
|
|
39
|
+
const [updatedToken] = await this._knex("user_push_notification_token").where({ id }).update(item).returning("*");
|
|
40
|
+
return updatedToken || null;
|
|
41
|
+
}
|
|
65
42
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return result > 0;
|
|
71
|
-
}
|
|
43
|
+
async delete(id: number): Promise<boolean> {
|
|
44
|
+
const result = await this._knex("user_push_notification_token").where({ id }).del();
|
|
45
|
+
return result > 0;
|
|
46
|
+
}
|
|
72
47
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
limit: number,
|
|
76
|
-
): Promise<IDataPaginator<IUserPushNotificationToken>> {
|
|
77
|
-
const offset = (page - 1) * limit;
|
|
48
|
+
async getAll(page: number, limit: number): Promise<IDataPaginator<IUserPushNotificationToken>> {
|
|
49
|
+
const offset = (page - 1) * limit;
|
|
78
50
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const totalCount = +countResult.count;
|
|
83
|
-
const tokens = await this._knex("user_push_notification_token")
|
|
84
|
-
.limit(limit)
|
|
85
|
-
.offset(offset);
|
|
51
|
+
const [countResult] = await this._knex("user_push_notification_token").count("* as count");
|
|
52
|
+
const totalCount = +countResult.count;
|
|
53
|
+
const tokens = await this._knex("user_push_notification_token").limit(limit).offset(offset);
|
|
86
54
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
55
|
+
return {
|
|
56
|
+
success: true,
|
|
57
|
+
data: tokens,
|
|
58
|
+
page,
|
|
59
|
+
limit,
|
|
60
|
+
count: tokens.length,
|
|
61
|
+
totalCount,
|
|
62
|
+
totalPages: Math.ceil(totalCount / limit),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|