@trafficgroup/knex-rel 0.1.11-rc0 → 0.1.11
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.
- package/dist/constants/video.constants.d.ts +2 -2
- package/dist/constants/video.constants.js +5 -9
- package/dist/constants/video.constants.js.map +1 -1
- package/dist/dao/VideoMinuteResultDAO.d.ts +1 -1
- package/dist/dao/VideoMinuteResultDAO.js +23 -29
- package/dist/dao/VideoMinuteResultDAO.js.map +1 -1
- package/dist/dao/auth/auth.dao.js +1 -4
- package/dist/dao/auth/auth.dao.js.map +1 -1
- package/dist/dao/batch/batch.dao.js +14 -13
- package/dist/dao/batch/batch.dao.js.map +1 -1
- package/dist/dao/camera/camera.dao.js +7 -10
- package/dist/dao/camera/camera.dao.js.map +1 -1
- package/dist/dao/chat/chat.dao.d.ts +1 -1
- package/dist/dao/chat/chat.dao.js +40 -27
- package/dist/dao/chat/chat.dao.js.map +1 -1
- package/dist/dao/folder/folder.dao.js +2 -7
- package/dist/dao/folder/folder.dao.js.map +1 -1
- package/dist/dao/location/location.dao.js +9 -16
- package/dist/dao/location/location.dao.js.map +1 -1
- package/dist/dao/message/message.dao.d.ts +1 -1
- package/dist/dao/message/message.dao.js +26 -18
- package/dist/dao/message/message.dao.js.map +1 -1
- package/dist/dao/report-configuration/report-configuration.dao.js +31 -32
- package/dist/dao/report-configuration/report-configuration.dao.js.map +1 -1
- package/dist/dao/study/study.dao.js +2 -7
- package/dist/dao/study/study.dao.js.map +1 -1
- package/dist/dao/user/user.dao.js +1 -4
- package/dist/dao/user/user.dao.js.map +1 -1
- package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js +8 -26
- package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js.map +1 -1
- package/dist/dao/video/video.dao.js +28 -30
- package/dist/dao/video/video.dao.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js.map +1 -1
- package/dist/interfaces/batch/batch.interfaces.d.ts +1 -1
- package/dist/interfaces/camera/camera.interfaces.d.ts +1 -1
- package/dist/interfaces/chat/chat.interfaces.d.ts +3 -3
- package/dist/interfaces/folder/folder.interfaces.d.ts +1 -1
- package/dist/interfaces/message/message.interfaces.d.ts +2 -2
- package/dist/interfaces/study/study.interfaces.d.ts +2 -2
- package/dist/interfaces/user/user.interfaces.d.ts +1 -1
- package/dist/interfaces/user-push-notification-token/user-push-notification-token.interfaces.d.ts +1 -1
- package/dist/interfaces/video/video.interfaces.d.ts +2 -2
- package/package.json +1 -1
|
@@ -20,19 +20,25 @@ class ChatDAO {
|
|
|
20
20
|
}
|
|
21
21
|
create(item) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const [result] = yield this._knex(
|
|
23
|
+
const [result] = yield this._knex('chat')
|
|
24
|
+
.insert(item)
|
|
25
|
+
.returning('*');
|
|
24
26
|
return result;
|
|
25
27
|
});
|
|
26
28
|
}
|
|
27
29
|
getById(id) {
|
|
28
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
const result = yield this._knex(
|
|
31
|
+
const result = yield this._knex('chat')
|
|
32
|
+
.where('id', id)
|
|
33
|
+
.first();
|
|
30
34
|
return result || null;
|
|
31
35
|
});
|
|
32
36
|
}
|
|
33
37
|
getByUuid(uuid) {
|
|
34
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
const result = yield this._knex(
|
|
39
|
+
const result = yield this._knex('chat')
|
|
40
|
+
.where('uuid', uuid)
|
|
41
|
+
.first();
|
|
36
42
|
return result || null;
|
|
37
43
|
});
|
|
38
44
|
}
|
|
@@ -40,11 +46,11 @@ class ChatDAO {
|
|
|
40
46
|
return __awaiter(this, arguments, void 0, function* (page = 1, limit = 10) {
|
|
41
47
|
const offset = (page - 1) * limit;
|
|
42
48
|
const [results, [{ count }]] = yield Promise.all([
|
|
43
|
-
this._knex(
|
|
44
|
-
.orderBy(
|
|
49
|
+
this._knex('chat')
|
|
50
|
+
.orderBy('created_at', 'desc')
|
|
45
51
|
.limit(limit)
|
|
46
52
|
.offset(offset),
|
|
47
|
-
this._knex(
|
|
53
|
+
this._knex('chat').count('* as count')
|
|
48
54
|
]);
|
|
49
55
|
const totalCount = parseInt(count);
|
|
50
56
|
return {
|
|
@@ -54,22 +60,24 @@ class ChatDAO {
|
|
|
54
60
|
limit,
|
|
55
61
|
count: results.length,
|
|
56
62
|
totalCount,
|
|
57
|
-
totalPages: Math.ceil(totalCount / limit)
|
|
63
|
+
totalPages: Math.ceil(totalCount / limit)
|
|
58
64
|
};
|
|
59
65
|
});
|
|
60
66
|
}
|
|
61
67
|
update(id, item) {
|
|
62
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
const [result] = yield this._knex(
|
|
64
|
-
.where(
|
|
69
|
+
const [result] = yield this._knex('chat')
|
|
70
|
+
.where('id', id)
|
|
65
71
|
.update(Object.assign(Object.assign({}, item), { updated_at: new Date() }))
|
|
66
|
-
.returning(
|
|
72
|
+
.returning('*');
|
|
67
73
|
return result || null;
|
|
68
74
|
});
|
|
69
75
|
}
|
|
70
76
|
delete(id) {
|
|
71
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
const result = yield this._knex(
|
|
78
|
+
const result = yield this._knex('chat')
|
|
79
|
+
.where('id', id)
|
|
80
|
+
.delete();
|
|
73
81
|
return result > 0;
|
|
74
82
|
});
|
|
75
83
|
}
|
|
@@ -77,12 +85,14 @@ class ChatDAO {
|
|
|
77
85
|
return __awaiter(this, arguments, void 0, function* (userId, page = 1, limit = 10) {
|
|
78
86
|
const offset = (page - 1) * limit;
|
|
79
87
|
const [results, [{ count }]] = yield Promise.all([
|
|
80
|
-
this._knex(
|
|
81
|
-
.where(
|
|
82
|
-
.orderBy(
|
|
88
|
+
this._knex('chat')
|
|
89
|
+
.where('userId', userId)
|
|
90
|
+
.orderBy('created_at', 'desc')
|
|
83
91
|
.limit(limit)
|
|
84
92
|
.offset(offset),
|
|
85
|
-
this._knex(
|
|
93
|
+
this._knex('chat')
|
|
94
|
+
.where('userId', userId)
|
|
95
|
+
.count('* as count')
|
|
86
96
|
]);
|
|
87
97
|
const totalCount = parseInt(count);
|
|
88
98
|
return {
|
|
@@ -92,7 +102,7 @@ class ChatDAO {
|
|
|
92
102
|
limit,
|
|
93
103
|
count: results.length,
|
|
94
104
|
totalCount,
|
|
95
|
-
totalPages: Math.ceil(totalCount / limit)
|
|
105
|
+
totalPages: Math.ceil(totalCount / limit)
|
|
96
106
|
};
|
|
97
107
|
});
|
|
98
108
|
}
|
|
@@ -100,22 +110,25 @@ class ChatDAO {
|
|
|
100
110
|
return __awaiter(this, arguments, void 0, function* (userId, page = 1, limit = 10, query) {
|
|
101
111
|
const offset = (page - 1) * limit;
|
|
102
112
|
// Build data query
|
|
103
|
-
let dataQuery = this._knex(
|
|
104
|
-
.where(
|
|
105
|
-
.where(
|
|
113
|
+
let dataQuery = this._knex('chat')
|
|
114
|
+
.where('userId', userId)
|
|
115
|
+
.where('status', 'active');
|
|
106
116
|
// Build count query
|
|
107
|
-
let countQuery = this._knex(
|
|
108
|
-
.where(
|
|
109
|
-
.where(
|
|
117
|
+
let countQuery = this._knex('chat')
|
|
118
|
+
.where('userId', userId)
|
|
119
|
+
.where('status', 'active');
|
|
110
120
|
// Apply search filter if query is provided
|
|
111
121
|
if (query && query.trim()) {
|
|
112
122
|
const searchTerm = `%${query.trim()}%`;
|
|
113
|
-
dataQuery = dataQuery.where(
|
|
114
|
-
countQuery = countQuery.where(
|
|
123
|
+
dataQuery = dataQuery.where('title', 'ILIKE', searchTerm);
|
|
124
|
+
countQuery = countQuery.where('title', 'ILIKE', searchTerm);
|
|
115
125
|
}
|
|
116
126
|
const [results, [{ count }]] = yield Promise.all([
|
|
117
|
-
dataQuery
|
|
118
|
-
|
|
127
|
+
dataQuery
|
|
128
|
+
.orderBy('created_at', 'desc')
|
|
129
|
+
.limit(limit)
|
|
130
|
+
.offset(offset),
|
|
131
|
+
countQuery.count('* as count')
|
|
119
132
|
]);
|
|
120
133
|
const totalCount = parseInt(count);
|
|
121
134
|
const totalPages = Math.ceil(totalCount / limit);
|
|
@@ -128,7 +141,7 @@ class ChatDAO {
|
|
|
128
141
|
count: results.length,
|
|
129
142
|
totalCount,
|
|
130
143
|
totalPages,
|
|
131
|
-
hasMore
|
|
144
|
+
hasMore
|
|
132
145
|
};
|
|
133
146
|
});
|
|
134
147
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.dao.js","sourceRoot":"","sources":["../../../src/dao/chat/chat.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"chat.dao.js","sourceRoot":"","sources":["../../../src/dao/chat/chat.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAGA,0EAA+C;AAM/C,MAAa,OAAO;IAApB;QACU,UAAK,GAAyB,wBAAW,CAAC,aAAa,EAAE,CAAC;IAqIpE,CAAC;IAnIO,MAAM,CAAC,IAAiB;;YAC5B,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;iBACtC,MAAM,CAAC,IAAI,CAAC;iBACZ,SAAS,CAAC,GAAG,CAAC,CAAC;YAClB,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;IAEK,OAAO,CAAC,EAAU;;YACtB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;iBACpC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;iBACf,KAAK,EAAE,CAAC;YACX,OAAO,MAAM,IAAI,IAAI,CAAC;QACxB,CAAC;KAAA;IAEK,SAAS,CAAC,IAAY;;YAC1B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;iBACpC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC;iBACnB,KAAK,EAAE,CAAC;YACX,OAAO,MAAM,IAAI,IAAI,CAAC;QACxB,CAAC;KAAA;IA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 class FolderDAO {
|
|
|
20
20
|
}
|
|
21
21
|
create(item) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const [createdFolder] = yield this._knex("folders")
|
|
24
|
-
.insert(item)
|
|
25
|
-
.returning("*");
|
|
23
|
+
const [createdFolder] = yield this._knex("folders").insert(item).returning("*");
|
|
26
24
|
return createdFolder;
|
|
27
25
|
});
|
|
28
26
|
}
|
|
@@ -48,10 +46,7 @@ class FolderDAO {
|
|
|
48
46
|
}
|
|
49
47
|
update(id, item) {
|
|
50
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
const [updatedFolder] = yield this._knex("folders")
|
|
52
|
-
.where({ id })
|
|
53
|
-
.update(item)
|
|
54
|
-
.returning("*");
|
|
49
|
+
const [updatedFolder] = yield this._knex("folders").where({ id }).update(item).returning("*");
|
|
55
50
|
return updatedFolder || null;
|
|
56
51
|
});
|
|
57
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"folder.dao.js","sourceRoot":"","sources":["../../../src/dao/folder/folder.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAGA,0EAA+C;AAE/C,MAAa,SAAS;IAAtB;
|
|
1
|
+
{"version":3,"file":"folder.dao.js","sourceRoot":"","sources":["../../../src/dao/folder/folder.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAGA,0EAA+C;AAE/C,MAAa,SAAS;IAAtB;QACY,UAAK,GAAyB,wBAAW,CAAC,aAAa,EAAE,CAAC;IAiEtE,CAAC;IA/DS,MAAM,CAAC,IAAa;;YACtB,MAAM,CAAC,aAAa,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YAChF,OAAO,aAAa,CAAC;QACzB,CAAC;KAAA;IAEK,OAAO,CAAC,EAAU;;YACpB,MAAM,MAAM,GAAG,MAAM,IAAI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AAC,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;YAElC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC;iBACnC,SAAS,CAAC,YAAY,EAAE,WAAW,EAAE,MAAM,CAAC;iBAC5C,QAAQ,CAAC,gBAAgB,EAAE,cAAc,EAAE,MAAM,CAAC;iBAClD,MAAM,CACH,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,wBAAwB,CAAC,EACxC,wBAAwB,EACxB,wBAAwB,CAC3B,CAAC;YACN,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;gBAC5C,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;YACtC,CAAC;YAED,MAAM,CAAC,WAAW,CAAC,GAAG,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YAC5E,MAAM,UAAU,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC;YACtC,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAEhE,OAAO;gBACH,OAAO,EAAE,IAAI;gBACb,IAAI,EAAE,OAAO;gBACb,IAAI;gBACJ,KAAK;gBACL,KAAK,EAAE,OAAO,CAAC,MAAM;gBACrB,UAAU;gBACV,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;aAC5C,CAAC;QACN,CAAC;KAAA;CACJ;AAlED,8BAkEC"}
|
|
@@ -20,9 +20,7 @@ class LocationDAO {
|
|
|
20
20
|
}
|
|
21
21
|
create(item) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const [createdLocation] = yield this._knex("locations")
|
|
24
|
-
.insert(item)
|
|
25
|
-
.returning("*");
|
|
23
|
+
const [createdLocation] = yield this._knex("locations").insert(item).returning("*");
|
|
26
24
|
return createdLocation;
|
|
27
25
|
});
|
|
28
26
|
}
|
|
@@ -40,10 +38,7 @@ class LocationDAO {
|
|
|
40
38
|
}
|
|
41
39
|
update(id, item) {
|
|
42
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
const [updatedLocation] = yield this._knex("locations")
|
|
44
|
-
.where({ id })
|
|
45
|
-
.update(item)
|
|
46
|
-
.returning("*");
|
|
41
|
+
const [updatedLocation] = yield this._knex("locations").where({ id }).update(item).returning("*");
|
|
47
42
|
return updatedLocation || null;
|
|
48
43
|
});
|
|
49
44
|
}
|
|
@@ -80,11 +75,13 @@ class LocationDAO {
|
|
|
80
75
|
return __awaiter(this, arguments, void 0, function* (longitude, latitude, radiusKm = 1) {
|
|
81
76
|
// Using ST_DWithin for geographic distance calculation
|
|
82
77
|
// This is a PostgreSQL-specific query for geospatial operations
|
|
83
|
-
const locations = yield this._knex("locations")
|
|
78
|
+
const locations = yield this._knex("locations")
|
|
79
|
+
.whereRaw(`ST_DWithin(
|
|
84
80
|
ST_MakePoint(longitude, latitude)::geography,
|
|
85
81
|
ST_MakePoint(?, ?)::geography,
|
|
86
82
|
?
|
|
87
|
-
)`, [longitude, latitude, radiusKm * 1000]
|
|
83
|
+
)`, [longitude, latitude, radiusKm * 1000] // Convert km to meters
|
|
84
|
+
);
|
|
88
85
|
return locations;
|
|
89
86
|
});
|
|
90
87
|
}
|
|
@@ -97,16 +94,12 @@ class LocationDAO {
|
|
|
97
94
|
let query = this._knex("locations");
|
|
98
95
|
// Apply search filter if name provided (escape special chars to prevent pattern injection)
|
|
99
96
|
if (name && name.trim().length > 0) {
|
|
100
|
-
const escapedName = name.trim().replace(/[%_\\]/g,
|
|
101
|
-
query = query.where(
|
|
97
|
+
const escapedName = name.trim().replace(/[%_\\]/g, '\\$&');
|
|
98
|
+
query = query.where('name', 'ilike', `%${escapedName}%`);
|
|
102
99
|
}
|
|
103
100
|
const [countResult] = yield query.clone().count("* as count");
|
|
104
101
|
const totalCount = +countResult.count;
|
|
105
|
-
const locations = yield query
|
|
106
|
-
.clone()
|
|
107
|
-
.limit(limit)
|
|
108
|
-
.offset(offset)
|
|
109
|
-
.orderBy("name", "asc");
|
|
102
|
+
const locations = yield query.clone().limit(limit).offset(offset).orderBy('name', 'asc');
|
|
110
103
|
return {
|
|
111
104
|
success: true,
|
|
112
105
|
data: locations,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"location.dao.js","sourceRoot":"","sources":["../../../src/dao/location/location.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAIA,0EAA+C;AAE/C,MAAa,WAAW;IAAxB;
|
|
1
|
+
{"version":3,"file":"location.dao.js","sourceRoot":"","sources":["../../../src/dao/location/location.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAIA,0EAA+C;AAE/C,MAAa,WAAW;IAAxB;QACY,UAAK,GAAyB,wBAAW,CAAC,aAAa,EAAE,CAAC;IA6FtE,CAAC;IA3FS,MAAM,CAAC,IAAe;;YACxB,MAAM,CAAC,eAAe,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACpF,OAAO,eAAe,CAAC;QAC3B,CAAC;KAAA;IAEK,OAAO,CAAC,EAAU;;YACpB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;YACrE,OAAO,QAAQ,IAAI,IAAI,CAAC;QAC5B,CAAC;KAAA;IAEK,SAAS,CAAC,IAAY;;YACxB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;Y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AAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YAEzF,OAAO;gBACH,OAAO,EAAE,IAAI;gBACb,IAAI,EAAE,SAAS;gBACf,IAAI;gBACJ,KAAK;gBACL,KAAK,EAAE,SAAS,CAAC,MAAM;gBACvB,UAAU;gBACV,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;aAC5C,CAAC;QACN,CAAC;KAAA;CACJ;AA9FD,kCA8FC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IBaseDAO, IDataPaginator } from "../../d.types";
|
|
2
|
-
import { IMessage, IMessageCreate, IMessageUpdate } from
|
|
2
|
+
import { IMessage, IMessageCreate, IMessageUpdate } from '../../interfaces/message/message.interfaces';
|
|
3
3
|
export declare class MessageDAO implements IBaseDAO<IMessage> {
|
|
4
4
|
private _knex;
|
|
5
5
|
create(item: IMessageCreate): Promise<IMessage>;
|
|
@@ -20,13 +20,17 @@ class MessageDAO {
|
|
|
20
20
|
}
|
|
21
21
|
create(item) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const [result] = yield this._knex(
|
|
23
|
+
const [result] = yield this._knex('message')
|
|
24
|
+
.insert(item)
|
|
25
|
+
.returning('*');
|
|
24
26
|
return result;
|
|
25
27
|
});
|
|
26
28
|
}
|
|
27
29
|
getById(id) {
|
|
28
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
const result = yield this._knex(
|
|
31
|
+
const result = yield this._knex('message')
|
|
32
|
+
.where('id', id)
|
|
33
|
+
.first();
|
|
30
34
|
return result || null;
|
|
31
35
|
});
|
|
32
36
|
}
|
|
@@ -40,11 +44,11 @@ class MessageDAO {
|
|
|
40
44
|
return __awaiter(this, arguments, void 0, function* (page = 1, limit = 10) {
|
|
41
45
|
const offset = (page - 1) * limit;
|
|
42
46
|
const [results, [{ count }]] = yield Promise.all([
|
|
43
|
-
this._knex(
|
|
44
|
-
.orderBy(
|
|
47
|
+
this._knex('message')
|
|
48
|
+
.orderBy('created_at', 'asc')
|
|
45
49
|
.limit(limit)
|
|
46
50
|
.offset(offset),
|
|
47
|
-
this._knex(
|
|
51
|
+
this._knex('message').count('* as count')
|
|
48
52
|
]);
|
|
49
53
|
const totalCount = parseInt(count);
|
|
50
54
|
return {
|
|
@@ -54,22 +58,24 @@ class MessageDAO {
|
|
|
54
58
|
limit,
|
|
55
59
|
count: results.length,
|
|
56
60
|
totalCount,
|
|
57
|
-
totalPages: Math.ceil(totalCount / limit)
|
|
61
|
+
totalPages: Math.ceil(totalCount / limit)
|
|
58
62
|
};
|
|
59
63
|
});
|
|
60
64
|
}
|
|
61
65
|
update(id, item) {
|
|
62
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
const [result] = yield this._knex(
|
|
64
|
-
.where(
|
|
67
|
+
const [result] = yield this._knex('message')
|
|
68
|
+
.where('id', id)
|
|
65
69
|
.update(Object.assign(Object.assign({}, item), { updated_at: new Date() }))
|
|
66
|
-
.returning(
|
|
70
|
+
.returning('*');
|
|
67
71
|
return result || null;
|
|
68
72
|
});
|
|
69
73
|
}
|
|
70
74
|
delete(id) {
|
|
71
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
const result = yield this._knex(
|
|
76
|
+
const result = yield this._knex('message')
|
|
77
|
+
.where('id', id)
|
|
78
|
+
.delete();
|
|
73
79
|
return result > 0;
|
|
74
80
|
});
|
|
75
81
|
}
|
|
@@ -77,12 +83,14 @@ class MessageDAO {
|
|
|
77
83
|
return __awaiter(this, arguments, void 0, function* (chatId, page = 1, limit = 50) {
|
|
78
84
|
const offset = (page - 1) * limit;
|
|
79
85
|
const [results, [{ count }]] = yield Promise.all([
|
|
80
|
-
this._knex(
|
|
81
|
-
.where(
|
|
82
|
-
.orderBy(
|
|
86
|
+
this._knex('message')
|
|
87
|
+
.where('chatId', chatId)
|
|
88
|
+
.orderBy('created_at', 'asc')
|
|
83
89
|
.limit(limit)
|
|
84
90
|
.offset(offset),
|
|
85
|
-
this._knex(
|
|
91
|
+
this._knex('message')
|
|
92
|
+
.where('chatId', chatId)
|
|
93
|
+
.count('* as count')
|
|
86
94
|
]);
|
|
87
95
|
const totalCount = parseInt(count);
|
|
88
96
|
return {
|
|
@@ -92,15 +100,15 @@ class MessageDAO {
|
|
|
92
100
|
limit,
|
|
93
101
|
count: results.length,
|
|
94
102
|
totalCount,
|
|
95
|
-
totalPages: Math.ceil(totalCount / limit)
|
|
103
|
+
totalPages: Math.ceil(totalCount / limit)
|
|
96
104
|
};
|
|
97
105
|
});
|
|
98
106
|
}
|
|
99
107
|
getLatestMessages(chatId_1) {
|
|
100
108
|
return __awaiter(this, arguments, void 0, function* (chatId, limit = 50) {
|
|
101
|
-
return yield this._knex(
|
|
102
|
-
.where(
|
|
103
|
-
.orderBy(
|
|
109
|
+
return yield this._knex('message')
|
|
110
|
+
.where('chatId', chatId)
|
|
111
|
+
.orderBy('created_at', 'desc')
|
|
104
112
|
.limit(limit)
|
|
105
113
|
.then((messages) => messages.reverse());
|
|
106
114
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.dao.js","sourceRoot":"","sources":["../../../src/dao/message/message.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"message.dao.js","sourceRoot":"","sources":["../../../src/dao/message/message.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAGA,0EAA+C;AAE/C,MAAa,UAAU;IAAvB;QACU,UAAK,GAAyB,wBAAW,CAAC,aAAa,EAAE,CAAC;IA+FpE,CAAC;IA7FO,MAAM,CAAC,IAAoB;;YAC/B,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;iBACzC,MAAM,CAAC,IAAI,CAAC;iBACZ,SAAS,CAAC,GAAG,CAAC,CAAC;YAClB,OAAO,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C1C,CAAC;QACJ,CAAC;KAAA;IAEK,iBAAiB;6DAAC,MAAc,EAAE,KAAK,GAAG,EAAE;YAChD,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;iBAC/B,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC;iBACvB,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC;iBAC7B,KAAK,CAAC,KAAK,CAAC;iBACZ,IAAI,CAAC,CAAC,QAAoB,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;QACxD,CAAC;KAAA;CACF;AAhGD,gCAgGC"}
|
|
@@ -29,14 +29,14 @@ const KnexConnection_1 = __importDefault(require("../../KnexConnection"));
|
|
|
29
29
|
* Non-motorized vehicles (pedestrian, bicycle, non_motorized_vehicle) are EXCLUDED
|
|
30
30
|
*/
|
|
31
31
|
const DETECTION_LABEL_TO_FHWA = {
|
|
32
|
-
motorcycle: [1],
|
|
33
|
-
car: [2],
|
|
34
|
-
pickup_truck: [3],
|
|
35
|
-
motorized_vehicle: [3], // Maps to Class 3 (same as pickup_truck)
|
|
36
|
-
bus: [4],
|
|
37
|
-
work_van: [5],
|
|
38
|
-
single_unit_truck: [6, 7, 8], // Classes 6-8
|
|
39
|
-
articulated_truck: [9, 10, 11, 12, 13]
|
|
32
|
+
'motorcycle': [1],
|
|
33
|
+
'car': [2],
|
|
34
|
+
'pickup_truck': [3],
|
|
35
|
+
'motorized_vehicle': [3], // Maps to Class 3 (same as pickup_truck)
|
|
36
|
+
'bus': [4],
|
|
37
|
+
'work_van': [5],
|
|
38
|
+
'single_unit_truck': [6, 7, 8], // Classes 6-8
|
|
39
|
+
'articulated_truck': [9, 10, 11, 12, 13] // Classes 9-13
|
|
40
40
|
// pedestrian, bicycle, non_motorized_vehicle are EXCLUDED
|
|
41
41
|
};
|
|
42
42
|
class ReportConfigurationDAO {
|
|
@@ -52,13 +52,13 @@ class ReportConfigurationDAO {
|
|
|
52
52
|
// Validate configuration before creating
|
|
53
53
|
const validation = this.validateConfiguration(item.configuration);
|
|
54
54
|
if (!validation.valid) {
|
|
55
|
-
throw new Error(`Invalid configuration: ${validation.errors.join(
|
|
55
|
+
throw new Error(`Invalid configuration: ${validation.errors.join(', ')}`);
|
|
56
56
|
}
|
|
57
57
|
const [createdConfig] = yield this._knex(this.tableName)
|
|
58
58
|
.insert({
|
|
59
59
|
name: item.name,
|
|
60
60
|
description: item.description,
|
|
61
|
-
configuration: JSON.stringify(item.configuration)
|
|
61
|
+
configuration: JSON.stringify(item.configuration)
|
|
62
62
|
})
|
|
63
63
|
.returning("*");
|
|
64
64
|
return this._deserialize(createdConfig);
|
|
@@ -102,7 +102,7 @@ class ReportConfigurationDAO {
|
|
|
102
102
|
if (item.configuration) {
|
|
103
103
|
const validation = this.validateConfiguration(item.configuration);
|
|
104
104
|
if (!validation.valid) {
|
|
105
|
-
throw new Error(`Invalid configuration: ${validation.errors.join(
|
|
105
|
+
throw new Error(`Invalid configuration: ${validation.errors.join(', ')}`);
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
const updateData = {};
|
|
@@ -126,9 +126,9 @@ class ReportConfigurationDAO {
|
|
|
126
126
|
delete(id) {
|
|
127
127
|
return __awaiter(this, void 0, void 0, function* () {
|
|
128
128
|
// Count total configurations
|
|
129
|
-
const [{ count }] = yield this._knex(this.tableName).count(
|
|
129
|
+
const [{ count }] = yield this._knex(this.tableName).count('* as count');
|
|
130
130
|
if (parseInt(count) <= 1) {
|
|
131
|
-
throw new Error(
|
|
131
|
+
throw new Error('Cannot delete the last configuration. At least one configuration must exist.');
|
|
132
132
|
}
|
|
133
133
|
const result = yield this._knex(this.tableName).where({ id }).del();
|
|
134
134
|
return result > 0;
|
|
@@ -148,7 +148,7 @@ class ReportConfigurationDAO {
|
|
|
148
148
|
.orderBy("created_at", "desc");
|
|
149
149
|
return {
|
|
150
150
|
success: true,
|
|
151
|
-
data: configs.map(
|
|
151
|
+
data: configs.map(c => this._deserialize(c)),
|
|
152
152
|
page,
|
|
153
153
|
limit,
|
|
154
154
|
count: configs.length,
|
|
@@ -171,19 +171,19 @@ class ReportConfigurationDAO {
|
|
|
171
171
|
const errors = [];
|
|
172
172
|
// Validate version exists
|
|
173
173
|
if (!config.version) {
|
|
174
|
-
errors.push(
|
|
174
|
+
errors.push('Configuration version is required');
|
|
175
175
|
}
|
|
176
176
|
// Validate custom classes array
|
|
177
177
|
if (!config.customClasses || !Array.isArray(config.customClasses)) {
|
|
178
|
-
errors.push(
|
|
178
|
+
errors.push('customClasses must be an array');
|
|
179
179
|
return { valid: false, errors };
|
|
180
180
|
}
|
|
181
181
|
// Min 2, max 7 custom classes
|
|
182
182
|
if (config.customClasses.length < 2) {
|
|
183
|
-
errors.push(
|
|
183
|
+
errors.push('Minimum 2 custom classes required');
|
|
184
184
|
}
|
|
185
185
|
if (config.customClasses.length > 7) {
|
|
186
|
-
errors.push(
|
|
186
|
+
errors.push('Maximum 7 custom classes allowed');
|
|
187
187
|
}
|
|
188
188
|
// Check name length (max 30 chars) and FHWA classes validity
|
|
189
189
|
const allFhwaClasses = [];
|
|
@@ -191,7 +191,7 @@ class ReportConfigurationDAO {
|
|
|
191
191
|
if (!cls.name || cls.name.length === 0) {
|
|
192
192
|
errors.push(`Custom class ${idx + 1}: name cannot be empty`);
|
|
193
193
|
}
|
|
194
|
-
if (cls.name && cls.name.toLowerCase() ===
|
|
194
|
+
if (cls.name && cls.name.toLowerCase() === 'total') {
|
|
195
195
|
errors.push(`Custom class ${idx + 1}: "Total" is a reserved name and cannot be used`);
|
|
196
196
|
}
|
|
197
197
|
if (cls.name && cls.name.length > 30) {
|
|
@@ -201,7 +201,7 @@ class ReportConfigurationDAO {
|
|
|
201
201
|
errors.push(`Custom class ${idx + 1}: must have at least one FHWA class`);
|
|
202
202
|
}
|
|
203
203
|
else {
|
|
204
|
-
cls.fhwaClasses.forEach(
|
|
204
|
+
cls.fhwaClasses.forEach(fhwa => {
|
|
205
205
|
if (!Number.isInteger(fhwa) || fhwa < 1 || fhwa > 13) {
|
|
206
206
|
errors.push(`Custom class ${idx + 1}: FHWA class ${fhwa} is invalid (must be 1-13)`);
|
|
207
207
|
}
|
|
@@ -213,7 +213,7 @@ class ReportConfigurationDAO {
|
|
|
213
213
|
const uniqueFhwaClasses = new Set(allFhwaClasses);
|
|
214
214
|
if (uniqueFhwaClasses.size !== allFhwaClasses.length) {
|
|
215
215
|
const duplicates = allFhwaClasses.filter((item, index) => allFhwaClasses.indexOf(item) !== index);
|
|
216
|
-
errors.push(`Duplicate FHWA classes detected: ${[...new Set(duplicates)].join(
|
|
216
|
+
errors.push(`Duplicate FHWA classes detected: ${[...new Set(duplicates)].join(', ')}. Each FHWA class can only be mapped to one custom class.`);
|
|
217
217
|
}
|
|
218
218
|
return { valid: errors.length === 0, errors };
|
|
219
219
|
}
|
|
@@ -236,18 +236,17 @@ class ReportConfigurationDAO {
|
|
|
236
236
|
for (const [label, count] of Object.entries(detectionResults)) {
|
|
237
237
|
const fhwaClasses = DETECTION_LABEL_TO_FHWA[label];
|
|
238
238
|
if (fhwaClasses && fhwaClasses.length > 0) {
|
|
239
|
-
fhwaClasses.forEach(
|
|
240
|
-
fhwaClassCounts[fhwaClass] =
|
|
241
|
-
(fhwaClassCounts[fhwaClass] || 0) + count;
|
|
239
|
+
fhwaClasses.forEach(fhwaClass => {
|
|
240
|
+
fhwaClassCounts[fhwaClass] = (fhwaClassCounts[fhwaClass] || 0) + count;
|
|
242
241
|
});
|
|
243
242
|
}
|
|
244
243
|
// Labels not in DETECTION_LABEL_TO_FHWA are silently ignored (e.g., pedestrian, bicycle)
|
|
245
244
|
}
|
|
246
245
|
// Step 2: FHWA classes → Custom classes
|
|
247
246
|
const customClassCounts = {};
|
|
248
|
-
config.configuration.customClasses.forEach(
|
|
247
|
+
config.configuration.customClasses.forEach(customClass => {
|
|
249
248
|
let total = 0;
|
|
250
|
-
customClass.fhwaClasses.forEach(
|
|
249
|
+
customClass.fhwaClasses.forEach(fhwaClass => {
|
|
251
250
|
total += fhwaClassCounts[fhwaClass] || 0;
|
|
252
251
|
});
|
|
253
252
|
customClassCounts[customClass.name] = total;
|
|
@@ -312,15 +311,15 @@ class ReportConfigurationDAO {
|
|
|
312
311
|
*/
|
|
313
312
|
_deepMergeNumericData(target, source) {
|
|
314
313
|
// Base case: if source is a number, add it to target
|
|
315
|
-
if (typeof source ===
|
|
316
|
-
return (typeof target ===
|
|
314
|
+
if (typeof source === 'number') {
|
|
315
|
+
return (typeof target === 'number' ? target : 0) + source;
|
|
317
316
|
}
|
|
318
317
|
// If source is not an object, return target unchanged
|
|
319
|
-
if (typeof source !==
|
|
318
|
+
if (typeof source !== 'object' || source === null) {
|
|
320
319
|
return target;
|
|
321
320
|
}
|
|
322
321
|
// Ensure target is an object
|
|
323
|
-
if (typeof target !==
|
|
322
|
+
if (typeof target !== 'object' || target === null) {
|
|
324
323
|
target = {};
|
|
325
324
|
}
|
|
326
325
|
// Recursively merge each key in source
|
|
@@ -359,11 +358,11 @@ class ReportConfigurationDAO {
|
|
|
359
358
|
uuid: row.uuid,
|
|
360
359
|
name: row.name,
|
|
361
360
|
description: row.description,
|
|
362
|
-
configuration: typeof row.configuration ===
|
|
361
|
+
configuration: typeof row.configuration === 'string'
|
|
363
362
|
? JSON.parse(row.configuration)
|
|
364
363
|
: row.configuration,
|
|
365
364
|
created_at: row.created_at,
|
|
366
|
-
updated_at: row.updated_at
|
|
365
|
+
updated_at: row.updated_at
|
|
367
366
|
};
|
|
368
367
|
}
|
|
369
368
|
}
|