@trafficgroup/knex-rel 0.1.10 → 0.1.11-rc0
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 +9 -5
- package/dist/constants/video.constants.js.map +1 -1
- package/dist/dao/VideoMinuteResultDAO.d.ts +1 -1
- package/dist/dao/VideoMinuteResultDAO.js +29 -23
- package/dist/dao/VideoMinuteResultDAO.js.map +1 -1
- package/dist/dao/auth/auth.dao.js +4 -1
- package/dist/dao/auth/auth.dao.js.map +1 -1
- package/dist/dao/batch/batch.dao.js +13 -14
- package/dist/dao/batch/batch.dao.js.map +1 -1
- package/dist/dao/camera/camera.dao.js +10 -7
- package/dist/dao/camera/camera.dao.js.map +1 -1
- package/dist/dao/chat/chat.dao.d.ts +5 -2
- package/dist/dao/chat/chat.dao.js +37 -38
- package/dist/dao/chat/chat.dao.js.map +1 -1
- package/dist/dao/folder/folder.dao.js +7 -2
- package/dist/dao/folder/folder.dao.js.map +1 -1
- package/dist/dao/location/location.dao.js +16 -9
- 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 +18 -26
- package/dist/dao/message/message.dao.js.map +1 -1
- package/dist/dao/report-configuration/report-configuration.dao.js +32 -31
- package/dist/dao/report-configuration/report-configuration.dao.js.map +1 -1
- package/dist/dao/study/study.dao.js +7 -2
- package/dist/dao/study/study.dao.js.map +1 -1
- package/dist/dao/user/user.dao.js +4 -1
- package/dist/dao/user/user.dao.js.map +1 -1
- package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js +26 -8
- package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js.map +1 -1
- package/dist/dao/video/video.dao.js +30 -28
- package/dist/dao/video/video.dao.js.map +1 -1
- package/dist/index.d.ts +6 -6
- 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
- package/src/dao/chat/chat.dao.ts +32 -12
- package/src/index.ts +1 -1
- package/.env.prod +0 -5
|
@@ -20,25 +20,19 @@ class ChatDAO {
|
|
|
20
20
|
}
|
|
21
21
|
create(item) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const [result] = yield this._knex(
|
|
24
|
-
.insert(item)
|
|
25
|
-
.returning('*');
|
|
23
|
+
const [result] = yield this._knex("chat").insert(item).returning("*");
|
|
26
24
|
return result;
|
|
27
25
|
});
|
|
28
26
|
}
|
|
29
27
|
getById(id) {
|
|
30
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
const result = yield this._knex(
|
|
32
|
-
.where('id', id)
|
|
33
|
-
.first();
|
|
29
|
+
const result = yield this._knex("chat").where("id", id).first();
|
|
34
30
|
return result || null;
|
|
35
31
|
});
|
|
36
32
|
}
|
|
37
33
|
getByUuid(uuid) {
|
|
38
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
const result = yield this._knex(
|
|
40
|
-
.where('uuid', uuid)
|
|
41
|
-
.first();
|
|
35
|
+
const result = yield this._knex("chat").where("uuid", uuid).first();
|
|
42
36
|
return result || null;
|
|
43
37
|
});
|
|
44
38
|
}
|
|
@@ -46,11 +40,11 @@ class ChatDAO {
|
|
|
46
40
|
return __awaiter(this, arguments, void 0, function* (page = 1, limit = 10) {
|
|
47
41
|
const offset = (page - 1) * limit;
|
|
48
42
|
const [results, [{ count }]] = yield Promise.all([
|
|
49
|
-
this._knex(
|
|
50
|
-
.orderBy(
|
|
43
|
+
this._knex("chat")
|
|
44
|
+
.orderBy("created_at", "desc")
|
|
51
45
|
.limit(limit)
|
|
52
46
|
.offset(offset),
|
|
53
|
-
this._knex(
|
|
47
|
+
this._knex("chat").count("* as count"),
|
|
54
48
|
]);
|
|
55
49
|
const totalCount = parseInt(count);
|
|
56
50
|
return {
|
|
@@ -60,24 +54,22 @@ class ChatDAO {
|
|
|
60
54
|
limit,
|
|
61
55
|
count: results.length,
|
|
62
56
|
totalCount,
|
|
63
|
-
totalPages: Math.ceil(totalCount / limit)
|
|
57
|
+
totalPages: Math.ceil(totalCount / limit),
|
|
64
58
|
};
|
|
65
59
|
});
|
|
66
60
|
}
|
|
67
61
|
update(id, item) {
|
|
68
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
const [result] = yield this._knex(
|
|
70
|
-
.where(
|
|
63
|
+
const [result] = yield this._knex("chat")
|
|
64
|
+
.where("id", id)
|
|
71
65
|
.update(Object.assign(Object.assign({}, item), { updated_at: new Date() }))
|
|
72
|
-
.returning(
|
|
66
|
+
.returning("*");
|
|
73
67
|
return result || null;
|
|
74
68
|
});
|
|
75
69
|
}
|
|
76
70
|
delete(id) {
|
|
77
71
|
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
const result = yield this._knex(
|
|
79
|
-
.where('id', id)
|
|
80
|
-
.delete();
|
|
72
|
+
const result = yield this._knex("chat").where("id", id).delete();
|
|
81
73
|
return result > 0;
|
|
82
74
|
});
|
|
83
75
|
}
|
|
@@ -85,14 +77,12 @@ class ChatDAO {
|
|
|
85
77
|
return __awaiter(this, arguments, void 0, function* (userId, page = 1, limit = 10) {
|
|
86
78
|
const offset = (page - 1) * limit;
|
|
87
79
|
const [results, [{ count }]] = yield Promise.all([
|
|
88
|
-
this._knex(
|
|
89
|
-
.where(
|
|
90
|
-
.orderBy(
|
|
80
|
+
this._knex("chat")
|
|
81
|
+
.where("userId", userId)
|
|
82
|
+
.orderBy("created_at", "desc")
|
|
91
83
|
.limit(limit)
|
|
92
84
|
.offset(offset),
|
|
93
|
-
this._knex(
|
|
94
|
-
.where('userId', userId)
|
|
95
|
-
.count('* as count')
|
|
85
|
+
this._knex("chat").where("userId", userId).count("* as count"),
|
|
96
86
|
]);
|
|
97
87
|
const totalCount = parseInt(count);
|
|
98
88
|
return {
|
|
@@ -102,26 +92,34 @@ class ChatDAO {
|
|
|
102
92
|
limit,
|
|
103
93
|
count: results.length,
|
|
104
94
|
totalCount,
|
|
105
|
-
totalPages: Math.ceil(totalCount / limit)
|
|
95
|
+
totalPages: Math.ceil(totalCount / limit),
|
|
106
96
|
};
|
|
107
97
|
});
|
|
108
98
|
}
|
|
109
99
|
getActiveByUserId(userId_1) {
|
|
110
|
-
return __awaiter(this, arguments, void 0, function* (userId, page = 1, limit = 10) {
|
|
100
|
+
return __awaiter(this, arguments, void 0, function* (userId, page = 1, limit = 10, query) {
|
|
111
101
|
const offset = (page - 1) * limit;
|
|
102
|
+
// Build data query
|
|
103
|
+
let dataQuery = this._knex("chat")
|
|
104
|
+
.where("userId", userId)
|
|
105
|
+
.where("status", "active");
|
|
106
|
+
// Build count query
|
|
107
|
+
let countQuery = this._knex("chat")
|
|
108
|
+
.where("userId", userId)
|
|
109
|
+
.where("status", "active");
|
|
110
|
+
// Apply search filter if query is provided
|
|
111
|
+
if (query && query.trim()) {
|
|
112
|
+
const searchTerm = `%${query.trim()}%`;
|
|
113
|
+
dataQuery = dataQuery.where("title", "ILIKE", searchTerm);
|
|
114
|
+
countQuery = countQuery.where("title", "ILIKE", searchTerm);
|
|
115
|
+
}
|
|
112
116
|
const [results, [{ count }]] = yield Promise.all([
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
.where('status', 'active')
|
|
116
|
-
.orderBy('created_at', 'desc')
|
|
117
|
-
.limit(limit)
|
|
118
|
-
.offset(offset),
|
|
119
|
-
this._knex('chat')
|
|
120
|
-
.where('userId', userId)
|
|
121
|
-
.where('status', 'active')
|
|
122
|
-
.count('* as count')
|
|
117
|
+
dataQuery.orderBy("created_at", "desc").limit(limit).offset(offset),
|
|
118
|
+
countQuery.count("* as count"),
|
|
123
119
|
]);
|
|
124
120
|
const totalCount = parseInt(count);
|
|
121
|
+
const totalPages = Math.ceil(totalCount / limit);
|
|
122
|
+
const hasMore = page < totalPages;
|
|
125
123
|
return {
|
|
126
124
|
success: true,
|
|
127
125
|
data: results,
|
|
@@ -129,7 +127,8 @@ class ChatDAO {
|
|
|
129
127
|
limit,
|
|
130
128
|
count: results.length,
|
|
131
129
|
totalCount,
|
|
132
|
-
totalPages
|
|
130
|
+
totalPages,
|
|
131
|
+
hasMore,
|
|
133
132
|
};
|
|
134
133
|
});
|
|
135
134
|
}
|
|
@@ -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":";;;;;;;;;;;;;;;AAOA,0EAA+C;AAM/C,MAAa,OAAO;IAApB;QACU,UAAK,GAAyB,wBAAW,CAAC,aAAa,EAAE,CAAC;IAiIpE,CAAC;IA/HO,MAAM,CAAC,IAAiB;;YAC5B,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACtE,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;IAEK,OAAO,CAAC,EAAU;;YACtB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;YAChE,OAAO,MAAM,IAAI,IAAI,CAAC;QAC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ACL,OAAO,EAAE,IAAI;gBACb,IAAI,EAAE,OAAO;gBACb,IAAI;gBACJ,KAAK;gBACL,KAAK,EAAE,OAAO,CAAC,MAAM;gBACrB,UAAU;gBACV,UAAU;gBACV,OAAO;aACR,CAAC;QACJ,CAAC;KAAA;CACF;AAlID,0BAkIC"}
|
|
@@ -20,7 +20,9 @@ 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")
|
|
23
|
+
const [createdFolder] = yield this._knex("folders")
|
|
24
|
+
.insert(item)
|
|
25
|
+
.returning("*");
|
|
24
26
|
return createdFolder;
|
|
25
27
|
});
|
|
26
28
|
}
|
|
@@ -46,7 +48,10 @@ class FolderDAO {
|
|
|
46
48
|
}
|
|
47
49
|
update(id, item) {
|
|
48
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
const [updatedFolder] = yield this._knex("folders")
|
|
51
|
+
const [updatedFolder] = yield this._knex("folders")
|
|
52
|
+
.where({ id })
|
|
53
|
+
.update(item)
|
|
54
|
+
.returning("*");
|
|
50
55
|
return updatedFolder || null;
|
|
51
56
|
});
|
|
52
57
|
}
|
|
@@ -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;QACU,UAAK,GAAyB,wBAAW,CAAC,aAAa,EAAE,CAAC;IA0EpE,CAAC;IAxEO,MAAM,CAAC,IAAa;;YACxB,MAAM,CAAC,aAAa,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK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-20,7 +20,9 @@ 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")
|
|
23
|
+
const [createdLocation] = yield this._knex("locations")
|
|
24
|
+
.insert(item)
|
|
25
|
+
.returning("*");
|
|
24
26
|
return createdLocation;
|
|
25
27
|
});
|
|
26
28
|
}
|
|
@@ -38,7 +40,10 @@ class LocationDAO {
|
|
|
38
40
|
}
|
|
39
41
|
update(id, item) {
|
|
40
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
const [updatedLocation] = yield this._knex("locations")
|
|
43
|
+
const [updatedLocation] = yield this._knex("locations")
|
|
44
|
+
.where({ id })
|
|
45
|
+
.update(item)
|
|
46
|
+
.returning("*");
|
|
42
47
|
return updatedLocation || null;
|
|
43
48
|
});
|
|
44
49
|
}
|
|
@@ -75,13 +80,11 @@ class LocationDAO {
|
|
|
75
80
|
return __awaiter(this, arguments, void 0, function* (longitude, latitude, radiusKm = 1) {
|
|
76
81
|
// Using ST_DWithin for geographic distance calculation
|
|
77
82
|
// This is a PostgreSQL-specific query for geospatial operations
|
|
78
|
-
const locations = yield this._knex("locations")
|
|
79
|
-
.whereRaw(`ST_DWithin(
|
|
83
|
+
const locations = yield this._knex("locations").whereRaw(`ST_DWithin(
|
|
80
84
|
ST_MakePoint(longitude, latitude)::geography,
|
|
81
85
|
ST_MakePoint(?, ?)::geography,
|
|
82
86
|
?
|
|
83
|
-
)`, [longitude, latitude, radiusKm * 1000]
|
|
84
|
-
);
|
|
87
|
+
)`, [longitude, latitude, radiusKm * 1000]);
|
|
85
88
|
return locations;
|
|
86
89
|
});
|
|
87
90
|
}
|
|
@@ -94,12 +97,16 @@ class LocationDAO {
|
|
|
94
97
|
let query = this._knex("locations");
|
|
95
98
|
// Apply search filter if name provided (escape special chars to prevent pattern injection)
|
|
96
99
|
if (name && name.trim().length > 0) {
|
|
97
|
-
const escapedName = name.trim().replace(/[%_\\]/g,
|
|
98
|
-
query = query.where(
|
|
100
|
+
const escapedName = name.trim().replace(/[%_\\]/g, "\\$&");
|
|
101
|
+
query = query.where("name", "ilike", `%${escapedName}%`);
|
|
99
102
|
}
|
|
100
103
|
const [countResult] = yield query.clone().count("* as count");
|
|
101
104
|
const totalCount = +countResult.count;
|
|
102
|
-
const locations = yield query
|
|
105
|
+
const locations = yield query
|
|
106
|
+
.clone()
|
|
107
|
+
.limit(limit)
|
|
108
|
+
.offset(offset)
|
|
109
|
+
.orderBy("name", "asc");
|
|
103
110
|
return {
|
|
104
111
|
success: true,
|
|
105
112
|
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;QACU,UAAK,GAAyB,wBAAW,CAAC,aAAa,EAAE,CAAC;IAmHpE,CAAC;IAjHO,MAAM,CAAC,IAAe;;YAC1B,MAAM,CAAC,eAAe,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;iBACpD,MAAM,CAAC,IAAI,CAAC;iBACZ,SAAS,CAAC,GAAG,CAAC,CAAC;YAClB,OAAO,eAAe,CAAC;QACzB,CAAC;KAAA;IAEK,OAAO,CAAC,EAAU;;YACtB,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;QAC1B,CAAC;KAAA;IAEK,SAAS,CAAC,IAAY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D,MAAM,UAAU,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC;YACtC,MAAM,SAAS,GAAG,MAAM,KAAK;iBAC1B,KAAK,EAAE;iBACP,KAAK,CAAC,KAAK,CAAC;iBACZ,MAAM,CAAC,MAAM,CAAC;iBACd,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YAE1B,OAAO;gBACL,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;aAC1C,CAAC;QACJ,CAAC;KAAA;CACF;AApHD,kCAoHC"}
|
|
@@ -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,17 +20,13 @@ class MessageDAO {
|
|
|
20
20
|
}
|
|
21
21
|
create(item) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const [result] = yield this._knex(
|
|
24
|
-
.insert(item)
|
|
25
|
-
.returning('*');
|
|
23
|
+
const [result] = yield this._knex("message").insert(item).returning("*");
|
|
26
24
|
return result;
|
|
27
25
|
});
|
|
28
26
|
}
|
|
29
27
|
getById(id) {
|
|
30
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
const result = yield this._knex(
|
|
32
|
-
.where('id', id)
|
|
33
|
-
.first();
|
|
29
|
+
const result = yield this._knex("message").where("id", id).first();
|
|
34
30
|
return result || null;
|
|
35
31
|
});
|
|
36
32
|
}
|
|
@@ -44,11 +40,11 @@ class MessageDAO {
|
|
|
44
40
|
return __awaiter(this, arguments, void 0, function* (page = 1, limit = 10) {
|
|
45
41
|
const offset = (page - 1) * limit;
|
|
46
42
|
const [results, [{ count }]] = yield Promise.all([
|
|
47
|
-
this._knex(
|
|
48
|
-
.orderBy(
|
|
43
|
+
this._knex("message")
|
|
44
|
+
.orderBy("created_at", "asc")
|
|
49
45
|
.limit(limit)
|
|
50
46
|
.offset(offset),
|
|
51
|
-
this._knex(
|
|
47
|
+
this._knex("message").count("* as count"),
|
|
52
48
|
]);
|
|
53
49
|
const totalCount = parseInt(count);
|
|
54
50
|
return {
|
|
@@ -58,24 +54,22 @@ class MessageDAO {
|
|
|
58
54
|
limit,
|
|
59
55
|
count: results.length,
|
|
60
56
|
totalCount,
|
|
61
|
-
totalPages: Math.ceil(totalCount / limit)
|
|
57
|
+
totalPages: Math.ceil(totalCount / limit),
|
|
62
58
|
};
|
|
63
59
|
});
|
|
64
60
|
}
|
|
65
61
|
update(id, item) {
|
|
66
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
const [result] = yield this._knex(
|
|
68
|
-
.where(
|
|
63
|
+
const [result] = yield this._knex("message")
|
|
64
|
+
.where("id", id)
|
|
69
65
|
.update(Object.assign(Object.assign({}, item), { updated_at: new Date() }))
|
|
70
|
-
.returning(
|
|
66
|
+
.returning("*");
|
|
71
67
|
return result || null;
|
|
72
68
|
});
|
|
73
69
|
}
|
|
74
70
|
delete(id) {
|
|
75
71
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
-
const result = yield this._knex(
|
|
77
|
-
.where('id', id)
|
|
78
|
-
.delete();
|
|
72
|
+
const result = yield this._knex("message").where("id", id).delete();
|
|
79
73
|
return result > 0;
|
|
80
74
|
});
|
|
81
75
|
}
|
|
@@ -83,14 +77,12 @@ class MessageDAO {
|
|
|
83
77
|
return __awaiter(this, arguments, void 0, function* (chatId, page = 1, limit = 50) {
|
|
84
78
|
const offset = (page - 1) * limit;
|
|
85
79
|
const [results, [{ count }]] = yield Promise.all([
|
|
86
|
-
this._knex(
|
|
87
|
-
.where(
|
|
88
|
-
.orderBy(
|
|
80
|
+
this._knex("message")
|
|
81
|
+
.where("chatId", chatId)
|
|
82
|
+
.orderBy("created_at", "asc")
|
|
89
83
|
.limit(limit)
|
|
90
84
|
.offset(offset),
|
|
91
|
-
this._knex(
|
|
92
|
-
.where('chatId', chatId)
|
|
93
|
-
.count('* as count')
|
|
85
|
+
this._knex("message").where("chatId", chatId).count("* as count"),
|
|
94
86
|
]);
|
|
95
87
|
const totalCount = parseInt(count);
|
|
96
88
|
return {
|
|
@@ -100,15 +92,15 @@ class MessageDAO {
|
|
|
100
92
|
limit,
|
|
101
93
|
count: results.length,
|
|
102
94
|
totalCount,
|
|
103
|
-
totalPages: Math.ceil(totalCount / limit)
|
|
95
|
+
totalPages: Math.ceil(totalCount / limit),
|
|
104
96
|
};
|
|
105
97
|
});
|
|
106
98
|
}
|
|
107
99
|
getLatestMessages(chatId_1) {
|
|
108
100
|
return __awaiter(this, arguments, void 0, function* (chatId, limit = 50) {
|
|
109
|
-
return yield this._knex(
|
|
110
|
-
.where(
|
|
111
|
-
.orderBy(
|
|
101
|
+
return yield this._knex("message")
|
|
102
|
+
.where("chatId", chatId)
|
|
103
|
+
.orderBy("created_at", "desc")
|
|
112
104
|
.limit(limit)
|
|
113
105
|
.then((messages) => messages.reverse());
|
|
114
106
|
});
|
|
@@ -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":";;;;;;;;;;;;;;;AAOA,0EAA+C;AAE/C,MAAa,UAAU;IAAvB;QACU,UAAK,GAAyB,wBAAW,CAAC,aAAa,EAAE,CAAC;IA2FpE,CAAC;IAzFO,MAA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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;aAC1C,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;AA5FD,gCA4FC"}
|
|
@@ -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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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(c => this._deserialize(c)),
|
|
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(fhwa => {
|
|
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,17 +236,18 @@ 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(fhwaClass => {
|
|
240
|
-
fhwaClassCounts[fhwaClass] =
|
|
239
|
+
fhwaClasses.forEach((fhwaClass) => {
|
|
240
|
+
fhwaClassCounts[fhwaClass] =
|
|
241
|
+
(fhwaClassCounts[fhwaClass] || 0) + count;
|
|
241
242
|
});
|
|
242
243
|
}
|
|
243
244
|
// Labels not in DETECTION_LABEL_TO_FHWA are silently ignored (e.g., pedestrian, bicycle)
|
|
244
245
|
}
|
|
245
246
|
// Step 2: FHWA classes → Custom classes
|
|
246
247
|
const customClassCounts = {};
|
|
247
|
-
config.configuration.customClasses.forEach(customClass => {
|
|
248
|
+
config.configuration.customClasses.forEach((customClass) => {
|
|
248
249
|
let total = 0;
|
|
249
|
-
customClass.fhwaClasses.forEach(fhwaClass => {
|
|
250
|
+
customClass.fhwaClasses.forEach((fhwaClass) => {
|
|
250
251
|
total += fhwaClassCounts[fhwaClass] || 0;
|
|
251
252
|
});
|
|
252
253
|
customClassCounts[customClass.name] = total;
|
|
@@ -311,15 +312,15 @@ class ReportConfigurationDAO {
|
|
|
311
312
|
*/
|
|
312
313
|
_deepMergeNumericData(target, source) {
|
|
313
314
|
// Base case: if source is a number, add it to target
|
|
314
|
-
if (typeof source ===
|
|
315
|
-
return (typeof target ===
|
|
315
|
+
if (typeof source === "number") {
|
|
316
|
+
return (typeof target === "number" ? target : 0) + source;
|
|
316
317
|
}
|
|
317
318
|
// If source is not an object, return target unchanged
|
|
318
|
-
if (typeof source !==
|
|
319
|
+
if (typeof source !== "object" || source === null) {
|
|
319
320
|
return target;
|
|
320
321
|
}
|
|
321
322
|
// Ensure target is an object
|
|
322
|
-
if (typeof target !==
|
|
323
|
+
if (typeof target !== "object" || target === null) {
|
|
323
324
|
target = {};
|
|
324
325
|
}
|
|
325
326
|
// Recursively merge each key in source
|
|
@@ -358,11 +359,11 @@ class ReportConfigurationDAO {
|
|
|
358
359
|
uuid: row.uuid,
|
|
359
360
|
name: row.name,
|
|
360
361
|
description: row.description,
|
|
361
|
-
configuration: typeof row.configuration ===
|
|
362
|
+
configuration: typeof row.configuration === "string"
|
|
362
363
|
? JSON.parse(row.configuration)
|
|
363
364
|
: row.configuration,
|
|
364
365
|
created_at: row.created_at,
|
|
365
|
-
updated_at: row.updated_at
|
|
366
|
+
updated_at: row.updated_at,
|
|
366
367
|
};
|
|
367
368
|
}
|
|
368
369
|
}
|