@trafficgroup/knex-rel 0.1.8 → 0.1.10
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/.claude/settings.local.json +5 -2
- package/.env.prod +5 -0
- package/CLAUDE.md +2 -11
- package/dist/constants/video.constants.d.ts +12 -0
- package/dist/constants/video.constants.js +18 -0
- package/dist/constants/video.constants.js.map +1 -0
- package/dist/dao/VideoMinuteResultDAO.d.ts +4 -1
- package/dist/dao/VideoMinuteResultDAO.js +28 -31
- 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.d.ts +17 -7
- package/dist/dao/camera/camera.dao.js +38 -56
- 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 +35 -25
- package/dist/dao/chat/chat.dao.js.map +1 -1
- package/dist/dao/folder/folder.dao.js +4 -8
- package/dist/dao/folder/folder.dao.js.map +1 -1
- package/dist/dao/location/location.dao.d.ts +17 -0
- package/dist/dao/location/location.dao.js +116 -0
- package/dist/dao/location/location.dao.js.map +1 -0
- 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.d.ts +1 -1
- package/dist/dao/study/study.dao.js +12 -17
- 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.d.ts +9 -1
- package/dist/dao/video/video.dao.js +73 -27
- package/dist/dao/video/video.dao.js.map +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.js +8 -1
- 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 +4 -2
- package/dist/interfaces/chat/chat.interfaces.d.ts +3 -3
- package/dist/interfaces/folder/folder.interfaces.d.ts +1 -1
- package/dist/interfaces/location/location.interfaces.d.ts +9 -0
- package/dist/interfaces/location/location.interfaces.js +3 -0
- package/dist/interfaces/location/location.interfaces.js.map +1 -0
- package/dist/interfaces/message/message.interfaces.d.ts +2 -2
- package/dist/interfaces/study/study.interfaces.d.ts +6 -5
- 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 +3 -2
- package/migrations/20250717160737_migration.ts +1 -1
- package/migrations/20250717160908_migration.ts +2 -5
- package/migrations/20250717161310_migration.ts +1 -1
- package/migrations/20250717161406_migration.ts +3 -3
- package/migrations/20250717162431_migration.ts +1 -1
- package/migrations/20250717173228_migration.ts +2 -2
- package/migrations/20250717204731_migration.ts +1 -1
- package/migrations/20250722210109_migration.ts +4 -8
- package/migrations/20250722211019_migration.ts +1 -1
- package/migrations/20250723153852_migration.ts +10 -13
- package/migrations/20250723162257_migration.ts +7 -4
- package/migrations/20250723171109_migration.ts +7 -4
- package/migrations/20250723205331_migration.ts +9 -6
- package/migrations/20250724191345_migration.ts +11 -8
- package/migrations/20250730180932_migration.ts +13 -14
- package/migrations/20250730213625_migration.ts +11 -8
- package/migrations/20250804124509_migration.ts +21 -26
- package/migrations/20250804132053_migration.ts +8 -5
- package/migrations/20250804164518_migration.ts +7 -7
- package/migrations/20250823223016_migration.ts +21 -32
- package/migrations/20250910015452_migration.ts +6 -18
- package/migrations/20250911000000_migration.ts +4 -18
- package/migrations/20250917144153_migration.ts +7 -14
- package/migrations/20250930200521_migration.ts +4 -8
- package/migrations/20251010143500_migration.ts +6 -27
- package/migrations/20251020225758_migration.ts +15 -51
- package/migrations/20251112120000_migration.ts +81 -0
- package/migrations/20251112120100_migration.ts +21 -0
- package/migrations/20251112120200_migration.ts +38 -0
- package/migrations/20251112120300_migration.ts +22 -0
- package/package.json +1 -1
- package/src/constants/video.constants.ts +19 -0
- package/src/d.types.ts +14 -18
- package/src/dao/VideoMinuteResultDAO.ts +54 -72
- package/src/dao/auth/auth.dao.ts +55 -58
- package/src/dao/batch/batch.dao.ts +98 -101
- package/src/dao/camera/camera.dao.ts +125 -145
- package/src/dao/chat/chat.dao.ts +43 -45
- package/src/dao/folder/folder.dao.ts +56 -59
- package/src/dao/location/location.dao.ts +101 -0
- package/src/dao/message/message.dao.ts +32 -32
- package/src/dao/report-configuration/report-configuration.dao.ts +342 -370
- package/src/dao/study/study.dao.ts +63 -88
- package/src/dao/user/user.dao.ts +50 -52
- package/src/dao/user-push-notification-token/user-push-notification-token.dao.ts +49 -83
- package/src/dao/video/video.dao.ts +339 -313
- package/src/entities/BaseEntity.ts +1 -1
- package/src/index.ts +24 -26
- package/src/interfaces/auth/auth.interfaces.ts +10 -10
- package/src/interfaces/batch/batch.interfaces.ts +1 -1
- package/src/interfaces/camera/camera.interfaces.ts +9 -7
- package/src/interfaces/chat/chat.interfaces.ts +4 -4
- package/src/interfaces/folder/folder.interfaces.ts +2 -2
- package/src/interfaces/location/location.interfaces.ts +9 -0
- package/src/interfaces/message/message.interfaces.ts +3 -3
- package/src/interfaces/report-configuration/report-configuration.interfaces.ts +16 -16
- package/src/interfaces/study/study.interfaces.ts +7 -6
- package/src/interfaces/user/user.interfaces.ts +9 -9
- package/src/interfaces/user-push-notification-token/user-push-notification-token.interfaces.ts +9 -9
- package/src/interfaces/video/video.interfaces.ts +34 -33
- package/plan.md +0 -684
|
@@ -20,9 +20,7 @@ class CameraDAO {
|
|
|
20
20
|
}
|
|
21
21
|
create(item) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const [createdCamera] = yield this._knex("cameras")
|
|
24
|
-
.insert(item)
|
|
25
|
-
.returning("*");
|
|
23
|
+
const [createdCamera] = yield this._knex("cameras").insert(item).returning("*");
|
|
26
24
|
return createdCamera;
|
|
27
25
|
});
|
|
28
26
|
}
|
|
@@ -40,10 +38,7 @@ class CameraDAO {
|
|
|
40
38
|
}
|
|
41
39
|
update(id, item) {
|
|
42
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
const [updatedCamera] = yield this._knex("cameras")
|
|
44
|
-
.where({ id })
|
|
45
|
-
.update(item)
|
|
46
|
-
.returning("*");
|
|
41
|
+
const [updatedCamera] = yield this._knex("cameras").where({ id }).update(item).returning("*");
|
|
47
42
|
return updatedCamera || null;
|
|
48
43
|
});
|
|
49
44
|
}
|
|
@@ -70,35 +65,35 @@ class CameraDAO {
|
|
|
70
65
|
};
|
|
71
66
|
});
|
|
72
67
|
}
|
|
73
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Get cameras for a specific location
|
|
70
|
+
* @param locationId - The location ID
|
|
71
|
+
* @param status - Optional filter by camera status
|
|
72
|
+
*/
|
|
73
|
+
getCamerasByLocationId(locationId, status) {
|
|
74
74
|
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
// Using ST_DWithin for geographic distance calculation
|
|
82
|
-
// This is a PostgreSQL-specific query for geospatial operations
|
|
83
|
-
const cameras = yield this._knex("cameras").whereRaw(`ST_DWithin(
|
|
84
|
-
ST_MakePoint(longitude, latitude)::geography,
|
|
85
|
-
ST_MakePoint(?, ?)::geography,
|
|
86
|
-
?
|
|
87
|
-
)`, [longitude, latitude, radiusKm * 1000]);
|
|
88
|
-
return cameras;
|
|
75
|
+
let query = this._knex("cameras")
|
|
76
|
+
.where("locationId", locationId);
|
|
77
|
+
if (status) {
|
|
78
|
+
query = query.where("status", status);
|
|
79
|
+
}
|
|
80
|
+
return query.orderBy("name", "asc");
|
|
89
81
|
});
|
|
90
82
|
}
|
|
91
83
|
/**
|
|
92
|
-
* Get
|
|
84
|
+
* Get cameras for a specific location with pagination
|
|
85
|
+
* @param locationId - The location ID
|
|
86
|
+
* @param page - Page number
|
|
87
|
+
* @param limit - Items per page
|
|
88
|
+
* @param status - Optional filter by camera status
|
|
93
89
|
*/
|
|
94
|
-
|
|
90
|
+
getCamerasByLocationIdPaginated(locationId, page, limit, status) {
|
|
95
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
96
92
|
const offset = (page - 1) * limit;
|
|
97
|
-
let query = this._knex("cameras")
|
|
98
|
-
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
query = query.where("name", "ilike", `%${escapedName}%`);
|
|
93
|
+
let query = this._knex("cameras")
|
|
94
|
+
.where("locationId", locationId);
|
|
95
|
+
if (status) {
|
|
96
|
+
query = query.where("status", status);
|
|
102
97
|
}
|
|
103
98
|
const [countResult] = yield query.clone().count("* as count");
|
|
104
99
|
const totalCount = +countResult.count;
|
|
@@ -114,39 +109,26 @@ class CameraDAO {
|
|
|
114
109
|
limit,
|
|
115
110
|
count: cameras.length,
|
|
116
111
|
totalCount,
|
|
117
|
-
totalPages: Math.ceil(totalCount / limit)
|
|
112
|
+
totalPages: Math.ceil(totalCount / limit)
|
|
118
113
|
};
|
|
119
114
|
});
|
|
120
115
|
}
|
|
121
116
|
/**
|
|
122
|
-
*
|
|
117
|
+
* Check if a camera name already exists for a location
|
|
118
|
+
* @param name - Camera name
|
|
119
|
+
* @param locationId - Location ID
|
|
120
|
+
* @param excludeId - Optional camera ID to exclude (for update operations)
|
|
123
121
|
*/
|
|
124
|
-
|
|
122
|
+
existsByNameAndLocation(name, locationId, excludeId) {
|
|
125
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
.
|
|
129
|
-
|
|
130
|
-
.
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
.count("* as count");
|
|
135
|
-
const totalCount = +countResult.count;
|
|
136
|
-
const videos = yield query
|
|
137
|
-
.clone()
|
|
138
|
-
.limit(limit)
|
|
139
|
-
.offset(offset)
|
|
140
|
-
.orderBy("v.created_at", "desc");
|
|
141
|
-
return {
|
|
142
|
-
success: true,
|
|
143
|
-
data: videos,
|
|
144
|
-
page,
|
|
145
|
-
limit,
|
|
146
|
-
count: videos.length,
|
|
147
|
-
totalCount,
|
|
148
|
-
totalPages: Math.ceil(totalCount / limit),
|
|
149
|
-
};
|
|
124
|
+
let query = this._knex("cameras")
|
|
125
|
+
.where("locationId", locationId)
|
|
126
|
+
.where("name", name);
|
|
127
|
+
if (excludeId !== undefined) {
|
|
128
|
+
query = query.whereNot("id", excludeId);
|
|
129
|
+
}
|
|
130
|
+
const result = yield query.first();
|
|
131
|
+
return result !== null && result !== undefined;
|
|
150
132
|
});
|
|
151
133
|
}
|
|
152
134
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"camera.dao.js","sourceRoot":"","sources":["../../../src/dao/camera/camera.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"camera.dao.js","sourceRoot":"","sources":["../../../src/dao/camera/camera.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAGA,0EAA+C;AAE/C,MAAa,SAAS;IAAtB;QACY,UAAK,GAAyB,wBAAW,CAAC,aAAa,EAAE,CAAC;IA+HtE,CAAC;IA7HS,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;KAA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YACtC,MAAM,OAAO,GAAG,MAAM,KAAK;iBACtB,KAAK,EAAE;iBACP,KAAK,CAAC,KAAK,CAAC;iBACZ,MAAM,CAAC,MAAM,CAAC;iBACd,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YAE5B,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;IAED;;;;;OAKG;IACG,uBAAuB,CACzB,IAAY,EACZ,UAAkB,EAClB,SAAkB;;YAElB,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;iBAC5B,KAAK,CAAC,YAAY,EAAE,UAAU,CAAC;iBAC/B,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAEzB,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;gBAC1B,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;YAC5C,CAAC;YAED,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;YACnC,OAAO,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,CAAC;QACnD,CAAC;KAAA;CACJ;AAhID,8BAgIC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IBaseDAO, IDataPaginator } from "../../d.types";
|
|
2
|
-
import { IChat, IChatCreate, IChatUpdate } from
|
|
2
|
+
import { IChat, IChatCreate, IChatUpdate } from '../../interfaces/chat/chat.interfaces';
|
|
3
3
|
export declare class ChatDAO implements IBaseDAO<IChat> {
|
|
4
4
|
private _knex;
|
|
5
5
|
create(item: IChatCreate): Promise<IChat>;
|
|
@@ -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,16 +110,16 @@ class ChatDAO {
|
|
|
100
110
|
return __awaiter(this, arguments, void 0, function* (userId, page = 1, limit = 10) {
|
|
101
111
|
const offset = (page - 1) * limit;
|
|
102
112
|
const [results, [{ count }]] = yield Promise.all([
|
|
103
|
-
this._knex(
|
|
104
|
-
.where(
|
|
105
|
-
.where(
|
|
106
|
-
.orderBy(
|
|
113
|
+
this._knex('chat')
|
|
114
|
+
.where('userId', userId)
|
|
115
|
+
.where('status', 'active')
|
|
116
|
+
.orderBy('created_at', 'desc')
|
|
107
117
|
.limit(limit)
|
|
108
118
|
.offset(offset),
|
|
109
|
-
this._knex(
|
|
110
|
-
.where(
|
|
111
|
-
.where(
|
|
112
|
-
.count(
|
|
119
|
+
this._knex('chat')
|
|
120
|
+
.where('userId', userId)
|
|
121
|
+
.where('status', 'active')
|
|
122
|
+
.count('* as count')
|
|
113
123
|
]);
|
|
114
124
|
const totalCount = parseInt(count);
|
|
115
125
|
return {
|
|
@@ -119,7 +129,7 @@ class ChatDAO {
|
|
|
119
129
|
limit,
|
|
120
130
|
count: results.length,
|
|
121
131
|
totalCount,
|
|
122
|
-
totalPages: Math.ceil(totalCount / limit)
|
|
132
|
+
totalPages: Math.ceil(totalCount / limit)
|
|
123
133
|
};
|
|
124
134
|
});
|
|
125
135
|
}
|
|
@@ -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;AAE/C,MAAa,OAAO;IAApB;QACU,UAAK,GAAyB,wBAAW,CAAC,aAAa,EAAE,CAAC;IAqHpE,CAAC;IAnHO,MAAM,CAAC,IAAiB;;YAC5B,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;iBACtC,MAA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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
|
}
|
|
@@ -66,7 +61,8 @@ class FolderDAO {
|
|
|
66
61
|
const offset = (page - 1) * limit;
|
|
67
62
|
const query = this._knex("folders as f")
|
|
68
63
|
.innerJoin("study as s", "f.studyId", "s.id")
|
|
69
|
-
.
|
|
64
|
+
.leftJoin("locations as l", "s.locationId", "l.id")
|
|
65
|
+
.select("f.*", this._knex.raw("to_jsonb(s.*) as study"), "l.name as locationName", "l.uuid as locationUuid");
|
|
70
66
|
if (studyId !== undefined && studyId !== null) {
|
|
71
67
|
query.where("f.studyId", studyId);
|
|
72
68
|
}
|
|
@@ -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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E,OAAO,CAAC,MAAM;gBACrB,UAAU;gBACV,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;aAC5C,CAAC;QACN,CAAC;KAAA;CACJ;AAlED,8BAkEC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IBaseDAO, IDataPaginator } from "../../d.types";
|
|
2
|
+
import { ILocation } from "../../interfaces/location/location.interfaces";
|
|
3
|
+
export declare class LocationDAO implements IBaseDAO<ILocation> {
|
|
4
|
+
private _knex;
|
|
5
|
+
create(item: ILocation): Promise<ILocation>;
|
|
6
|
+
getById(id: number): Promise<ILocation | null>;
|
|
7
|
+
getByUuid(uuid: string): Promise<ILocation | null>;
|
|
8
|
+
update(id: number, item: Partial<ILocation>): Promise<ILocation | null>;
|
|
9
|
+
delete(id: number): Promise<boolean>;
|
|
10
|
+
getAll(page: number, limit: number): Promise<IDataPaginator<ILocation>>;
|
|
11
|
+
getByName(name: string): Promise<ILocation | null>;
|
|
12
|
+
getLocationsNearCoordinates(longitude: number, latitude: number, radiusKm?: number): Promise<ILocation[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Get all locations with optional search filter by name (case-insensitive partial match)
|
|
15
|
+
*/
|
|
16
|
+
getAllWithSearch(page: number, limit: number, name?: string): Promise<IDataPaginator<ILocation>>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
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.LocationDAO = void 0;
|
|
16
|
+
const KnexConnection_1 = __importDefault(require("../../KnexConnection"));
|
|
17
|
+
class LocationDAO {
|
|
18
|
+
constructor() {
|
|
19
|
+
this._knex = KnexConnection_1.default.getConnection();
|
|
20
|
+
}
|
|
21
|
+
create(item) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const [createdLocation] = yield this._knex("locations").insert(item).returning("*");
|
|
24
|
+
return createdLocation;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
getById(id) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const location = yield this._knex("locations").where({ id }).first();
|
|
30
|
+
return location || null;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
getByUuid(uuid) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const location = yield this._knex("locations").where({ uuid }).first();
|
|
36
|
+
return location || null;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
update(id, item) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const [updatedLocation] = yield this._knex("locations").where({ id }).update(item).returning("*");
|
|
42
|
+
return updatedLocation || null;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
delete(id) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const result = yield this._knex("locations").where({ id }).del();
|
|
48
|
+
return result > 0;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
getAll(page, limit) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const offset = (page - 1) * limit;
|
|
54
|
+
const [countResult] = yield this._knex("locations").count("* as count");
|
|
55
|
+
const totalCount = +countResult.count;
|
|
56
|
+
const locations = yield this._knex("locations").limit(limit).offset(offset);
|
|
57
|
+
return {
|
|
58
|
+
success: true,
|
|
59
|
+
data: locations,
|
|
60
|
+
page,
|
|
61
|
+
limit,
|
|
62
|
+
count: locations.length,
|
|
63
|
+
totalCount,
|
|
64
|
+
totalPages: Math.ceil(totalCount / limit),
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
getByName(name) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
const location = yield this._knex("locations").where({ name }).first();
|
|
71
|
+
return location || null;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
getLocationsNearCoordinates(longitude_1, latitude_1) {
|
|
75
|
+
return __awaiter(this, arguments, void 0, function* (longitude, latitude, radiusKm = 1) {
|
|
76
|
+
// Using ST_DWithin for geographic distance calculation
|
|
77
|
+
// This is a PostgreSQL-specific query for geospatial operations
|
|
78
|
+
const locations = yield this._knex("locations")
|
|
79
|
+
.whereRaw(`ST_DWithin(
|
|
80
|
+
ST_MakePoint(longitude, latitude)::geography,
|
|
81
|
+
ST_MakePoint(?, ?)::geography,
|
|
82
|
+
?
|
|
83
|
+
)`, [longitude, latitude, radiusKm * 1000] // Convert km to meters
|
|
84
|
+
);
|
|
85
|
+
return locations;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get all locations with optional search filter by name (case-insensitive partial match)
|
|
90
|
+
*/
|
|
91
|
+
getAllWithSearch(page, limit, name) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
const offset = (page - 1) * limit;
|
|
94
|
+
let query = this._knex("locations");
|
|
95
|
+
// Apply search filter if name provided (escape special chars to prevent pattern injection)
|
|
96
|
+
if (name && name.trim().length > 0) {
|
|
97
|
+
const escapedName = name.trim().replace(/[%_\\]/g, '\\$&');
|
|
98
|
+
query = query.where('name', 'ilike', `%${escapedName}%`);
|
|
99
|
+
}
|
|
100
|
+
const [countResult] = yield query.clone().count("* as count");
|
|
101
|
+
const totalCount = +countResult.count;
|
|
102
|
+
const locations = yield query.clone().limit(limit).offset(offset).orderBy('name', 'asc');
|
|
103
|
+
return {
|
|
104
|
+
success: true,
|
|
105
|
+
data: locations,
|
|
106
|
+
page,
|
|
107
|
+
limit,
|
|
108
|
+
count: locations.length,
|
|
109
|
+
totalCount,
|
|
110
|
+
totalPages: Math.ceil(totalCount / limit),
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.LocationDAO = LocationDAO;
|
|
116
|
+
//# sourceMappingURL=location.dao.js.map
|
|
@@ -0,0 +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;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,CA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tC,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,KAAK,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
|
});
|