@trafficgroup/knex-rel 0.1.17 → 0.1.19

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 (128) hide show
  1. package/.claude/settings.local.json +5 -2
  2. package/CLAUDE.md +2 -11
  3. package/dist/constants/folder.constants.d.ts +2 -2
  4. package/dist/constants/folder.constants.js +6 -15
  5. package/dist/constants/folder.constants.js.map +1 -1
  6. package/dist/constants/study.constants.d.ts +10 -0
  7. package/dist/constants/study.constants.js +18 -0
  8. package/dist/constants/study.constants.js.map +1 -0
  9. package/dist/constants/video.constants.d.ts +2 -2
  10. package/dist/constants/video.constants.js +5 -9
  11. package/dist/constants/video.constants.js.map +1 -1
  12. package/dist/dao/VideoMinuteResultDAO.d.ts +1 -1
  13. package/dist/dao/VideoMinuteResultDAO.js +23 -29
  14. package/dist/dao/VideoMinuteResultDAO.js.map +1 -1
  15. package/dist/dao/auth/auth.dao.js +1 -4
  16. package/dist/dao/auth/auth.dao.js.map +1 -1
  17. package/dist/dao/batch/batch.dao.js +14 -13
  18. package/dist/dao/batch/batch.dao.js.map +1 -1
  19. package/dist/dao/camera/camera.dao.js +7 -10
  20. package/dist/dao/camera/camera.dao.js.map +1 -1
  21. package/dist/dao/chat/chat.dao.d.ts +1 -1
  22. package/dist/dao/chat/chat.dao.js +40 -27
  23. package/dist/dao/chat/chat.dao.js.map +1 -1
  24. package/dist/dao/folder/folder.dao.js +7 -18
  25. package/dist/dao/folder/folder.dao.js.map +1 -1
  26. package/dist/dao/location/location.dao.js +9 -16
  27. package/dist/dao/location/location.dao.js.map +1 -1
  28. package/dist/dao/message/message.dao.d.ts +1 -1
  29. package/dist/dao/message/message.dao.js +26 -18
  30. package/dist/dao/message/message.dao.js.map +1 -1
  31. package/dist/dao/reconciliation-log/reconciliation-log.dao.d.ts +6 -0
  32. package/dist/dao/reconciliation-log/reconciliation-log.dao.js +39 -0
  33. package/dist/dao/reconciliation-log/reconciliation-log.dao.js.map +1 -0
  34. package/dist/dao/report-configuration/report-configuration.dao.js +31 -32
  35. package/dist/dao/report-configuration/report-configuration.dao.js.map +1 -1
  36. package/dist/dao/study/study.dao.d.ts +8 -1
  37. package/dist/dao/study/study.dao.js +20 -11
  38. package/dist/dao/study/study.dao.js.map +1 -1
  39. package/dist/dao/systemConfiguration/SystemConfigurationDAO.d.ts +2 -2
  40. package/dist/dao/systemConfiguration/SystemConfigurationDAO.js +26 -26
  41. package/dist/dao/systemConfiguration/SystemConfigurationDAO.js.map +1 -1
  42. package/dist/dao/user/user.dao.js +1 -4
  43. package/dist/dao/user/user.dao.js.map +1 -1
  44. package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js +8 -26
  45. package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js.map +1 -1
  46. package/dist/dao/video/video.dao.js +28 -30
  47. package/dist/dao/video/video.dao.js.map +1 -1
  48. package/dist/index.d.ts +12 -7
  49. package/dist/index.js +6 -1
  50. package/dist/index.js.map +1 -1
  51. package/dist/interfaces/batch/batch.interfaces.d.ts +1 -1
  52. package/dist/interfaces/camera/camera.interfaces.d.ts +1 -1
  53. package/dist/interfaces/chat/chat.interfaces.d.ts +3 -3
  54. package/dist/interfaces/folder/folder.interfaces.d.ts +1 -1
  55. package/dist/interfaces/message/message.interfaces.d.ts +2 -2
  56. package/dist/interfaces/reconciliation-log/reconciliation-log.interfaces.d.ts +15 -0
  57. package/dist/interfaces/reconciliation-log/reconciliation-log.interfaces.js +3 -0
  58. package/dist/interfaces/reconciliation-log/reconciliation-log.interfaces.js.map +1 -0
  59. package/dist/interfaces/study/study.interfaces.d.ts +2 -2
  60. package/dist/interfaces/user/user.interfaces.d.ts +1 -1
  61. package/dist/interfaces/user-push-notification-token/user-push-notification-token.interfaces.d.ts +1 -1
  62. package/dist/interfaces/video/video.interfaces.d.ts +2 -2
  63. package/migrations/20250717160737_migration.ts +1 -1
  64. package/migrations/20250717160908_migration.ts +2 -5
  65. package/migrations/20250717161310_migration.ts +1 -1
  66. package/migrations/20250717161406_migration.ts +3 -3
  67. package/migrations/20250717162431_migration.ts +1 -1
  68. package/migrations/20250717173228_migration.ts +2 -2
  69. package/migrations/20250717204731_migration.ts +1 -1
  70. package/migrations/20250722210109_migration.ts +4 -8
  71. package/migrations/20250722211019_migration.ts +1 -1
  72. package/migrations/20250723153852_migration.ts +10 -13
  73. package/migrations/20250723162257_migration.ts +7 -4
  74. package/migrations/20250723171109_migration.ts +7 -4
  75. package/migrations/20250723205331_migration.ts +9 -6
  76. package/migrations/20250724191345_migration.ts +11 -8
  77. package/migrations/20250730180932_migration.ts +13 -14
  78. package/migrations/20250730213625_migration.ts +11 -8
  79. package/migrations/20250804124509_migration.ts +21 -26
  80. package/migrations/20250804132053_migration.ts +8 -5
  81. package/migrations/20250804164518_migration.ts +7 -7
  82. package/migrations/20250823223016_migration.ts +21 -32
  83. package/migrations/20250910015452_migration.ts +6 -18
  84. package/migrations/20250911000000_migration.ts +4 -18
  85. package/migrations/20250917144153_migration.ts +7 -14
  86. package/migrations/20250930200521_migration.ts +4 -8
  87. package/migrations/20251010143500_migration.ts +6 -27
  88. package/migrations/20251020225758_migration.ts +15 -51
  89. package/migrations/20251112120000_migration.ts +2 -10
  90. package/migrations/20251112120200_migration.ts +7 -19
  91. package/migrations/20251112120300_migration.ts +2 -7
  92. package/migrations/20260109140000_migration.ts +2 -7
  93. package/migrations/20260209140000_migration.ts +27 -0
  94. package/package.json +1 -1
  95. package/src/constants/folder.constants.ts +8 -17
  96. package/src/constants/study.constants.ts +17 -0
  97. package/src/constants/video.constants.ts +7 -11
  98. package/src/d.types.ts +14 -18
  99. package/src/dao/VideoMinuteResultDAO.ts +52 -83
  100. package/src/dao/auth/auth.dao.ts +55 -58
  101. package/src/dao/batch/batch.dao.ts +98 -101
  102. package/src/dao/camera/camera.dao.ts +121 -124
  103. package/src/dao/chat/chat.dao.ts +45 -45
  104. package/src/dao/folder/folder.dao.ts +90 -105
  105. package/src/dao/location/location.dao.ts +87 -109
  106. package/src/dao/message/message.dao.ts +32 -32
  107. package/src/dao/reconciliation-log/reconciliation-log.dao.ts +26 -0
  108. package/src/dao/report-configuration/report-configuration.dao.ts +342 -370
  109. package/src/dao/study/study.dao.ts +84 -88
  110. package/src/dao/systemConfiguration/SystemConfigurationDAO.ts +35 -41
  111. package/src/dao/user/user.dao.ts +50 -52
  112. package/src/dao/user-push-notification-token/user-push-notification-token.dao.ts +48 -80
  113. package/src/dao/video/video.dao.ts +345 -396
  114. package/src/entities/BaseEntity.ts +1 -1
  115. package/src/index.ts +31 -37
  116. package/src/interfaces/auth/auth.interfaces.ts +10 -10
  117. package/src/interfaces/batch/batch.interfaces.ts +1 -1
  118. package/src/interfaces/camera/camera.interfaces.ts +9 -9
  119. package/src/interfaces/chat/chat.interfaces.ts +4 -4
  120. package/src/interfaces/folder/folder.interfaces.ts +2 -2
  121. package/src/interfaces/location/location.interfaces.ts +7 -7
  122. package/src/interfaces/message/message.interfaces.ts +3 -3
  123. package/src/interfaces/reconciliation-log/reconciliation-log.interfaces.ts +15 -0
  124. package/src/interfaces/report-configuration/report-configuration.interfaces.ts +16 -16
  125. package/src/interfaces/study/study.interfaces.ts +3 -3
  126. package/src/interfaces/user/user.interfaces.ts +9 -9
  127. package/src/interfaces/user-push-notification-token/user-push-notification-token.interfaces.ts +9 -9
  128. package/src/interfaces/video/video.interfaces.ts +34 -34
@@ -2,105 +2,101 @@ 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
+ }
5
13
 
6
14
  export class StudyDAO implements IBaseDAO<IStudy> {
7
- private _knex: Knex<any, unknown[]> = KnexManager.getConnection();
15
+ private _knex: Knex<any, unknown[]> = KnexManager.getConnection();
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
+ }
8
31
 
9
- async create(item: IStudy): Promise<IStudy> {
10
- const [createdStudy] = await this._knex("study")
11
- .insert(item)
12
- .returning("*");
13
- return createdStudy;
14
- }
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
+ }
15
41
 
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
- }
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
+ }
29
46
 
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
- }
47
+ async delete(id: number): Promise<boolean> {
48
+ const result = await this._knex("study").where({ id }).del();
49
+ return result > 0;
50
+ }
43
51
 
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
- }
52
+ async getAll(page: number, limit: number, filters?: IStudyFilters): Promise<IDataPaginator<IStudy>> {
53
+ const offset = (page - 1) * limit;
51
54
 
52
- async delete(id: number): Promise<boolean> {
53
- const result = await this._knex("study").where({ id }).del();
54
- return result > 0;
55
- }
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"));
56
59
 
57
- async getAll(
58
- page: number,
59
- limit: number,
60
- createdBy?: number | null,
61
- ): Promise<IDataPaginator<IStudy>> {
62
- const offset = (page - 1) * limit;
60
+ if (filters) {
61
+ if (filters.createdBy !== undefined && filters.createdBy !== null) {
62
+ query.where("s.createdBy", filters.createdBy);
63
+ }
63
64
 
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
- }
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
+ }
75
75
 
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);
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);
79
79
 
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
- }
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
- 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);
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);
103
99
 
104
- return studies;
105
- }
100
+ return studies;
101
+ }
106
102
  }
@@ -1,14 +1,12 @@
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";
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>("system_configuration")
31
- .where("id", id)
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>("system_configuration")
38
- .where("configUuid", uuid)
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>("system_configuration")
45
- .where("key", key)
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>("system_configuration")
58
- .whereIn("key", keys)
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>("system_configuration")
64
- .select("*")
65
- .orderBy("key", "asc");
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>("system_configuration")
77
- .where("id", id)
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>("system_configuration")
87
- .where("key", key)
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>("system_configuration")
97
- .where("configUuid", uuid)
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>("system_configuration")
104
- .where("id", id)
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>("system_configuration")
110
- .where("key", key)
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>("system_configuration")
116
- .where("configUuid", uuid)
109
+ await this.knex<ISystemConfiguration>('system_configuration')
110
+ .where('configUuid', uuid)
117
111
  .del();
118
112
  }
119
113
  }
@@ -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
  }
@@ -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
- private _knex: Knex<any, unknown[]> = KnexManager.getConnection();
7
+ private _knex: Knex<any, unknown[]> = KnexManager.getConnection();
8
8
 
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
- }
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
- 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
- }
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
- async getByUuid(uuid: string): Promise<IUserPushNotificationToken | null> {
26
- throw new Error(
27
- "Method not implemented. UserPushNotificationToken does not have UUID field.",
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
- async getByUserId(userId: number): Promise<IUserPushNotificationToken[]> {
32
- const tokens = await this._knex("user_push_notification_token").where({
33
- userId,
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- async getAll(
74
- page: number,
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
- 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);
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
- 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
- }
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
+ }