@trafficgroup/knex-rel 0.1.11 → 0.1.12

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 (110) hide show
  1. package/.claude/settings.local.json +2 -5
  2. package/CLAUDE.md +11 -2
  3. package/dist/constants/folder.constants.d.ts +12 -0
  4. package/dist/constants/folder.constants.js +28 -0
  5. package/dist/constants/folder.constants.js.map +1 -0
  6. package/dist/constants/video.constants.d.ts +2 -2
  7. package/dist/constants/video.constants.js +9 -5
  8. package/dist/constants/video.constants.js.map +1 -1
  9. package/dist/dao/VideoMinuteResultDAO.d.ts +1 -1
  10. package/dist/dao/VideoMinuteResultDAO.js +29 -23
  11. package/dist/dao/VideoMinuteResultDAO.js.map +1 -1
  12. package/dist/dao/auth/auth.dao.js +4 -1
  13. package/dist/dao/auth/auth.dao.js.map +1 -1
  14. package/dist/dao/batch/batch.dao.js +13 -14
  15. package/dist/dao/batch/batch.dao.js.map +1 -1
  16. package/dist/dao/camera/camera.dao.js +10 -7
  17. package/dist/dao/camera/camera.dao.js.map +1 -1
  18. package/dist/dao/chat/chat.dao.d.ts +1 -1
  19. package/dist/dao/chat/chat.dao.js +27 -40
  20. package/dist/dao/chat/chat.dao.js.map +1 -1
  21. package/dist/dao/folder/folder.dao.d.ts +10 -1
  22. package/dist/dao/folder/folder.dao.js +44 -6
  23. package/dist/dao/folder/folder.dao.js.map +1 -1
  24. package/dist/dao/location/location.dao.js +16 -9
  25. package/dist/dao/location/location.dao.js.map +1 -1
  26. package/dist/dao/message/message.dao.d.ts +1 -1
  27. package/dist/dao/message/message.dao.js +18 -26
  28. package/dist/dao/message/message.dao.js.map +1 -1
  29. package/dist/dao/report-configuration/report-configuration.dao.js +32 -31
  30. package/dist/dao/report-configuration/report-configuration.dao.js.map +1 -1
  31. package/dist/dao/study/study.dao.js +7 -2
  32. package/dist/dao/study/study.dao.js.map +1 -1
  33. package/dist/dao/user/user.dao.js +4 -1
  34. package/dist/dao/user/user.dao.js.map +1 -1
  35. package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js +26 -8
  36. package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js.map +1 -1
  37. package/dist/dao/video/video.dao.js +30 -28
  38. package/dist/dao/video/video.dao.js.map +1 -1
  39. package/dist/index.d.ts +8 -5
  40. package/dist/index.js +5 -1
  41. package/dist/index.js.map +1 -1
  42. package/dist/interfaces/batch/batch.interfaces.d.ts +1 -1
  43. package/dist/interfaces/camera/camera.interfaces.d.ts +1 -1
  44. package/dist/interfaces/chat/chat.interfaces.d.ts +3 -3
  45. package/dist/interfaces/folder/folder.interfaces.d.ts +1 -1
  46. package/dist/interfaces/message/message.interfaces.d.ts +2 -2
  47. package/dist/interfaces/study/study.interfaces.d.ts +2 -2
  48. package/dist/interfaces/user/user.interfaces.d.ts +1 -1
  49. package/dist/interfaces/user-push-notification-token/user-push-notification-token.interfaces.d.ts +1 -1
  50. package/dist/interfaces/video/video.interfaces.d.ts +2 -2
  51. package/migrations/20250717160737_migration.ts +1 -1
  52. package/migrations/20250717160908_migration.ts +5 -2
  53. package/migrations/20250717161310_migration.ts +1 -1
  54. package/migrations/20250717161406_migration.ts +3 -3
  55. package/migrations/20250717162431_migration.ts +1 -1
  56. package/migrations/20250717173228_migration.ts +2 -2
  57. package/migrations/20250717204731_migration.ts +1 -1
  58. package/migrations/20250722210109_migration.ts +8 -4
  59. package/migrations/20250722211019_migration.ts +1 -1
  60. package/migrations/20250723153852_migration.ts +13 -10
  61. package/migrations/20250723162257_migration.ts +4 -7
  62. package/migrations/20250723171109_migration.ts +4 -7
  63. package/migrations/20250723205331_migration.ts +6 -9
  64. package/migrations/20250724191345_migration.ts +8 -11
  65. package/migrations/20250730180932_migration.ts +14 -13
  66. package/migrations/20250730213625_migration.ts +8 -11
  67. package/migrations/20250804124509_migration.ts +26 -21
  68. package/migrations/20250804132053_migration.ts +5 -8
  69. package/migrations/20250804164518_migration.ts +7 -7
  70. package/migrations/20250823223016_migration.ts +32 -21
  71. package/migrations/20250910015452_migration.ts +18 -6
  72. package/migrations/20250911000000_migration.ts +18 -4
  73. package/migrations/20250917144153_migration.ts +14 -7
  74. package/migrations/20250930200521_migration.ts +8 -4
  75. package/migrations/20251010143500_migration.ts +27 -6
  76. package/migrations/20251020225758_migration.ts +51 -15
  77. package/migrations/20251112120000_migration.ts +10 -2
  78. package/migrations/20251112120200_migration.ts +19 -7
  79. package/migrations/20251112120300_migration.ts +7 -2
  80. package/package.json +1 -1
  81. package/src/constants/folder.constants.ts +29 -0
  82. package/src/constants/video.constants.ts +11 -7
  83. package/src/d.types.ts +18 -14
  84. package/src/dao/VideoMinuteResultDAO.ts +72 -49
  85. package/src/dao/auth/auth.dao.ts +58 -55
  86. package/src/dao/batch/batch.dao.ts +101 -98
  87. package/src/dao/camera/camera.dao.ts +124 -121
  88. package/src/dao/chat/chat.dao.ts +45 -45
  89. package/src/dao/folder/folder.dao.ts +112 -55
  90. package/src/dao/location/location.dao.ts +109 -87
  91. package/src/dao/message/message.dao.ts +32 -32
  92. package/src/dao/report-configuration/report-configuration.dao.ts +370 -342
  93. package/src/dao/study/study.dao.ts +88 -63
  94. package/src/dao/user/user.dao.ts +52 -50
  95. package/src/dao/user-push-notification-token/user-push-notification-token.dao.ts +80 -48
  96. package/src/dao/video/video.dao.ts +385 -334
  97. package/src/entities/BaseEntity.ts +1 -1
  98. package/src/index.ts +42 -17
  99. package/src/interfaces/auth/auth.interfaces.ts +10 -10
  100. package/src/interfaces/batch/batch.interfaces.ts +1 -1
  101. package/src/interfaces/camera/camera.interfaces.ts +9 -9
  102. package/src/interfaces/chat/chat.interfaces.ts +4 -4
  103. package/src/interfaces/folder/folder.interfaces.ts +2 -2
  104. package/src/interfaces/location/location.interfaces.ts +7 -7
  105. package/src/interfaces/message/message.interfaces.ts +3 -3
  106. package/src/interfaces/report-configuration/report-configuration.interfaces.ts +16 -16
  107. package/src/interfaces/study/study.interfaces.ts +3 -3
  108. package/src/interfaces/user/user.interfaces.ts +9 -9
  109. package/src/interfaces/user-push-notification-token/user-push-notification-token.interfaces.ts +9 -9
  110. package/src/interfaces/video/video.interfaces.ts +34 -34
@@ -5,97 +5,119 @@ import { IVideo } from "../../interfaces/video/video.interfaces";
5
5
  import KnexManager from "../../KnexConnection";
6
6
 
7
7
  export class LocationDAO implements IBaseDAO<ILocation> {
8
- private _knex: Knex<any, unknown[]> = KnexManager.getConnection();
9
-
10
- async create(item: ILocation): Promise<ILocation> {
11
- const [createdLocation] = await this._knex("locations").insert(item).returning("*");
12
- return createdLocation;
13
- }
14
-
15
- async getById(id: number): Promise<ILocation | null> {
16
- const location = await this._knex("locations").where({ id }).first();
17
- return location || null;
18
- }
19
-
20
- async getByUuid(uuid: string): Promise<ILocation | null> {
21
- const location = await this._knex("locations").where({ uuid }).first();
22
- return location || null;
23
- }
24
-
25
- async update(id: number, item: Partial<ILocation>): Promise<ILocation | null> {
26
- const [updatedLocation] = await this._knex("locations").where({ id }).update(item).returning("*");
27
- return updatedLocation || null;
28
- }
29
-
30
- async delete(id: number): Promise<boolean> {
31
- const result = await this._knex("locations").where({ id }).del();
32
- return result > 0;
33
- }
34
-
35
- async getAll(page: number, limit: number): Promise<IDataPaginator<ILocation>> {
36
- const offset = (page - 1) * limit;
37
-
38
- const [countResult] = await this._knex("locations").count("* as count");
39
- const totalCount = +countResult.count;
40
- const locations = await this._knex("locations").limit(limit).offset(offset);
41
-
42
- return {
43
- success: true,
44
- data: locations,
45
- page,
46
- limit,
47
- count: locations.length,
48
- totalCount,
49
- totalPages: Math.ceil(totalCount / limit),
50
- };
51
- }
52
-
53
- async getByName(name: string): Promise<ILocation | null> {
54
- const location = await this._knex("locations").where({ name }).first();
55
- return location || null;
56
- }
57
-
58
- async getLocationsNearCoordinates(longitude: number, latitude: number, radiusKm: number = 1): Promise<ILocation[]> {
59
- // Using ST_DWithin for geographic distance calculation
60
- // This is a PostgreSQL-specific query for geospatial operations
61
- const locations = await this._knex("locations")
62
- .whereRaw(
63
- `ST_DWithin(
8
+ private _knex: Knex<any, unknown[]> = KnexManager.getConnection();
9
+
10
+ async create(item: ILocation): Promise<ILocation> {
11
+ const [createdLocation] = await this._knex("locations")
12
+ .insert(item)
13
+ .returning("*");
14
+ return createdLocation;
15
+ }
16
+
17
+ async getById(id: number): Promise<ILocation | null> {
18
+ const location = await this._knex("locations").where({ id }).first();
19
+ return location || null;
20
+ }
21
+
22
+ async getByUuid(uuid: string): Promise<ILocation | null> {
23
+ const location = await this._knex("locations").where({ uuid }).first();
24
+ return location || null;
25
+ }
26
+
27
+ async update(
28
+ id: number,
29
+ item: Partial<ILocation>,
30
+ ): Promise<ILocation | null> {
31
+ const [updatedLocation] = await this._knex("locations")
32
+ .where({ id })
33
+ .update(item)
34
+ .returning("*");
35
+ return updatedLocation || null;
36
+ }
37
+
38
+ async delete(id: number): Promise<boolean> {
39
+ const result = await this._knex("locations").where({ id }).del();
40
+ return result > 0;
41
+ }
42
+
43
+ async getAll(
44
+ page: number,
45
+ limit: number,
46
+ ): Promise<IDataPaginator<ILocation>> {
47
+ const offset = (page - 1) * limit;
48
+
49
+ const [countResult] = await this._knex("locations").count("* as count");
50
+ const totalCount = +countResult.count;
51
+ const locations = await this._knex("locations").limit(limit).offset(offset);
52
+
53
+ return {
54
+ success: true,
55
+ data: locations,
56
+ page,
57
+ limit,
58
+ count: locations.length,
59
+ totalCount,
60
+ totalPages: Math.ceil(totalCount / limit),
61
+ };
62
+ }
63
+
64
+ async getByName(name: string): Promise<ILocation | null> {
65
+ const location = await this._knex("locations").where({ name }).first();
66
+ return location || null;
67
+ }
68
+
69
+ async getLocationsNearCoordinates(
70
+ longitude: number,
71
+ latitude: number,
72
+ radiusKm: number = 1,
73
+ ): Promise<ILocation[]> {
74
+ // Using ST_DWithin for geographic distance calculation
75
+ // This is a PostgreSQL-specific query for geospatial operations
76
+ const locations = await this._knex("locations").whereRaw(
77
+ `ST_DWithin(
64
78
  ST_MakePoint(longitude, latitude)::geography,
65
79
  ST_MakePoint(?, ?)::geography,
66
80
  ?
67
81
  )`,
68
- [longitude, latitude, radiusKm * 1000] // Convert km to meters
69
- );
70
- return locations;
82
+ [longitude, latitude, radiusKm * 1000], // Convert km to meters
83
+ );
84
+ return locations;
85
+ }
86
+
87
+ /**
88
+ * Get all locations with optional search filter by name (case-insensitive partial match)
89
+ */
90
+ async getAllWithSearch(
91
+ page: number,
92
+ limit: number,
93
+ name?: string,
94
+ ): Promise<IDataPaginator<ILocation>> {
95
+ const offset = (page - 1) * limit;
96
+
97
+ let query = this._knex("locations");
98
+
99
+ // Apply search filter if name provided (escape special chars to prevent pattern injection)
100
+ if (name && name.trim().length > 0) {
101
+ const escapedName = name.trim().replace(/[%_\\]/g, "\\$&");
102
+ query = query.where("name", "ilike", `%${escapedName}%`);
71
103
  }
72
104
 
73
- /**
74
- * Get all locations with optional search filter by name (case-insensitive partial match)
75
- */
76
- async getAllWithSearch(page: number, limit: number, name?: string): Promise<IDataPaginator<ILocation>> {
77
- const offset = (page - 1) * limit;
78
-
79
- let query = this._knex("locations");
80
-
81
- // Apply search filter if name provided (escape special chars to prevent pattern injection)
82
- if (name && name.trim().length > 0) {
83
- const escapedName = name.trim().replace(/[%_\\]/g, '\\$&');
84
- query = query.where('name', 'ilike', `%${escapedName}%`);
85
- }
86
-
87
- const [countResult] = await query.clone().count("* as count");
88
- const totalCount = +countResult.count;
89
- const locations = await query.clone().limit(limit).offset(offset).orderBy('name', 'asc');
90
-
91
- return {
92
- success: true,
93
- data: locations,
94
- page,
95
- limit,
96
- count: locations.length,
97
- totalCount,
98
- totalPages: Math.ceil(totalCount / limit),
99
- };
100
- }
105
+ const [countResult] = await query.clone().count("* as count");
106
+ const totalCount = +countResult.count;
107
+ const locations = await query
108
+ .clone()
109
+ .limit(limit)
110
+ .offset(offset)
111
+ .orderBy("name", "asc");
112
+
113
+ return {
114
+ success: true,
115
+ data: locations,
116
+ page,
117
+ limit,
118
+ count: locations.length,
119
+ totalCount,
120
+ totalPages: Math.ceil(totalCount / limit),
121
+ };
122
+ }
101
123
  }
@@ -1,22 +1,22 @@
1
1
  import { Knex } from "knex";
2
2
  import { IBaseDAO, IDataPaginator } from "../../d.types";
3
- import { IMessage, IMessageCreate, IMessageUpdate } from '../../interfaces/message/message.interfaces';
3
+ import {
4
+ IMessage,
5
+ IMessageCreate,
6
+ IMessageUpdate,
7
+ } from "../../interfaces/message/message.interfaces";
4
8
  import KnexManager from "../../KnexConnection";
5
9
 
6
10
  export class MessageDAO implements IBaseDAO<IMessage> {
7
11
  private _knex: Knex<any, unknown[]> = KnexManager.getConnection();
8
12
 
9
13
  async create(item: IMessageCreate): Promise<IMessage> {
10
- const [result] = await this._knex('message')
11
- .insert(item)
12
- .returning('*');
14
+ const [result] = await this._knex("message").insert(item).returning("*");
13
15
  return result;
14
16
  }
15
17
 
16
18
  async getById(id: number): Promise<IMessage | null> {
17
- const result = await this._knex('message')
18
- .where('id', id)
19
- .first();
19
+ const result = await this._knex("message").where("id", id).first();
20
20
  return result || null;
21
21
  }
22
22
 
@@ -27,13 +27,13 @@ export class MessageDAO implements IBaseDAO<IMessage> {
27
27
 
28
28
  async getAll(page = 1, limit = 10): Promise<IDataPaginator<IMessage>> {
29
29
  const offset = (page - 1) * limit;
30
-
30
+
31
31
  const [results, [{ count }]] = await Promise.all([
32
- this._knex('message')
33
- .orderBy('created_at', 'asc')
32
+ this._knex("message")
33
+ .orderBy("created_at", "asc")
34
34
  .limit(limit)
35
35
  .offset(offset),
36
- this._knex('message').count('* as count')
36
+ this._knex("message").count("* as count"),
37
37
  ]);
38
38
 
39
39
  const totalCount = parseInt(count as string);
@@ -44,40 +44,40 @@ export class MessageDAO implements IBaseDAO<IMessage> {
44
44
  limit,
45
45
  count: results.length,
46
46
  totalCount,
47
- totalPages: Math.ceil(totalCount / limit)
47
+ totalPages: Math.ceil(totalCount / limit),
48
48
  };
49
49
  }
50
50
 
51
51
  async update(id: number, item: IMessageUpdate): Promise<IMessage | null> {
52
- const [result] = await this._knex('message')
53
- .where('id', id)
52
+ const [result] = await this._knex("message")
53
+ .where("id", id)
54
54
  .update({
55
55
  ...item,
56
- updated_at: new Date()
56
+ updated_at: new Date(),
57
57
  })
58
- .returning('*');
58
+ .returning("*");
59
59
  return result || null;
60
60
  }
61
61
 
62
62
  async delete(id: number): Promise<boolean> {
63
- const result = await this._knex('message')
64
- .where('id', id)
65
- .delete();
63
+ const result = await this._knex("message").where("id", id).delete();
66
64
  return result > 0;
67
65
  }
68
66
 
69
- async getByChatId(chatId: number, page = 1, limit = 50): Promise<IDataPaginator<IMessage>> {
67
+ async getByChatId(
68
+ chatId: number,
69
+ page = 1,
70
+ limit = 50,
71
+ ): Promise<IDataPaginator<IMessage>> {
70
72
  const offset = (page - 1) * limit;
71
-
73
+
72
74
  const [results, [{ count }]] = await Promise.all([
73
- this._knex('message')
74
- .where('chatId', chatId)
75
- .orderBy('created_at', 'asc')
75
+ this._knex("message")
76
+ .where("chatId", chatId)
77
+ .orderBy("created_at", "asc")
76
78
  .limit(limit)
77
79
  .offset(offset),
78
- this._knex('message')
79
- .where('chatId', chatId)
80
- .count('* as count')
80
+ this._knex("message").where("chatId", chatId).count("* as count"),
81
81
  ]);
82
82
 
83
83
  const totalCount = parseInt(count as string);
@@ -88,15 +88,15 @@ export class MessageDAO implements IBaseDAO<IMessage> {
88
88
  limit,
89
89
  count: results.length,
90
90
  totalCount,
91
- totalPages: Math.ceil(totalCount / limit)
91
+ totalPages: Math.ceil(totalCount / limit),
92
92
  };
93
93
  }
94
94
 
95
95
  async getLatestMessages(chatId: number, limit = 50): Promise<IMessage[]> {
96
- return await this._knex('message')
97
- .where('chatId', chatId)
98
- .orderBy('created_at', 'desc')
96
+ return await this._knex("message")
97
+ .where("chatId", chatId)
98
+ .orderBy("created_at", "desc")
99
99
  .limit(limit)
100
100
  .then((messages: IMessage[]) => messages.reverse());
101
101
  }
102
- }
102
+ }