@trafficgroup/knex-rel 0.1.9 → 0.1.10

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