@tmscloud/tbt-knex 0.0.1

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 (58) hide show
  1. package/dist/KnexConnection.d.ts +17 -0
  2. package/dist/KnexConnection.js +81 -0
  3. package/dist/KnexConnection.js.map +1 -0
  4. package/dist/d.types.d.ts +16 -0
  5. package/dist/d.types.js +3 -0
  6. package/dist/d.types.js.map +1 -0
  7. package/dist/dao/driver-tracking/driver-tracking.dao.d.ts +42 -0
  8. package/dist/dao/driver-tracking/driver-tracking.dao.js +329 -0
  9. package/dist/dao/driver-tracking/driver-tracking.dao.js.map +1 -0
  10. package/dist/dao/gps-location/gps-location.dao.d.ts +76 -0
  11. package/dist/dao/gps-location/gps-location.dao.js +364 -0
  12. package/dist/dao/gps-location/gps-location.dao.js.map +1 -0
  13. package/dist/dao/role/role.dao.d.ts +38 -0
  14. package/dist/dao/role/role.dao.js +146 -0
  15. package/dist/dao/role/role.dao.js.map +1 -0
  16. package/dist/dao/route/route.dao.d.ts +38 -0
  17. package/dist/dao/route/route.dao.js +167 -0
  18. package/dist/dao/route/route.dao.js.map +1 -0
  19. package/dist/dao/route-assignment/route-assignment.dao.d.ts +58 -0
  20. package/dist/dao/route-assignment/route-assignment.dao.js +330 -0
  21. package/dist/dao/route-assignment/route-assignment.dao.js.map +1 -0
  22. package/dist/dao/sundays-package-version/sundays-package-version.dao.d.ts +11 -0
  23. package/dist/dao/sundays-package-version/sundays-package-version.dao.js +88 -0
  24. package/dist/dao/sundays-package-version/sundays-package-version.dao.js.map +1 -0
  25. package/dist/dao/trip/trip.dao.d.ts +102 -0
  26. package/dist/dao/trip/trip.dao.js +502 -0
  27. package/dist/dao/trip/trip.dao.js.map +1 -0
  28. package/dist/dao/user/user.dao.d.ts +74 -0
  29. package/dist/dao/user/user.dao.js +287 -0
  30. package/dist/dao/user/user.dao.js.map +1 -0
  31. package/dist/index.d.ts +19 -0
  32. package/dist/index.js +26 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/interfaces/driver-tracking/driver-tracking.interfaces.d.ts +102 -0
  35. package/dist/interfaces/driver-tracking/driver-tracking.interfaces.js +3 -0
  36. package/dist/interfaces/driver-tracking/driver-tracking.interfaces.js.map +1 -0
  37. package/dist/interfaces/gps-location/gps-location.interfaces.d.ts +30 -0
  38. package/dist/interfaces/gps-location/gps-location.interfaces.js +3 -0
  39. package/dist/interfaces/gps-location/gps-location.interfaces.js.map +1 -0
  40. package/dist/interfaces/role/role.interfaces.d.ts +8 -0
  41. package/dist/interfaces/role/role.interfaces.js +3 -0
  42. package/dist/interfaces/role/role.interfaces.js.map +1 -0
  43. package/dist/interfaces/route/route.interfaces.d.ts +23 -0
  44. package/dist/interfaces/route/route.interfaces.js +3 -0
  45. package/dist/interfaces/route/route.interfaces.js.map +1 -0
  46. package/dist/interfaces/route-assignment/route-assignment.interfaces.d.ts +18 -0
  47. package/dist/interfaces/route-assignment/route-assignment.interfaces.js +3 -0
  48. package/dist/interfaces/route-assignment/route-assignment.interfaces.js.map +1 -0
  49. package/dist/interfaces/sundays-package-version/sundays-package-version.interfaces.d.ts +6 -0
  50. package/dist/interfaces/sundays-package-version/sundays-package-version.interfaces.js +3 -0
  51. package/dist/interfaces/sundays-package-version/sundays-package-version.interfaces.js.map +1 -0
  52. package/dist/interfaces/trip/trip.interfaces.d.ts +46 -0
  53. package/dist/interfaces/trip/trip.interfaces.js +3 -0
  54. package/dist/interfaces/trip/trip.interfaces.js.map +1 -0
  55. package/dist/interfaces/user/user.interfaces.d.ts +25 -0
  56. package/dist/interfaces/user/user.interfaces.js +3 -0
  57. package/dist/interfaces/user/user.interfaces.js.map +1 -0
  58. package/package.json +52 -0
@@ -0,0 +1,364 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.GPSLocationDAO = void 0;
16
+ const KnexConnection_1 = __importDefault(require("../../KnexConnection"));
17
+ class GPSLocationDAO {
18
+ get knex() {
19
+ if (!this._knex) {
20
+ this._knex = KnexConnection_1.default.getConnection();
21
+ }
22
+ return this._knex;
23
+ }
24
+ /**
25
+ * Parse JSON fields from database
26
+ */
27
+ parseLocationJson(location) {
28
+ var _a;
29
+ // Parse user JSON if present
30
+ if (location.user && typeof location.user === "string") {
31
+ location.user = JSON.parse(location.user);
32
+ }
33
+ if (((_a = location.user) === null || _a === void 0 ? void 0 : _a.role) && typeof location.user.role === "string") {
34
+ location.user.role = JSON.parse(location.user.role);
35
+ }
36
+ // Parse trip JSON if present
37
+ if (location.trip && typeof location.trip === "string") {
38
+ location.trip = JSON.parse(location.trip);
39
+ }
40
+ // Parse metadata if present
41
+ if (location.metadata && typeof location.metadata === "string") {
42
+ location.metadata = JSON.parse(location.metadata);
43
+ }
44
+ return location;
45
+ }
46
+ /**
47
+ * Base query with joins
48
+ */
49
+ baseQuery() {
50
+ return this.knex("gps_locations as gl")
51
+ .leftJoin("users as u", "gl.user_id", "u.id")
52
+ .leftJoin("roles as ur", "u.role_id", "ur.id")
53
+ .leftJoin("trips as t", "gl.trip_id", "t.id")
54
+ .select("gl.*", this.knex.raw(`jsonb_build_object(
55
+ 'id', u.id,
56
+ 'uuid', u.uuid,
57
+ 'email', u.email,
58
+ 'username', u.username,
59
+ 'first_name', u.first_name,
60
+ 'last_name', u.last_name,
61
+ 'role', to_jsonb(ur.*)
62
+ ) as user`), this.knex.raw("to_jsonb(t.*) as trip"));
63
+ }
64
+ /**
65
+ * Get all GPS locations with pagination
66
+ */
67
+ getAll() {
68
+ return __awaiter(this, arguments, void 0, function* (page = 1, limit = 10) {
69
+ const offset = (page - 1) * limit;
70
+ // Get paginated data
71
+ const rawData = yield this.baseQuery()
72
+ .limit(limit)
73
+ .offset(offset)
74
+ .orderBy("gl.recorded_at", "desc");
75
+ // Parse JSON fields
76
+ const data = rawData.map((location) => this.parseLocationJson(location));
77
+ // Get total count
78
+ const totalCountResult = yield this.knex("gps_locations")
79
+ .count("* as count")
80
+ .first();
81
+ const totalCount = Number((totalCountResult === null || totalCountResult === void 0 ? void 0 : totalCountResult.count) || 0);
82
+ const count = data.length;
83
+ const totalPages = Math.ceil(totalCount / limit);
84
+ return {
85
+ success: true,
86
+ data,
87
+ page,
88
+ limit,
89
+ count,
90
+ totalCount,
91
+ totalPages,
92
+ };
93
+ });
94
+ }
95
+ /**
96
+ * Get GPS location by ID
97
+ */
98
+ getById(id) {
99
+ return __awaiter(this, void 0, void 0, function* () {
100
+ const result = yield this.baseQuery().where("gl.id", id).first();
101
+ return result ? this.parseLocationJson(result) : null;
102
+ });
103
+ }
104
+ /**
105
+ * Get GPS location by UUID
106
+ */
107
+ getByUuid(uuid) {
108
+ return __awaiter(this, void 0, void 0, function* () {
109
+ const result = yield this.baseQuery().where("gl.uuid", uuid).first();
110
+ return result ? this.parseLocationJson(result) : null;
111
+ });
112
+ }
113
+ /**
114
+ * Get current location for a trip
115
+ */
116
+ getCurrentLocationByTripId(tripId) {
117
+ return __awaiter(this, void 0, void 0, function* () {
118
+ const result = yield this.baseQuery()
119
+ .where("gl.trip_id", tripId)
120
+ .orderBy("gl.recorded_at", "desc")
121
+ .first();
122
+ return result ? this.parseLocationJson(result) : null;
123
+ });
124
+ }
125
+ /**
126
+ * Get location history for a trip
127
+ */
128
+ getLocationHistoryByTripId(tripId_1) {
129
+ return __awaiter(this, arguments, void 0, function* (tripId, page = 1, limit = 100) {
130
+ const offset = (page - 1) * limit;
131
+ // Get paginated data
132
+ const rawData = yield this.baseQuery()
133
+ .where("gl.trip_id", tripId)
134
+ .limit(limit)
135
+ .offset(offset)
136
+ .orderBy("gl.recorded_at", "desc");
137
+ // Parse JSON fields
138
+ const data = rawData.map((location) => this.parseLocationJson(location));
139
+ // Get total count
140
+ const totalCountResult = yield this.knex("gps_locations")
141
+ .where("trip_id", tripId)
142
+ .count("* as count")
143
+ .first();
144
+ const totalCount = Number((totalCountResult === null || totalCountResult === void 0 ? void 0 : totalCountResult.count) || 0);
145
+ const count = data.length;
146
+ const totalPages = Math.ceil(totalCount / limit);
147
+ return {
148
+ success: true,
149
+ data,
150
+ page,
151
+ limit,
152
+ count,
153
+ totalCount,
154
+ totalPages,
155
+ };
156
+ });
157
+ }
158
+ /**
159
+ * Get recent locations for a trip (last N locations)
160
+ */
161
+ getRecentLocationsByTripId(tripId_1) {
162
+ return __awaiter(this, arguments, void 0, function* (tripId, limit = 10) {
163
+ const rawData = yield this.baseQuery()
164
+ .where("gl.trip_id", tripId)
165
+ .orderBy("gl.recorded_at", "desc")
166
+ .limit(limit);
167
+ return rawData.map((location) => this.parseLocationJson(location));
168
+ });
169
+ }
170
+ /**
171
+ * Get locations by user ID
172
+ */
173
+ getLocationsByUserId(userId_1) {
174
+ return __awaiter(this, arguments, void 0, function* (userId, page = 1, limit = 100) {
175
+ const offset = (page - 1) * limit;
176
+ // Get paginated data
177
+ const rawData = yield this.baseQuery()
178
+ .where("gl.user_id", userId)
179
+ .limit(limit)
180
+ .offset(offset)
181
+ .orderBy("gl.recorded_at", "desc");
182
+ // Parse JSON fields
183
+ const data = rawData.map((location) => this.parseLocationJson(location));
184
+ // Get total count
185
+ const totalCountResult = yield this.knex("gps_locations")
186
+ .where("user_id", userId)
187
+ .count("* as count")
188
+ .first();
189
+ const totalCount = Number((totalCountResult === null || totalCountResult === void 0 ? void 0 : totalCountResult.count) || 0);
190
+ const count = data.length;
191
+ const totalPages = Math.ceil(totalCount / limit);
192
+ return {
193
+ success: true,
194
+ data,
195
+ page,
196
+ limit,
197
+ count,
198
+ totalCount,
199
+ totalPages,
200
+ };
201
+ });
202
+ }
203
+ /**
204
+ * Get trip location summary
205
+ */
206
+ getTripLocationSummary(tripId) {
207
+ return __awaiter(this, void 0, void 0, function* () {
208
+ // Get current location
209
+ const currentLocation = yield this.getCurrentLocationByTripId(tripId);
210
+ // Get total count
211
+ const countResult = yield this.knex("gps_locations")
212
+ .where("trip_id", tripId)
213
+ .count("* as count")
214
+ .first();
215
+ const totalLocations = Number((countResult === null || countResult === void 0 ? void 0 : countResult.count) || 0);
216
+ return {
217
+ trip_id: tripId,
218
+ current_location: currentLocation || undefined,
219
+ last_updated: currentLocation === null || currentLocation === void 0 ? void 0 : currentLocation.recorded_at,
220
+ total_locations: totalLocations,
221
+ };
222
+ });
223
+ }
224
+ /**
225
+ * Create a new GPS location
226
+ */
227
+ create(data) {
228
+ return __awaiter(this, void 0, void 0, function* () {
229
+ const [result] = yield this.knex("gps_locations")
230
+ .insert({
231
+ trip_id: data.trip_id,
232
+ user_id: data.user_id,
233
+ latitude: data.latitude,
234
+ longitude: data.longitude,
235
+ accuracy: data.accuracy,
236
+ altitude: data.altitude,
237
+ speed: data.speed,
238
+ heading: data.heading,
239
+ recorded_at: data.recorded_at || new Date(),
240
+ metadata: data.metadata ? JSON.stringify(data.metadata) : null,
241
+ })
242
+ .returning("*");
243
+ // Fetch with joins
244
+ return this.getById(result.id);
245
+ });
246
+ }
247
+ /**
248
+ * Update a GPS location by ID
249
+ */
250
+ update(id, data) {
251
+ return __awaiter(this, void 0, void 0, function* () {
252
+ const updateData = {};
253
+ if (data.latitude !== undefined)
254
+ updateData.latitude = data.latitude;
255
+ if (data.longitude !== undefined)
256
+ updateData.longitude = data.longitude;
257
+ if (data.accuracy !== undefined)
258
+ updateData.accuracy = data.accuracy;
259
+ if (data.altitude !== undefined)
260
+ updateData.altitude = data.altitude;
261
+ if (data.speed !== undefined)
262
+ updateData.speed = data.speed;
263
+ if (data.heading !== undefined)
264
+ updateData.heading = data.heading;
265
+ if (data.recorded_at !== undefined)
266
+ updateData.recorded_at = data.recorded_at;
267
+ if (data.metadata !== undefined)
268
+ updateData.metadata = JSON.stringify(data.metadata);
269
+ updateData.updated_at = new Date();
270
+ const [result] = yield this.knex("gps_locations")
271
+ .where("id", id)
272
+ .update(updateData)
273
+ .returning("*");
274
+ return result ? this.getById(result.id) : null;
275
+ });
276
+ }
277
+ /**
278
+ * Delete a GPS location by ID
279
+ */
280
+ delete(id) {
281
+ return __awaiter(this, void 0, void 0, function* () {
282
+ const result = yield this.knex("gps_locations").where("id", id).delete();
283
+ return result > 0;
284
+ });
285
+ }
286
+ /**
287
+ * Delete old GPS locations (older than specified hours)
288
+ */
289
+ deleteOldLocations() {
290
+ return __awaiter(this, arguments, void 0, function* (hoursOld = 48) {
291
+ const cutoffDate = new Date();
292
+ cutoffDate.setHours(cutoffDate.getHours() - hoursOld);
293
+ const result = yield this.knex("gps_locations")
294
+ .where("recorded_at", "<", cutoffDate)
295
+ .delete();
296
+ return result;
297
+ });
298
+ }
299
+ /**
300
+ * Calculate distance between two GPS coordinates using Haversine formula
301
+ * Returns distance in kilometers
302
+ */
303
+ calculateDistance(lat1, lon1, lat2, lon2) {
304
+ const R = 6371; // Radius of the Earth in km
305
+ const dLat = this.toRad(lat2 - lat1);
306
+ const dLon = this.toRad(lon2 - lon1);
307
+ const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
308
+ Math.cos(this.toRad(lat1)) *
309
+ Math.cos(this.toRad(lat2)) *
310
+ Math.sin(dLon / 2) *
311
+ Math.sin(dLon / 2);
312
+ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
313
+ const distance = R * c;
314
+ return distance;
315
+ }
316
+ toRad(degrees) {
317
+ return degrees * (Math.PI / 180);
318
+ }
319
+ /**
320
+ * Calculate total distance traveled for a trip
321
+ */
322
+ calculateTripDistance(tripId) {
323
+ return __awaiter(this, void 0, void 0, function* () {
324
+ const locations = yield this.knex("gps_locations")
325
+ .where("trip_id", tripId)
326
+ .orderBy("recorded_at", "asc")
327
+ .select("latitude", "longitude");
328
+ if (locations.length < 2) {
329
+ return 0;
330
+ }
331
+ let totalDistance = 0;
332
+ for (let i = 1; i < locations.length; i++) {
333
+ const prev = locations[i - 1];
334
+ const curr = locations[i];
335
+ totalDistance += this.calculateDistance(Number(prev.latitude), Number(prev.longitude), Number(curr.latitude), Number(curr.longitude));
336
+ }
337
+ return totalDistance;
338
+ });
339
+ }
340
+ /**
341
+ * Get location history with distances
342
+ */
343
+ getLocationHistoryWithDistances(tripId) {
344
+ return __awaiter(this, void 0, void 0, function* () {
345
+ const locations = yield this.knex("gps_locations")
346
+ .where("trip_id", tripId)
347
+ .orderBy("recorded_at", "asc")
348
+ .select("*");
349
+ const locationsWithDistance = [];
350
+ for (let i = 0; i < locations.length; i++) {
351
+ const location = locations[i];
352
+ let distanceFromPrevious;
353
+ if (i > 0) {
354
+ const prev = locations[i - 1];
355
+ distanceFromPrevious = this.calculateDistance(Number(prev.latitude), Number(prev.longitude), Number(location.latitude), Number(location.longitude));
356
+ }
357
+ locationsWithDistance.push(Object.assign(Object.assign({}, location), { distance_from_previous: distanceFromPrevious }));
358
+ }
359
+ return locationsWithDistance;
360
+ });
361
+ }
362
+ }
363
+ exports.GPSLocationDAO = GPSLocationDAO;
364
+ //# sourceMappingURL=gps-location.dao.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gps-location.dao.js","sourceRoot":"","sources":["../../../src/dao/gps-location/gps-location.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,0EAA+C;AAQ/C,MAAa,cAAc;IAGzB,IAAY,IAAI;QACd,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YAChB,IAAI,CAAC,KAAK,GAAG,wBAAW,CAAC,aAAa,EAAE,CAAC;QAC3C,CA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,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC;iBAC/C,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC;iBACxB,OAAO,CAAC,aAAa,EAAE,KAAK,CAAC;iBAC7B,MAAM,CAAC,GAAG,CAAC,CAAC;YAEf,MAAM,qBAAqB,GAA+B,EAAE,CAAC;YAE7D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC1C,MAAM,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;gBAC9B,IAAI,oBAAwC,CAAC;gBAE7C,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;oBACV,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;oBAC9B,oBAAoB,GAAG,IAAI,CAAC,iBAAiB,CAC3C,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EACrB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EACtB,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,EACzB,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAC3B,CAAC;gBACJ,CAAC;gBAED,qBAAqB,CAAC,IAAI,iCACrB,QAAQ,KACX,sBAAsB,EAAE,oBAAoB,IAC5C,CAAC;YACL,CAAC;YAED,OAAO,qBAAqB,CAAC;QAC/B,CAAC;KAAA;CACF;AAjaD,wCAiaC"}
@@ -0,0 +1,38 @@
1
+ import { IRole } from "../../interfaces/role/role.interfaces";
2
+ import { IBaseDAO, IDataPaginator } from "../../d.types";
3
+ export declare class RoleDAO implements IBaseDAO<IRole> {
4
+ private _knex?;
5
+ private get knex();
6
+ /**
7
+ * Parse JSON fields from database
8
+ */
9
+ private parseRoleJson;
10
+ /**
11
+ * Get all roles with pagination
12
+ */
13
+ getAll(page?: number, limit?: number): Promise<IDataPaginator<IRole>>;
14
+ /**
15
+ * Get role by ID
16
+ */
17
+ getById(id: number): Promise<IRole | null>;
18
+ /**
19
+ * Get role by name
20
+ */
21
+ getByName(name: string): Promise<IRole | null>;
22
+ /**
23
+ * Create a new role
24
+ */
25
+ create(data: IRole): Promise<IRole>;
26
+ /**
27
+ * Update a role by ID
28
+ */
29
+ update(id: number, data: Partial<IRole>): Promise<IRole | null>;
30
+ /**
31
+ * Delete a role by ID
32
+ */
33
+ delete(id: number): Promise<boolean>;
34
+ /**
35
+ * Check if role has a specific permission
36
+ */
37
+ hasPermission(roleId: number, permission: string): Promise<boolean>;
38
+ }
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.RoleDAO = void 0;
16
+ const KnexConnection_1 = __importDefault(require("../../KnexConnection"));
17
+ class RoleDAO {
18
+ get knex() {
19
+ if (!this._knex) {
20
+ this._knex = KnexConnection_1.default.getConnection();
21
+ }
22
+ return this._knex;
23
+ }
24
+ /**
25
+ * Parse JSON fields from database
26
+ */
27
+ parseRoleJson(role) {
28
+ return Object.assign(Object.assign({}, role), { permissions: typeof role.permissions === "string"
29
+ ? JSON.parse(role.permissions)
30
+ : role.permissions });
31
+ }
32
+ /**
33
+ * Get all roles with pagination
34
+ */
35
+ getAll() {
36
+ return __awaiter(this, arguments, void 0, function* (page = 1, limit = 10) {
37
+ const offset = (page - 1) * limit;
38
+ // Get paginated data
39
+ const rawData = yield this.knex("roles")
40
+ .select("*")
41
+ .limit(limit)
42
+ .offset(offset)
43
+ .orderBy("id", "asc");
44
+ // Parse JSON fields
45
+ const data = rawData.map((role) => this.parseRoleJson(role));
46
+ // Get total count
47
+ const totalCountResult = yield this.knex("roles")
48
+ .count("* as count")
49
+ .first();
50
+ const totalCount = Number((totalCountResult === null || totalCountResult === void 0 ? void 0 : totalCountResult.count) || 0);
51
+ const count = data.length;
52
+ const totalPages = Math.ceil(totalCount / limit);
53
+ return {
54
+ success: true,
55
+ data,
56
+ page,
57
+ limit,
58
+ count,
59
+ totalCount,
60
+ totalPages,
61
+ };
62
+ });
63
+ }
64
+ /**
65
+ * Get role by ID
66
+ */
67
+ getById(id) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ const result = yield this.knex("roles").select("*").where("id", id).first();
70
+ return result ? this.parseRoleJson(result) : null;
71
+ });
72
+ }
73
+ /**
74
+ * Get role by name
75
+ */
76
+ getByName(name) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ const result = yield this.knex("roles")
79
+ .select("*")
80
+ .where("name", name)
81
+ .first();
82
+ return result ? this.parseRoleJson(result) : null;
83
+ });
84
+ }
85
+ /**
86
+ * Create a new role
87
+ */
88
+ create(data) {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ const [result] = yield this.knex("roles")
91
+ .insert({
92
+ name: data.name,
93
+ description: data.description,
94
+ permissions: data.permissions ? JSON.stringify(data.permissions) : null,
95
+ })
96
+ .returning("*");
97
+ return this.parseRoleJson(result);
98
+ });
99
+ }
100
+ /**
101
+ * Update a role by ID
102
+ */
103
+ update(id, data) {
104
+ return __awaiter(this, void 0, void 0, function* () {
105
+ const updateData = {};
106
+ if (data.name !== undefined)
107
+ updateData.name = data.name;
108
+ if (data.description !== undefined)
109
+ updateData.description = data.description;
110
+ if (data.permissions !== undefined) {
111
+ updateData.permissions = data.permissions
112
+ ? JSON.stringify(data.permissions)
113
+ : null;
114
+ }
115
+ updateData.updated_at = new Date();
116
+ const [result] = yield this.knex("roles")
117
+ .where("id", id)
118
+ .update(updateData)
119
+ .returning("*");
120
+ return result ? this.parseRoleJson(result) : null;
121
+ });
122
+ }
123
+ /**
124
+ * Delete a role by ID
125
+ */
126
+ delete(id) {
127
+ return __awaiter(this, void 0, void 0, function* () {
128
+ const result = yield this.knex("roles").where("id", id).delete();
129
+ return result > 0;
130
+ });
131
+ }
132
+ /**
133
+ * Check if role has a specific permission
134
+ */
135
+ hasPermission(roleId, permission) {
136
+ return __awaiter(this, void 0, void 0, function* () {
137
+ const role = yield this.getById(roleId);
138
+ if (!role || !role.permissions) {
139
+ return false;
140
+ }
141
+ return role.permissions.includes(permission);
142
+ });
143
+ }
144
+ }
145
+ exports.RoleDAO = RoleDAO;
146
+ //# sourceMappingURL=role.dao.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"role.dao.js","sourceRoot":"","sources":["../../../src/dao/role/role.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,0EAA+C;AAI/C,MAAa,OAAO;IAGlB,IAAY,IAAI;QACd,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YAChB,IAAI,CAAC,KAAK,GAAG,wBAAW,CAAC,aAAa,EAAE,CAAC;QAC3C,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;OAEG;IACK,aAAa,CAAC,IAAS;QAC7B,uCACK,IAAI,KACP,WAAW,EACT,OAAO,IAAI,CAAC,WAAW,KAAK,QAAQ;gBAClC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC;gBAC9B,CAAC,CAAC,IAAI,CAAC,WAAW,IACtB;IACJ,CAAC;IAED;;OAEG;IACG,MAAM;6DACV,OAAe,CAAC,EAChB,QAAgB,EAAE;YAElB,MAAM,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,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CAAC,CAAC,IAAI,CAAC;YACX,CAAC;YAED,UAAU,CAAC,UAAU,GAAG,IAAI,IAAI,EAAE,CAAC;YAEnC,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;iBACtC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;iBACf,MAAM,CAAC,UAAU,CAAC;iBAClB,SAAS,CAAC,GAAG,CAAC,CAAC;YAElB,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACpD,CAAC;KAAA;IAED;;OAEG;IACG,MAAM,CAAC,EAAU;;YACrB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;YAEjE,OAAO,MAAM,GAAG,CAAC,CAAC;QACpB,CAAC;KAAA;IAED;;OAEG;IACG,aAAa,CAAC,MAAc,EAAE,UAAkB;;YACpD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACxC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;gBAC/B,OAAO,KAAK,CAAC;YACf,CAAC;YAED,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;QAC/C,CAAC;KAAA;CACF;AA/ID,0BA+IC"}
@@ -0,0 +1,38 @@
1
+ import { IRoute } from "../../interfaces/route/route.interfaces";
2
+ import { IBaseDAO, IDataPaginator } from "../../d.types";
3
+ export declare class RouteDAO implements IBaseDAO<IRoute> {
4
+ private _knex?;
5
+ private get knex();
6
+ /**
7
+ * Parse JSON fields from database
8
+ */
9
+ private parseRouteJson;
10
+ /**
11
+ * Get all routes with pagination
12
+ */
13
+ getAll(page?: number, limit?: number): Promise<IDataPaginator<IRoute>>;
14
+ /**
15
+ * Get route by ID
16
+ */
17
+ getById(id: number): Promise<IRoute | null>;
18
+ /**
19
+ * Get route by UUID
20
+ */
21
+ getByUuid(uuid: string): Promise<IRoute | null>;
22
+ /**
23
+ * Create a new route
24
+ */
25
+ create(data: IRoute): Promise<IRoute>;
26
+ /**
27
+ * Update a route by ID
28
+ */
29
+ update(id: number, data: Partial<IRoute>): Promise<IRoute | null>;
30
+ /**
31
+ * Delete a route by ID (soft delete by setting is_active to false)
32
+ */
33
+ delete(id: number): Promise<boolean>;
34
+ /**
35
+ * Hard delete a route by ID
36
+ */
37
+ hardDelete(id: number): Promise<boolean>;
38
+ }