@trafficgroup/knex-rel 0.1.21 → 0.1.23-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) 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 +1 -1
  7. package/dist/constants/study.constants.js +1 -1
  8. package/dist/constants/video.constants.d.ts +2 -2
  9. package/dist/constants/video.constants.js +5 -9
  10. package/dist/constants/video.constants.js.map +1 -1
  11. package/dist/dao/VideoMinuteResultDAO.d.ts +19 -2
  12. package/dist/dao/VideoMinuteResultDAO.js +75 -29
  13. package/dist/dao/VideoMinuteResultDAO.js.map +1 -1
  14. package/dist/dao/auth/auth.dao.js +1 -4
  15. package/dist/dao/auth/auth.dao.js.map +1 -1
  16. package/dist/dao/batch/batch.dao.d.ts +0 -10
  17. package/dist/dao/batch/batch.dao.js +14 -51
  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/report-configuration/report-configuration.dao.js +68 -39
  32. package/dist/dao/report-configuration/report-configuration.dao.js.map +1 -1
  33. package/dist/dao/study/study.dao.d.ts +8 -1
  34. package/dist/dao/study/study.dao.js +20 -15
  35. package/dist/dao/study/study.dao.js.map +1 -1
  36. package/dist/dao/systemConfiguration/SystemConfigurationDAO.d.ts +2 -2
  37. package/dist/dao/systemConfiguration/SystemConfigurationDAO.js +26 -26
  38. package/dist/dao/systemConfiguration/SystemConfigurationDAO.js.map +1 -1
  39. package/dist/dao/user/user.dao.js +1 -4
  40. package/dist/dao/user/user.dao.js.map +1 -1
  41. package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js +8 -26
  42. package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js.map +1 -1
  43. package/dist/dao/video/video.dao.js +28 -30
  44. package/dist/dao/video/video.dao.js.map +1 -1
  45. package/dist/index.d.ts +10 -9
  46. package/dist/index.js +4 -4
  47. package/dist/index.js.map +1 -1
  48. package/dist/interfaces/batch/batch.interfaces.d.ts +1 -1
  49. package/dist/interfaces/camera/camera.interfaces.d.ts +1 -1
  50. package/dist/interfaces/chat/chat.interfaces.d.ts +3 -3
  51. package/dist/interfaces/folder/folder.interfaces.d.ts +1 -1
  52. package/dist/interfaces/message/message.interfaces.d.ts +2 -2
  53. package/dist/interfaces/report-configuration/report-configuration.interfaces.d.ts +1 -0
  54. package/dist/interfaces/study/study.interfaces.d.ts +2 -8
  55. package/dist/interfaces/user/user.interfaces.d.ts +1 -1
  56. package/dist/interfaces/user-push-notification-token/user-push-notification-token.interfaces.d.ts +1 -1
  57. package/dist/interfaces/video/video.interfaces.d.ts +2 -2
  58. package/migrations/20250717160737_migration.ts +1 -1
  59. package/migrations/20250717160908_migration.ts +2 -5
  60. package/migrations/20250717161310_migration.ts +1 -1
  61. package/migrations/20250717161406_migration.ts +3 -3
  62. package/migrations/20250717162431_migration.ts +1 -1
  63. package/migrations/20250717173228_migration.ts +2 -2
  64. package/migrations/20250717204731_migration.ts +1 -1
  65. package/migrations/20250722210109_migration.ts +4 -8
  66. package/migrations/20250722211019_migration.ts +1 -1
  67. package/migrations/20250723153852_migration.ts +10 -13
  68. package/migrations/20250723162257_migration.ts +7 -4
  69. package/migrations/20250723171109_migration.ts +7 -4
  70. package/migrations/20250723205331_migration.ts +9 -6
  71. package/migrations/20250724191345_migration.ts +11 -8
  72. package/migrations/20250730180932_migration.ts +13 -14
  73. package/migrations/20250730213625_migration.ts +11 -8
  74. package/migrations/20250804124509_migration.ts +21 -26
  75. package/migrations/20250804132053_migration.ts +8 -5
  76. package/migrations/20250804164518_migration.ts +7 -7
  77. package/migrations/20250823223016_migration.ts +21 -32
  78. package/migrations/20250910015452_migration.ts +6 -18
  79. package/migrations/20250911000000_migration.ts +4 -18
  80. package/migrations/20250917144153_migration.ts +7 -14
  81. package/migrations/20250930200521_migration.ts +4 -8
  82. package/migrations/20251010143500_migration.ts +6 -27
  83. package/migrations/20251020225758_migration.ts +15 -51
  84. package/migrations/20251112120000_migration.ts +2 -10
  85. package/migrations/20251112120200_migration.ts +7 -19
  86. package/migrations/20251112120300_migration.ts +2 -7
  87. package/migrations/20260109140000_migration.ts +2 -7
  88. package/package.json +3 -3
  89. package/src/constants/folder.constants.ts +8 -17
  90. package/src/constants/study.constants.ts +1 -1
  91. package/src/constants/video.constants.ts +7 -11
  92. package/src/d.types.ts +14 -18
  93. package/src/dao/VideoMinuteResultDAO.ts +127 -83
  94. package/src/dao/auth/auth.dao.ts +55 -58
  95. package/src/dao/batch/batch.dao.ts +100 -145
  96. package/src/dao/camera/camera.dao.ts +121 -124
  97. package/src/dao/chat/chat.dao.ts +45 -45
  98. package/src/dao/folder/folder.dao.ts +90 -105
  99. package/src/dao/location/location.dao.ts +87 -109
  100. package/src/dao/message/message.dao.ts +32 -32
  101. package/src/dao/reconciliation-log/reconciliation-log.dao.ts +1 -1
  102. package/src/dao/report-configuration/report-configuration.dao.ts +381 -370
  103. package/src/dao/study/study.dao.ts +83 -94
  104. package/src/dao/systemConfiguration/SystemConfigurationDAO.ts +35 -41
  105. package/src/dao/user/user.dao.ts +50 -52
  106. package/src/dao/user-push-notification-token/user-push-notification-token.dao.ts +48 -80
  107. package/src/dao/video/video.dao.ts +345 -396
  108. package/src/entities/BaseEntity.ts +1 -1
  109. package/src/index.ts +30 -43
  110. package/src/interfaces/auth/auth.interfaces.ts +10 -10
  111. package/src/interfaces/batch/batch.interfaces.ts +1 -1
  112. package/src/interfaces/camera/camera.interfaces.ts +9 -9
  113. package/src/interfaces/chat/chat.interfaces.ts +4 -4
  114. package/src/interfaces/folder/folder.interfaces.ts +2 -2
  115. package/src/interfaces/location/location.interfaces.ts +7 -7
  116. package/src/interfaces/message/message.interfaces.ts +3 -3
  117. package/src/interfaces/report-configuration/report-configuration.interfaces.ts +17 -16
  118. package/src/interfaces/study/study.interfaces.ts +3 -10
  119. package/src/interfaces/user/user.interfaces.ts +9 -9
  120. package/src/interfaces/user-push-notification-token/user-push-notification-token.interfaces.ts +9 -9
  121. package/src/interfaces/video/video.interfaces.ts +34 -34
@@ -1,113 +1,102 @@
1
1
  import { Knex } from "knex";
2
2
  import { IBaseDAO, IDataPaginator } from "../../d.types";
3
- import { IStudy, IStudyFilters } from "../../interfaces/study/study.interfaces";
4
- import { STUDY_SORT_COLUMN_MAP } from "../../constants/study.constants";
3
+ import { IStudy } from "../../interfaces/study/study.interfaces";
5
4
  import KnexManager from "../../KnexConnection";
5
+ import { StudySortField, STUDY_SORT_COLUMN_MAP } from "../../constants/study.constants";
6
+ import { SortOrder } from "../../constants/video.constants";
7
+
8
+ export interface IStudyFilters {
9
+ createdBy?: number | null;
10
+ sortBy?: StudySortField;
11
+ sortOrder?: SortOrder;
12
+ }
6
13
 
7
14
  export class StudyDAO implements IBaseDAO<IStudy> {
8
- private _knex: Knex<any, unknown[]> = KnexManager.getConnection();
15
+ private _knex: Knex<any, unknown[]> = KnexManager.getConnection();
9
16
 
10
- async create(item: IStudy): Promise<IStudy> {
11
- const [createdStudy] = await this._knex("study")
12
- .insert(item)
13
- .returning("*");
14
- return createdStudy;
15
- }
17
+ async create(item: IStudy): Promise<IStudy> {
18
+ const [createdStudy] = await this._knex("study").insert(item).returning("*");
19
+ return createdStudy;
20
+ }
16
21
 
17
- async getById(id: number): Promise<IStudy | null> {
18
- const study = await this._knex("study as s")
19
- .innerJoin("users as u", "s.createdBy", "u.id")
20
- .leftJoin("locations as l", "s.locationId", "l.id")
21
- .select(
22
- "s.*",
23
- this._knex.raw("to_jsonb(u.*) as user"),
24
- this._knex.raw("to_jsonb(l.*) as location"),
25
- )
26
- .where("s.id", id)
27
- .first();
28
- return study || null;
29
- }
22
+ async getById(id: number): Promise<IStudy | null> {
23
+ const study = await this._knex("study as s")
24
+ .innerJoin("users as u", "s.createdBy", "u.id")
25
+ .leftJoin("locations as l", "s.locationId", "l.id")
26
+ .select("s.*", this._knex.raw("to_jsonb(u.*) as user"), this._knex.raw("to_jsonb(l.*) as location"))
27
+ .where("s.id", id)
28
+ .first();
29
+ return study || null;
30
+ }
30
31
 
31
- async getByUuid(uuid: string): Promise<IStudy | null> {
32
- const study = await this._knex("study as s")
33
- .innerJoin("users as u", "s.createdBy", "u.id")
34
- .leftJoin("locations as l", "s.locationId", "l.id")
35
- .select(
36
- "s.*",
37
- this._knex.raw("to_jsonb(u.*) as user"),
38
- this._knex.raw("to_jsonb(l.*) as location"),
39
- )
40
- .where("s.uuid", uuid)
41
- .first();
42
- return study || null;
43
- }
32
+ async getByUuid(uuid: string): Promise<IStudy | null> {
33
+ const study = await this._knex("study as s")
34
+ .innerJoin("users as u", "s.createdBy", "u.id")
35
+ .leftJoin("locations as l", "s.locationId", "l.id")
36
+ .select("s.*", this._knex.raw("to_jsonb(u.*) as user"), this._knex.raw("to_jsonb(l.*) as location"))
37
+ .where("s.uuid", uuid)
38
+ .first();
39
+ return study || null;
40
+ }
44
41
 
45
- async update(id: number, item: Partial<IStudy>): Promise<IStudy | null> {
46
- const [updatedStudy] = await this._knex("study")
47
- .where({ id })
48
- .update(item)
49
- .returning("*");
50
- return updatedStudy || null;
51
- }
42
+ async update(id: number, item: Partial<IStudy>): Promise<IStudy | null> {
43
+ const [updatedStudy] = await this._knex("study").where({ id }).update(item).returning("*");
44
+ return updatedStudy || null;
45
+ }
52
46
 
53
- async delete(id: number): Promise<boolean> {
54
- const result = await this._knex("study").where({ id }).del();
55
- return result > 0;
56
- }
47
+ async delete(id: number): Promise<boolean> {
48
+ const result = await this._knex("study").where({ id }).del();
49
+ return result > 0;
50
+ }
57
51
 
58
- async getAll(
59
- page: number,
60
- limit: number,
61
- filters?: IStudyFilters,
62
- ): Promise<IDataPaginator<IStudy>> {
63
- const offset = (page - 1) * limit;
52
+ async getAll(page: number, limit: number, filters?: IStudyFilters): Promise<IDataPaginator<IStudy>> {
53
+ const offset = (page - 1) * limit;
64
54
 
65
- const query = this._knex("study as s")
66
- .innerJoin("users as u", "s.createdBy", "u.id")
67
- .leftJoin("locations as l", "s.locationId", "l.id")
68
- .select(
69
- "s.*",
70
- this._knex.raw("to_jsonb(u.*) as user"),
71
- this._knex.raw("to_jsonb(l.*) as location"),
72
- );
55
+ const query = this._knex("study as s")
56
+ .innerJoin("users as u", "s.createdBy", "u.id")
57
+ .leftJoin("locations as l", "s.locationId", "l.id")
58
+ .select("s.*", this._knex.raw("to_jsonb(u.*) as user"), this._knex.raw("to_jsonb(l.*) as location"));
73
59
 
74
- const [countResult] = await query.clone().clearSelect().count("* as count");
75
- const totalCount = +countResult.count;
60
+ if (filters) {
61
+ if (filters.createdBy !== undefined && filters.createdBy !== null) {
62
+ query.where("s.createdBy", filters.createdBy);
63
+ }
76
64
 
77
- // Apply sorting
78
- const sortColumn =
79
- filters?.sortBy && STUDY_SORT_COLUMN_MAP[filters.sortBy]
80
- ? STUDY_SORT_COLUMN_MAP[filters.sortBy]
81
- : "s.created_at";
82
- const sortOrder = filters?.sortOrder || "DESC";
83
- query.orderBy(sortColumn, sortOrder);
65
+ if (filters.sortBy) {
66
+ const columnName = STUDY_SORT_COLUMN_MAP[filters.sortBy];
67
+ const order = filters.sortOrder || "DESC";
68
+ query.orderBy(columnName, order);
69
+ } else {
70
+ query.orderBy("s.created_at", "DESC");
71
+ }
72
+ } else {
73
+ query.orderBy("s.created_at", "DESC");
74
+ }
84
75
 
85
- 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);
86
79
 
87
- return {
88
- success: true,
89
- data: studies,
90
- page,
91
- limit,
92
- count: studies.length,
93
- totalCount,
94
- totalPages: Math.ceil(totalCount / limit),
95
- };
96
- }
80
+ return {
81
+ success: true,
82
+ data: studies,
83
+ page,
84
+ limit,
85
+ count: studies.length,
86
+ totalCount,
87
+ totalPages: Math.ceil(totalCount / limit),
88
+ };
89
+ }
97
90
 
98
- async getStudiesByLocation(locationId: number): Promise<IStudy[]> {
99
- const studies = await this._knex("study as s")
100
- .innerJoin("users as u", "s.createdBy", "u.id")
101
- .leftJoin("locations as l", "s.locationId", "l.id")
102
- .select(
103
- "s.*",
104
- this._knex.raw("to_jsonb(u.*) as user"),
105
- this._knex.raw("to_jsonb(l.*) as location"),
106
- )
107
- .where("s.locationId", locationId)
108
- .orderBy("s.created_at", "desc")
109
- .limit(10);
91
+ async getStudiesByLocation(locationId: number): Promise<IStudy[]> {
92
+ const studies = await this._knex("study as s")
93
+ .innerJoin("users as u", "s.createdBy", "u.id")
94
+ .leftJoin("locations as l", "s.locationId", "l.id")
95
+ .select("s.*", this._knex.raw("to_jsonb(u.*) as user"), this._knex.raw("to_jsonb(l.*) as location"))
96
+ .where("s.locationId", locationId)
97
+ .orderBy("s.created_at", "desc")
98
+ .limit(10);
110
99
 
111
- return studies;
112
- }
100
+ return studies;
101
+ }
113
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
+ }