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