@trafficgroup/knex-rel 0.1.6 → 0.1.7
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/dao/folder/folder.dao.js +3 -6
- package/dist/dao/folder/folder.dao.js.map +1 -1
- package/dist/dao/study/study.dao.d.ts +1 -0
- package/dist/dao/study/study.dao.js +18 -3
- package/dist/dao/study/study.dao.js.map +1 -1
- package/dist/dao/video/video.dao.d.ts +0 -9
- package/dist/dao/video/video.dao.js +0 -51
- package/dist/dao/video/video.dao.js.map +1 -1
- package/dist/interfaces/folder/folder.interfaces.d.ts +0 -3
- package/dist/interfaces/study/study.interfaces.d.ts +5 -0
- package/dist/interfaces/video/video.interfaces.d.ts +0 -3
- package/migrations/20251010143500_migration.ts +83 -0
- package/package.json +1 -1
- package/src/dao/folder/folder.dao.ts +3 -18
- package/src/dao/study/study.dao.ts +34 -3
- package/src/dao/video/video.dao.ts +0 -63
- package/src/interfaces/folder/folder.interfaces.ts +0 -3
- package/src/interfaces/study/study.interfaces.ts +5 -0
- package/src/interfaces/video/video.interfaces.ts +0 -3
- package/plan.md +0 -871
|
@@ -30,8 +30,7 @@ class FolderDAO {
|
|
|
30
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
31
|
const folder = yield this._knex("folders as f")
|
|
32
32
|
.innerJoin("study as s", "f.studyId", "s.id")
|
|
33
|
-
.
|
|
34
|
-
.select("f.*", this._knex.raw("to_jsonb(s.*) as study"), this._knex.raw("to_jsonb(c.*) as camera"))
|
|
33
|
+
.select("f.*", this._knex.raw("to_jsonb(s.*) as study"))
|
|
35
34
|
.where("f.id", id)
|
|
36
35
|
.first();
|
|
37
36
|
return folder || null;
|
|
@@ -41,8 +40,7 @@ class FolderDAO {
|
|
|
41
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
41
|
const folder = yield this._knex("folders as f")
|
|
43
42
|
.innerJoin("study as s", "f.studyId", "s.id")
|
|
44
|
-
.
|
|
45
|
-
.select("f.*", this._knex.raw("to_jsonb(s.*) as study"), this._knex.raw("to_jsonb(c.*) as camera"))
|
|
43
|
+
.select("f.*", this._knex.raw("to_jsonb(s.*) as study"))
|
|
46
44
|
.where("f.uuid", uuid)
|
|
47
45
|
.first();
|
|
48
46
|
return folder || null;
|
|
@@ -68,8 +66,7 @@ class FolderDAO {
|
|
|
68
66
|
const offset = (page - 1) * limit;
|
|
69
67
|
const query = this._knex("folders as f")
|
|
70
68
|
.innerJoin("study as s", "f.studyId", "s.id")
|
|
71
|
-
.
|
|
72
|
-
.select("f.*", this._knex.raw("to_jsonb(s.*) as study"), this._knex.raw("to_jsonb(c.*) as camera"));
|
|
69
|
+
.select("f.*", this._knex.raw("to_jsonb(s.*) as study"));
|
|
73
70
|
if (studyId !== undefined && studyId !== null) {
|
|
74
71
|
query.where("f.studyId", studyId);
|
|
75
72
|
}
|
|
@@ -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;QACU,UAAK,GAAyB,wBAAW,CAAC,aAAa,EAAE,CAAC;
|
|
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;IAoEpE,CAAC;IAlEO,MAAM,CAAC,IAAa;;YACxB,MAAM,CAAC,aAAa,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;iBAChD,MAAM,CAAC,IAAI,CAAC;iBACZ,SAAS,CAAC,GAAG,CAAC,CAAC;YAClB,OAAO,aAAa,CAAC;QACvB,CAAC;KAAA;IAEK,OAAO,CAAC,EAAU;;YACtB,MAAM,MAAM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AM,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;YAElC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC;iBACrC,SAAS,CAAC,YAAY,EAAE,WAAW,EAAE,MAAM,CAAC;iBAC5C,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC,CAAC;YAC3D,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;gBAC9C,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;YACpC,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;gBACL,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;aAC1C,CAAC;QACJ,CAAC;KAAA;CACF;AArED,8BAqEC"}
|
|
@@ -8,4 +8,5 @@ export declare class StudyDAO implements IBaseDAO<IStudy> {
|
|
|
8
8
|
update(id: number, item: Partial<IStudy>): Promise<IStudy | null>;
|
|
9
9
|
delete(id: number): Promise<boolean>;
|
|
10
10
|
getAll(page: number, limit: number, createdBy?: number | null): Promise<IDataPaginator<IStudy>>;
|
|
11
|
+
getStudiesByCamera(cameraId: number): Promise<IStudy[]>;
|
|
11
12
|
}
|
|
@@ -30,7 +30,8 @@ class StudyDAO {
|
|
|
30
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
31
|
const study = yield this._knex("study as s")
|
|
32
32
|
.innerJoin("users as u", "s.createdBy", "u.id")
|
|
33
|
-
.
|
|
33
|
+
.leftJoin("cameras as c", "s.cameraId", "c.id")
|
|
34
|
+
.select("s.*", this._knex.raw("to_jsonb(u.*) as user"), this._knex.raw("to_jsonb(c.*) as camera"))
|
|
34
35
|
.where("s.id", id)
|
|
35
36
|
.first();
|
|
36
37
|
return study || null;
|
|
@@ -40,7 +41,8 @@ class StudyDAO {
|
|
|
40
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
42
|
const study = yield this._knex("study as s")
|
|
42
43
|
.innerJoin("users as u", "s.createdBy", "u.id")
|
|
43
|
-
.
|
|
44
|
+
.leftJoin("cameras as c", "s.cameraId", "c.id")
|
|
45
|
+
.select("s.*", this._knex.raw("to_jsonb(u.*) as user"), this._knex.raw("to_jsonb(c.*) as camera"))
|
|
44
46
|
.where("s.uuid", uuid)
|
|
45
47
|
.first();
|
|
46
48
|
return study || null;
|
|
@@ -66,7 +68,8 @@ class StudyDAO {
|
|
|
66
68
|
const offset = (page - 1) * limit;
|
|
67
69
|
const query = this._knex("study as s")
|
|
68
70
|
.innerJoin("users as u", "s.createdBy", "u.id")
|
|
69
|
-
.
|
|
71
|
+
.leftJoin("cameras as c", "s.cameraId", "c.id")
|
|
72
|
+
.select("s.*", this._knex.raw("to_jsonb(u.*) as user"), this._knex.raw("to_jsonb(c.*) as camera"));
|
|
70
73
|
if (createdBy !== undefined && createdBy !== null) {
|
|
71
74
|
query.where("s.createdBy", createdBy);
|
|
72
75
|
}
|
|
@@ -84,6 +87,18 @@ class StudyDAO {
|
|
|
84
87
|
};
|
|
85
88
|
});
|
|
86
89
|
}
|
|
90
|
+
getStudiesByCamera(cameraId) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
const studies = yield this._knex("study as s")
|
|
93
|
+
.innerJoin("users as u", "s.createdBy", "u.id")
|
|
94
|
+
.leftJoin("cameras as c", "s.cameraId", "c.id")
|
|
95
|
+
.select("s.*", this._knex.raw("to_jsonb(u.*) as user"), this._knex.raw("to_jsonb(c.*) as camera"))
|
|
96
|
+
.where("s.cameraId", cameraId)
|
|
97
|
+
.orderBy("s.created_at", "desc")
|
|
98
|
+
.limit(10);
|
|
99
|
+
return studies;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
87
102
|
}
|
|
88
103
|
exports.StudyDAO = StudyDAO;
|
|
89
104
|
//# sourceMappingURL=study.dao.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"study.dao.js","sourceRoot":"","sources":["../../../src/dao/study/study.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAGA,0EAA+C;AAE/C,MAAa,QAAQ;IAArB;QACU,UAAK,GAAyB,wBAAW,CAAC,aAAa,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"study.dao.js","sourceRoot":"","sources":["../../../src/dao/study/study.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAGA,0EAA+C;AAE/C,MAAa,QAAQ;IAArB;QACU,UAAK,GAAyB,wBAAW,CAAC,aAAa,EAAE,CAAC;IAmGpE,CAAC;IAjGO,MAAM,CAAC,IAAY;;YACvB,MAAM,CAAC,YAAY,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;iBAC7C,MAAM,CAAC,IAAI,CAAC;iBACZ,SAAS,CAAC,GAAG,CAAC,CAAC;YAClB,OAAO,YAAY,CAAC;QACtB,CAAC;KAAA;IAEK,OAAO,CAAC,EAAU;;YACtB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC;iBACzC,SAAS,CAAC,YAAY,EAAE,aAAa,EAAE,MAAM,CAAC;iBAC9C,QAAQ,CAAC,cAAc,EAAE,YAAY,EAAE,MAAM,CAAC;iBAC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EAAE,aAAa,EAAE,MAAM,CAAC;iBAC9C,QAAQ,CAAC,cAAc,EAAE,YAAY,EAAE,MAAM,CAAC;iBAC9C,MAAM,CACL,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,uBAAuB,CAAC,EACvC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAC1C;iBACA,KAAK,CAAC,YAAY,EAAE,QAAQ,CAAC;iBAC7B,OAAO,CAAC,cAAc,EAAE,MAAM,CAAC;iBAC/B,KAAK,CAAC,EAAE,CAAC,CAAC;YAEb,OAAO,OAAO,CAAC;QACjB,CAAC;KAAA;CACF;AApGD,4BAoGC"}
|
|
@@ -34,13 +34,4 @@ export declare class VideoDAO implements IBaseDAO<IVideo> {
|
|
|
34
34
|
* Get all video IDs for a specific folder (used for cascade operations)
|
|
35
35
|
*/
|
|
36
36
|
getVideoIdsByFolderId(folderId: number): Promise<number[]>;
|
|
37
|
-
/**
|
|
38
|
-
* Bulk update camera assignment for multiple videos
|
|
39
|
-
* Supports optional transaction for service-level transaction management
|
|
40
|
-
*/
|
|
41
|
-
bulkUpdateCamera(videoIds: number[], cameraId: number | null, trx?: Knex.Transaction): Promise<number>;
|
|
42
|
-
/**
|
|
43
|
-
* Get videos by camera ID with folder information (paginated)
|
|
44
|
-
*/
|
|
45
|
-
getVideosByCameraIdWithFolder(cameraId: number, page: number, limit: number): Promise<IDataPaginator<IVideo>>;
|
|
46
37
|
}
|
|
@@ -224,57 +224,6 @@ class VideoDAO {
|
|
|
224
224
|
return rows.map((row) => row.id);
|
|
225
225
|
});
|
|
226
226
|
}
|
|
227
|
-
/**
|
|
228
|
-
* Bulk update camera assignment for multiple videos
|
|
229
|
-
* Supports optional transaction for service-level transaction management
|
|
230
|
-
*/
|
|
231
|
-
bulkUpdateCamera(videoIds, cameraId, trx) {
|
|
232
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
-
if (!videoIds || videoIds.length === 0) {
|
|
234
|
-
return 0;
|
|
235
|
-
}
|
|
236
|
-
const query = trx || this._knex;
|
|
237
|
-
const result = yield query("video")
|
|
238
|
-
.whereIn("id", videoIds)
|
|
239
|
-
.update({
|
|
240
|
-
cameraId: cameraId,
|
|
241
|
-
updated_at: query.fn.now(),
|
|
242
|
-
})
|
|
243
|
-
.returning("id");
|
|
244
|
-
return result.length;
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Get videos by camera ID with folder information (paginated)
|
|
249
|
-
*/
|
|
250
|
-
getVideosByCameraIdWithFolder(cameraId, page, limit) {
|
|
251
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
252
|
-
const offset = (page - 1) * limit;
|
|
253
|
-
const query = this._knex("video as v")
|
|
254
|
-
.innerJoin("folders as f", "v.folderId", "f.id")
|
|
255
|
-
.select("v.*", this._knex.raw("to_jsonb(f.*) as folder"))
|
|
256
|
-
.where("v.cameraId", cameraId);
|
|
257
|
-
// Optimized count query without JOIN
|
|
258
|
-
const [countResult] = yield this._knex("video as v")
|
|
259
|
-
.where("v.cameraId", cameraId)
|
|
260
|
-
.count("* as count");
|
|
261
|
-
const totalCount = +countResult.count;
|
|
262
|
-
const videos = yield query
|
|
263
|
-
.clone()
|
|
264
|
-
.limit(limit)
|
|
265
|
-
.offset(offset)
|
|
266
|
-
.orderBy("v.created_at", "desc");
|
|
267
|
-
return {
|
|
268
|
-
success: true,
|
|
269
|
-
data: videos,
|
|
270
|
-
page,
|
|
271
|
-
limit,
|
|
272
|
-
count: videos.length,
|
|
273
|
-
totalCount,
|
|
274
|
-
totalPages: Math.ceil(totalCount / limit),
|
|
275
|
-
};
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
227
|
}
|
|
279
228
|
exports.VideoDAO = VideoDAO;
|
|
280
229
|
//# sourceMappingURL=video.dao.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"video.dao.js","sourceRoot":"","sources":["../../../src/dao/video/video.dao.ts"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ICamera } from "../camera/camera.interfaces";
|
|
3
2
|
export interface IFolder {
|
|
4
3
|
id: number;
|
|
5
4
|
uuid: string;
|
|
@@ -7,9 +6,7 @@ export interface IFolder {
|
|
|
7
6
|
createdBy: number;
|
|
8
7
|
status: "UPLOADING" | "COMPLETE";
|
|
9
8
|
studyId: number;
|
|
10
|
-
cameraId?: number;
|
|
11
9
|
created_at: string;
|
|
12
10
|
updated_at: string;
|
|
13
11
|
study?: IStudy;
|
|
14
|
-
camera?: ICamera;
|
|
15
12
|
}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import type { IUser } from "../user/user.interfaces";
|
|
2
|
+
import type { ICamera } from "../camera/camera.interfaces";
|
|
2
3
|
export interface IStudy {
|
|
3
4
|
id: number;
|
|
4
5
|
uuid: string;
|
|
5
6
|
name: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
type: "TMC" | "ATR";
|
|
6
9
|
createdBy: number;
|
|
10
|
+
cameraId?: number;
|
|
7
11
|
status: "COMPLETE" | "IN PROGRESS" | "FAILED";
|
|
8
12
|
created_at: string;
|
|
9
13
|
updated_at: string;
|
|
10
14
|
user?: IUser;
|
|
15
|
+
camera?: ICamera;
|
|
11
16
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import type { IFolder } from "../folder/folder.interfaces";
|
|
2
|
-
import type { ICamera } from "../camera/camera.interfaces";
|
|
3
2
|
export interface IVideo {
|
|
4
3
|
id: number;
|
|
5
4
|
uuid: string;
|
|
6
5
|
folderId: number;
|
|
7
|
-
cameraId?: number;
|
|
8
6
|
annotationSourceId?: number;
|
|
9
7
|
name: string;
|
|
10
8
|
videoLocation: string;
|
|
@@ -25,5 +23,4 @@ export interface IVideo {
|
|
|
25
23
|
created_at: string;
|
|
26
24
|
updated_at: string;
|
|
27
25
|
folder?: IFolder;
|
|
28
|
-
camera?: ICamera;
|
|
29
26
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { Knex } from "knex";
|
|
2
|
+
|
|
3
|
+
export async function up(knex: Knex): Promise<void> {
|
|
4
|
+
// 1. Add cameraId to study table
|
|
5
|
+
const studyHasCamera = await knex.schema.hasColumn("study", "cameraId");
|
|
6
|
+
if (!studyHasCamera) {
|
|
7
|
+
await knex.schema.alterTable("study", (table) => {
|
|
8
|
+
table
|
|
9
|
+
.integer("cameraId")
|
|
10
|
+
.nullable()
|
|
11
|
+
.references("id")
|
|
12
|
+
.inTable("cameras")
|
|
13
|
+
.onDelete("SET NULL");
|
|
14
|
+
table.index(["cameraId"]);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// 2. Remove cameraId from video table
|
|
19
|
+
const videoHasCamera = await knex.schema.hasColumn("video", "cameraId");
|
|
20
|
+
if (videoHasCamera) {
|
|
21
|
+
await knex.raw(
|
|
22
|
+
`ALTER TABLE video DROP CONSTRAINT IF EXISTS video_cameraid_foreign`,
|
|
23
|
+
);
|
|
24
|
+
await knex.raw(`DROP INDEX IF EXISTS video_cameraid_index`);
|
|
25
|
+
await knex.schema.alterTable("video", (table) => {
|
|
26
|
+
table.dropColumn("cameraId");
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 3. Remove cameraId from folders table
|
|
31
|
+
const foldersHasCamera = await knex.schema.hasColumn("folders", "cameraId");
|
|
32
|
+
if (foldersHasCamera) {
|
|
33
|
+
await knex.raw(
|
|
34
|
+
`ALTER TABLE folders DROP CONSTRAINT IF EXISTS folders_cameraid_foreign`,
|
|
35
|
+
);
|
|
36
|
+
await knex.raw(`DROP INDEX IF EXISTS folders_cameraid_index`);
|
|
37
|
+
await knex.schema.alterTable("folders", (table) => {
|
|
38
|
+
table.dropColumn("cameraId");
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function down(knex: Knex): Promise<void> {
|
|
44
|
+
// 1. Restore cameraId to folders table
|
|
45
|
+
const foldersHasCamera = await knex.schema.hasColumn("folders", "cameraId");
|
|
46
|
+
if (!foldersHasCamera) {
|
|
47
|
+
await knex.schema.alterTable("folders", (table) => {
|
|
48
|
+
table
|
|
49
|
+
.integer("cameraId")
|
|
50
|
+
.nullable()
|
|
51
|
+
.references("id")
|
|
52
|
+
.inTable("cameras")
|
|
53
|
+
.onDelete("SET NULL");
|
|
54
|
+
table.index(["cameraId"]);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 2. Restore cameraId to video table
|
|
59
|
+
const videoHasCamera = await knex.schema.hasColumn("video", "cameraId");
|
|
60
|
+
if (!videoHasCamera) {
|
|
61
|
+
await knex.schema.alterTable("video", (table) => {
|
|
62
|
+
table
|
|
63
|
+
.integer("cameraId")
|
|
64
|
+
.nullable()
|
|
65
|
+
.references("id")
|
|
66
|
+
.inTable("cameras")
|
|
67
|
+
.onDelete("SET NULL");
|
|
68
|
+
table.index(["cameraId"]);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 3. Remove cameraId from study table
|
|
73
|
+
const studyHasCamera = await knex.schema.hasColumn("study", "cameraId");
|
|
74
|
+
if (studyHasCamera) {
|
|
75
|
+
await knex.raw(
|
|
76
|
+
`ALTER TABLE study DROP CONSTRAINT IF EXISTS study_cameraid_foreign`,
|
|
77
|
+
);
|
|
78
|
+
await knex.raw(`DROP INDEX IF EXISTS study_cameraid_index`);
|
|
79
|
+
await knex.schema.alterTable("study", (table) => {
|
|
80
|
+
table.dropColumn("cameraId");
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
package/package.json
CHANGED
|
@@ -16,12 +16,7 @@ export class FolderDAO implements IBaseDAO<IFolder> {
|
|
|
16
16
|
async getById(id: number): Promise<IFolder | null> {
|
|
17
17
|
const folder = await this._knex("folders as f")
|
|
18
18
|
.innerJoin("study as s", "f.studyId", "s.id")
|
|
19
|
-
.
|
|
20
|
-
.select(
|
|
21
|
-
"f.*",
|
|
22
|
-
this._knex.raw("to_jsonb(s.*) as study"),
|
|
23
|
-
this._knex.raw("to_jsonb(c.*) as camera"),
|
|
24
|
-
)
|
|
19
|
+
.select("f.*", this._knex.raw("to_jsonb(s.*) as study"))
|
|
25
20
|
.where("f.id", id)
|
|
26
21
|
.first();
|
|
27
22
|
return folder || null;
|
|
@@ -30,12 +25,7 @@ export class FolderDAO implements IBaseDAO<IFolder> {
|
|
|
30
25
|
async getByUuid(uuid: string): Promise<IFolder | null> {
|
|
31
26
|
const folder = await this._knex("folders as f")
|
|
32
27
|
.innerJoin("study as s", "f.studyId", "s.id")
|
|
33
|
-
.
|
|
34
|
-
.select(
|
|
35
|
-
"f.*",
|
|
36
|
-
this._knex.raw("to_jsonb(s.*) as study"),
|
|
37
|
-
this._knex.raw("to_jsonb(c.*) as camera"),
|
|
38
|
-
)
|
|
28
|
+
.select("f.*", this._knex.raw("to_jsonb(s.*) as study"))
|
|
39
29
|
.where("f.uuid", uuid)
|
|
40
30
|
.first();
|
|
41
31
|
return folder || null;
|
|
@@ -63,12 +53,7 @@ export class FolderDAO implements IBaseDAO<IFolder> {
|
|
|
63
53
|
|
|
64
54
|
const query = this._knex("folders as f")
|
|
65
55
|
.innerJoin("study as s", "f.studyId", "s.id")
|
|
66
|
-
.
|
|
67
|
-
.select(
|
|
68
|
-
"f.*",
|
|
69
|
-
this._knex.raw("to_jsonb(s.*) as study"),
|
|
70
|
-
this._knex.raw("to_jsonb(c.*) as camera"),
|
|
71
|
-
);
|
|
56
|
+
.select("f.*", this._knex.raw("to_jsonb(s.*) as study"));
|
|
72
57
|
if (studyId !== undefined && studyId !== null) {
|
|
73
58
|
query.where("f.studyId", studyId);
|
|
74
59
|
}
|
|
@@ -16,7 +16,12 @@ export class StudyDAO implements IBaseDAO<IStudy> {
|
|
|
16
16
|
async getById(id: number): Promise<IStudy | null> {
|
|
17
17
|
const study = await this._knex("study as s")
|
|
18
18
|
.innerJoin("users as u", "s.createdBy", "u.id")
|
|
19
|
-
.
|
|
19
|
+
.leftJoin("cameras as c", "s.cameraId", "c.id")
|
|
20
|
+
.select(
|
|
21
|
+
"s.*",
|
|
22
|
+
this._knex.raw("to_jsonb(u.*) as user"),
|
|
23
|
+
this._knex.raw("to_jsonb(c.*) as camera"),
|
|
24
|
+
)
|
|
20
25
|
.where("s.id", id)
|
|
21
26
|
.first();
|
|
22
27
|
return study || null;
|
|
@@ -25,7 +30,12 @@ export class StudyDAO implements IBaseDAO<IStudy> {
|
|
|
25
30
|
async getByUuid(uuid: string): Promise<IStudy | null> {
|
|
26
31
|
const study = await this._knex("study as s")
|
|
27
32
|
.innerJoin("users as u", "s.createdBy", "u.id")
|
|
28
|
-
.
|
|
33
|
+
.leftJoin("cameras as c", "s.cameraId", "c.id")
|
|
34
|
+
.select(
|
|
35
|
+
"s.*",
|
|
36
|
+
this._knex.raw("to_jsonb(u.*) as user"),
|
|
37
|
+
this._knex.raw("to_jsonb(c.*) as camera"),
|
|
38
|
+
)
|
|
29
39
|
.where("s.uuid", uuid)
|
|
30
40
|
.first();
|
|
31
41
|
return study || null;
|
|
@@ -53,7 +63,12 @@ export class StudyDAO implements IBaseDAO<IStudy> {
|
|
|
53
63
|
|
|
54
64
|
const query = this._knex("study as s")
|
|
55
65
|
.innerJoin("users as u", "s.createdBy", "u.id")
|
|
56
|
-
.
|
|
66
|
+
.leftJoin("cameras as c", "s.cameraId", "c.id")
|
|
67
|
+
.select(
|
|
68
|
+
"s.*",
|
|
69
|
+
this._knex.raw("to_jsonb(u.*) as user"),
|
|
70
|
+
this._knex.raw("to_jsonb(c.*) as camera"),
|
|
71
|
+
);
|
|
57
72
|
if (createdBy !== undefined && createdBy !== null) {
|
|
58
73
|
query.where("s.createdBy", createdBy);
|
|
59
74
|
}
|
|
@@ -72,4 +87,20 @@ export class StudyDAO implements IBaseDAO<IStudy> {
|
|
|
72
87
|
totalPages: Math.ceil(totalCount / limit),
|
|
73
88
|
};
|
|
74
89
|
}
|
|
90
|
+
|
|
91
|
+
async getStudiesByCamera(cameraId: number): Promise<IStudy[]> {
|
|
92
|
+
const studies = await this._knex("study as s")
|
|
93
|
+
.innerJoin("users as u", "s.createdBy", "u.id")
|
|
94
|
+
.leftJoin("cameras as c", "s.cameraId", "c.id")
|
|
95
|
+
.select(
|
|
96
|
+
"s.*",
|
|
97
|
+
this._knex.raw("to_jsonb(u.*) as user"),
|
|
98
|
+
this._knex.raw("to_jsonb(c.*) as camera"),
|
|
99
|
+
)
|
|
100
|
+
.where("s.cameraId", cameraId)
|
|
101
|
+
.orderBy("s.created_at", "desc")
|
|
102
|
+
.limit(10);
|
|
103
|
+
|
|
104
|
+
return studies;
|
|
105
|
+
}
|
|
75
106
|
}
|
|
@@ -257,67 +257,4 @@ export class VideoDAO implements IBaseDAO<IVideo> {
|
|
|
257
257
|
|
|
258
258
|
return rows.map((row) => row.id);
|
|
259
259
|
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Bulk update camera assignment for multiple videos
|
|
263
|
-
* Supports optional transaction for service-level transaction management
|
|
264
|
-
*/
|
|
265
|
-
async bulkUpdateCamera(
|
|
266
|
-
videoIds: number[],
|
|
267
|
-
cameraId: number | null,
|
|
268
|
-
trx?: Knex.Transaction,
|
|
269
|
-
): Promise<number> {
|
|
270
|
-
if (!videoIds || videoIds.length === 0) {
|
|
271
|
-
return 0;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const query = trx || this._knex;
|
|
275
|
-
|
|
276
|
-
const result = await query("video")
|
|
277
|
-
.whereIn("id", videoIds)
|
|
278
|
-
.update({
|
|
279
|
-
cameraId: cameraId,
|
|
280
|
-
updated_at: query.fn.now(),
|
|
281
|
-
})
|
|
282
|
-
.returning("id");
|
|
283
|
-
|
|
284
|
-
return result.length;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Get videos by camera ID with folder information (paginated)
|
|
289
|
-
*/
|
|
290
|
-
async getVideosByCameraIdWithFolder(
|
|
291
|
-
cameraId: number,
|
|
292
|
-
page: number,
|
|
293
|
-
limit: number,
|
|
294
|
-
): Promise<IDataPaginator<IVideo>> {
|
|
295
|
-
const offset = (page - 1) * limit;
|
|
296
|
-
|
|
297
|
-
const query = this._knex("video as v")
|
|
298
|
-
.innerJoin("folders as f", "v.folderId", "f.id")
|
|
299
|
-
.select("v.*", this._knex.raw("to_jsonb(f.*) as folder"))
|
|
300
|
-
.where("v.cameraId", cameraId);
|
|
301
|
-
|
|
302
|
-
// Optimized count query without JOIN
|
|
303
|
-
const [countResult] = await this._knex("video as v")
|
|
304
|
-
.where("v.cameraId", cameraId)
|
|
305
|
-
.count("* as count");
|
|
306
|
-
const totalCount = +countResult.count;
|
|
307
|
-
const videos = await query
|
|
308
|
-
.clone()
|
|
309
|
-
.limit(limit)
|
|
310
|
-
.offset(offset)
|
|
311
|
-
.orderBy("v.created_at", "desc");
|
|
312
|
-
|
|
313
|
-
return {
|
|
314
|
-
success: true,
|
|
315
|
-
data: videos,
|
|
316
|
-
page,
|
|
317
|
-
limit,
|
|
318
|
-
count: videos.length,
|
|
319
|
-
totalCount,
|
|
320
|
-
totalPages: Math.ceil(totalCount / limit),
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
260
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { IStudy } from "../study/study.interfaces";
|
|
2
|
-
import type { ICamera } from "../camera/camera.interfaces";
|
|
3
2
|
|
|
4
3
|
export interface IFolder {
|
|
5
4
|
id: number;
|
|
@@ -8,9 +7,7 @@ export interface IFolder {
|
|
|
8
7
|
createdBy: number; // user.id
|
|
9
8
|
status: "UPLOADING" | "COMPLETE";
|
|
10
9
|
studyId: number; // study.id
|
|
11
|
-
cameraId?: number; // camera.id
|
|
12
10
|
created_at: string;
|
|
13
11
|
updated_at: string;
|
|
14
12
|
study?: IStudy;
|
|
15
|
-
camera?: ICamera;
|
|
16
13
|
}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import type { IUser } from "../user/user.interfaces";
|
|
2
|
+
import type { ICamera } from "../camera/camera.interfaces";
|
|
2
3
|
|
|
3
4
|
export interface IStudy {
|
|
4
5
|
id: number;
|
|
5
6
|
uuid: string;
|
|
6
7
|
name: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
type: "TMC" | "ATR";
|
|
7
10
|
createdBy: number;
|
|
11
|
+
cameraId?: number;
|
|
8
12
|
status: "COMPLETE" | "IN PROGRESS" | "FAILED";
|
|
9
13
|
created_at: string;
|
|
10
14
|
updated_at: string;
|
|
11
15
|
user?: IUser;
|
|
16
|
+
camera?: ICamera;
|
|
12
17
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { IFolder } from "../folder/folder.interfaces";
|
|
2
|
-
import type { ICamera } from "../camera/camera.interfaces";
|
|
3
2
|
|
|
4
3
|
export interface IVideo {
|
|
5
4
|
id: number;
|
|
6
5
|
uuid: string;
|
|
7
6
|
folderId: number;
|
|
8
|
-
cameraId?: number;
|
|
9
7
|
annotationSourceId?: number;
|
|
10
8
|
name: string;
|
|
11
9
|
videoLocation: string;
|
|
@@ -31,5 +29,4 @@ export interface IVideo {
|
|
|
31
29
|
created_at: string;
|
|
32
30
|
updated_at: string;
|
|
33
31
|
folder?: IFolder;
|
|
34
|
-
camera?: ICamera;
|
|
35
32
|
}
|