@trafficgroup/knex-rel 0.0.9 → 0.0.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.
@@ -0,0 +1,11 @@
1
+ import { IBaseDAO, IDataPaginator } from "../../d.types";
2
+ import { IFolder } from "../../interfaces/folder/folder.interfaces";
3
+ export declare class FolderDAO implements IBaseDAO<IFolder> {
4
+ private _knex;
5
+ create(item: IFolder): Promise<IFolder>;
6
+ getById(id: number): Promise<IFolder | null>;
7
+ getByUuid(uuid: string): Promise<IFolder | null>;
8
+ update(id: number, item: Partial<IFolder>): Promise<IFolder | null>;
9
+ delete(id: number): Promise<boolean>;
10
+ getAll(page: number, limit: number, studyId?: number | null): Promise<IDataPaginator<IFolder>>;
11
+ }
@@ -0,0 +1,84 @@
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.FolderDAO = void 0;
16
+ const KnexConnection_1 = __importDefault(require("../../KnexConnection"));
17
+ class FolderDAO {
18
+ constructor() {
19
+ this._knex = KnexConnection_1.default.getConnection();
20
+ }
21
+ create(item) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ const [createdFolder] = yield this._knex("folder").insert(item).returning("*");
24
+ return createdFolder;
25
+ });
26
+ }
27
+ getById(id) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const folder = yield this._knex("folder as f")
30
+ .innerJoin("study as s", "f.studyId", "s.id")
31
+ .select("f.*", this._knex.raw("to_jsonb(s.*) as study"))
32
+ .where("f.id", id)
33
+ .first();
34
+ return folder || null;
35
+ });
36
+ }
37
+ getByUuid(uuid) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ const folder = yield this._knex("folder as f")
40
+ .innerJoin("study as s", "f.studyId", "s.id")
41
+ .select("f.*", this._knex.raw("to_jsonb(s.*) as study"))
42
+ .where("f.uuid", uuid)
43
+ .first();
44
+ return folder || null;
45
+ });
46
+ }
47
+ update(id, item) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ const [updatedFolder] = yield this._knex("folder").where({ id }).update(item).returning("*");
50
+ return updatedFolder || null;
51
+ });
52
+ }
53
+ delete(id) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ const result = yield this._knex("folder").where({ id }).del();
56
+ return result > 0;
57
+ });
58
+ }
59
+ getAll(page, limit, studyId) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ const offset = (page - 1) * limit;
62
+ const query = this._knex("folder as f")
63
+ .innerJoin("study as s", "f.studyId", "s.id")
64
+ .select("f.*", this._knex.raw("to_jsonb(s.*) as study"));
65
+ if (studyId !== undefined && studyId !== null) {
66
+ query.where("f.studyId", studyId);
67
+ }
68
+ const [countResult] = yield query.clone().clearSelect().count("* as count");
69
+ const totalCount = +countResult.count;
70
+ const folder = yield query.clone().limit(limit).offset(offset);
71
+ return {
72
+ success: true,
73
+ data: folder,
74
+ page,
75
+ limit,
76
+ count: folder.length,
77
+ totalCount,
78
+ totalPages: Math.ceil(totalCount / limit),
79
+ };
80
+ });
81
+ }
82
+ }
83
+ exports.FolderDAO = FolderDAO;
84
+ //# sourceMappingURL=folder.dao.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"folder.dao.js","sourceRoot":"","sources":["../../../src/dao/folder/folder.dao.ts"],"names":[],"mapp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gBACV,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;aAC5C,CAAC;QACN,CAAC;KAAA;CACJ;AA5DD,8BA4DC"}
@@ -0,0 +1,11 @@
1
+ import { IBaseDAO, IDataPaginator } from "../../d.types";
2
+ import { IStudy } from "../../interfaces/study/study.interfaces";
3
+ export declare class StudyDAO implements IBaseDAO<IStudy> {
4
+ private _knex;
5
+ create(item: IStudy): Promise<IStudy>;
6
+ getById(id: number): Promise<IStudy | null>;
7
+ getByUuid(uuid: string): Promise<IStudy | null>;
8
+ update(id: number, item: Partial<IStudy>): Promise<IStudy | null>;
9
+ delete(id: number): Promise<boolean>;
10
+ getAll(page: number, limit: number, createdBy?: number | null): Promise<IDataPaginator<IStudy>>;
11
+ }
@@ -0,0 +1,84 @@
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.StudyDAO = void 0;
16
+ const KnexConnection_1 = __importDefault(require("../../KnexConnection"));
17
+ class StudyDAO {
18
+ constructor() {
19
+ this._knex = KnexConnection_1.default.getConnection();
20
+ }
21
+ create(item) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ const [createdStudy] = yield this._knex("study").insert(item).returning("*");
24
+ return createdStudy;
25
+ });
26
+ }
27
+ getById(id) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const study = yield this._knex("study as s")
30
+ .innerJoin("users as u", "s.createdBy", "u.id")
31
+ .select("s.*", this._knex.raw("to_jsonb(u.*) as user"))
32
+ .where("s.id", id)
33
+ .first();
34
+ return study || null;
35
+ });
36
+ }
37
+ getByUuid(uuid) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ const study = yield this._knex("study as s")
40
+ .innerJoin("users as u", "s.createdBy", "u.id")
41
+ .select("s.*", this._knex.raw("to_jsonb(u.*) as user"))
42
+ .where("s.uuid", uuid)
43
+ .first();
44
+ return study || null;
45
+ });
46
+ }
47
+ update(id, item) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ const [updatedStudy] = yield this._knex("study").where({ id }).update(item).returning("*");
50
+ return updatedStudy || null;
51
+ });
52
+ }
53
+ delete(id) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ const result = yield this._knex("study").where({ id }).del();
56
+ return result > 0;
57
+ });
58
+ }
59
+ getAll(page, limit, createdBy) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ const offset = (page - 1) * limit;
62
+ const query = this._knex("study as s")
63
+ .innerJoin("users as u", "s.createdBy", "u.id")
64
+ .select("s.*", this._knex.raw("to_jsonb(u.*) as user"));
65
+ if (createdBy !== undefined && createdBy !== null) {
66
+ query.where("s.createdBy", createdBy);
67
+ }
68
+ const [countResult] = yield query.clone().clearSelect().count("* as count");
69
+ const totalCount = +countResult.count;
70
+ const studies = yield query.clone().limit(limit).offset(offset);
71
+ return {
72
+ success: true,
73
+ data: studies,
74
+ page,
75
+ limit,
76
+ count: studies.length,
77
+ totalCount,
78
+ totalPages: Math.ceil(totalCount / limit),
79
+ };
80
+ });
81
+ }
82
+ }
83
+ exports.StudyDAO = StudyDAO;
84
+ //# sourceMappingURL=study.dao.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"study.dao.js","sourceRoot":"","sources":["../../../src/dao/study/study.dao.ts"],"names":[],"mappings":";;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EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;aAC5C,CAAC;QACN,CAAC;KAAA;CACJ;AA5DD,4BA4DC"}
@@ -0,0 +1,11 @@
1
+ import { IBaseDAO, IDataPaginator } from "../../d.types";
2
+ import { IVideo } from "../../interfaces/video/video.interfaces";
3
+ export declare class VideoDAO implements IBaseDAO<IVideo> {
4
+ private _knex;
5
+ create(item: IVideo): Promise<IVideo>;
6
+ getById(id: number): Promise<IVideo | null>;
7
+ getByUuid(uuid: string): Promise<IVideo | null>;
8
+ update(id: number, item: Partial<IVideo>): Promise<IVideo | null>;
9
+ delete(id: number): Promise<boolean>;
10
+ getAll(page: number, limit: number, folderId?: number | null): Promise<IDataPaginator<IVideo>>;
11
+ }
@@ -0,0 +1,85 @@
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.VideoDAO = void 0;
16
+ const KnexConnection_1 = __importDefault(require("../../KnexConnection"));
17
+ class VideoDAO {
18
+ constructor() {
19
+ this._knex = KnexConnection_1.default.getConnection();
20
+ }
21
+ create(item) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ const [createdVideo] = yield this._knex("video").insert(item).returning("*");
24
+ return createdVideo;
25
+ });
26
+ }
27
+ getById(id) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const video = yield this._knex("video as v")
30
+ .innerJoin("folders as f", "v.folderId", "f.id")
31
+ .select("v.*", this._knex.raw("to_jsonb(f.*) as folder"))
32
+ .where("v.id", id)
33
+ .first();
34
+ return video || null;
35
+ });
36
+ }
37
+ getByUuid(uuid) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ const video = yield this._knex("video as v")
40
+ .innerJoin("folders as f", "v.folderId", "f.id")
41
+ .select("v.*", this._knex.raw("to_jsonb(f.*) as folder"))
42
+ .where("v.uuid", uuid)
43
+ .first();
44
+ return video || null;
45
+ });
46
+ }
47
+ update(id, item) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ const [updatedVideo] = yield this._knex("video").where({ id }).update(item).returning("*");
50
+ return updatedVideo || null;
51
+ });
52
+ }
53
+ delete(id) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ const result = yield this._knex("video").where({ id }).del();
56
+ return result > 0;
57
+ });
58
+ }
59
+ // entityId corresponde al id del folder al que pertenece el video
60
+ getAll(page, limit, folderId) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ const offset = (page - 1) * limit;
63
+ const query = this._knex("video as v")
64
+ .innerJoin("folders as f", "v.folderId", "f.id")
65
+ .select("v.*", this._knex.raw("to_jsonb(f.*) as folder"));
66
+ if (folderId !== undefined && folderId !== null) {
67
+ query.where("v.folderId", folderId);
68
+ }
69
+ const [countResult] = yield query.clone().clearSelect().count("* as count");
70
+ const totalCount = +countResult.count;
71
+ const videos = yield query.clone().limit(limit).offset(offset);
72
+ return {
73
+ success: true,
74
+ data: videos,
75
+ page,
76
+ limit,
77
+ count: videos.length,
78
+ totalCount,
79
+ totalPages: Math.ceil(totalCount / limit),
80
+ };
81
+ });
82
+ }
83
+ }
84
+ exports.VideoDAO = VideoDAO;
85
+ //# sourceMappingURL=video.dao.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"video.dao.js","sourceRoot":"","sources":["../../../src/dao/video/video.dao.ts"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AC,MAAM;gBACpB,UAAU;gBACV,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;aAC5C,CAAC;QACN,CAAC;KAAA;CACJ;AA7DD,4BA6DC"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,11 @@
1
1
  export { UserDAO } from "./dao/user/user.dao";
2
+ export { StudyDAO } from "./dao/study/study.dao";
3
+ export { FolderDAO } from "./dao/folder/folder.dao";
4
+ export { VideoDAO } from "./dao/video/video.dao";
2
5
  export { IDataPaginator } from "./d.types";
3
6
  export { IUser } from "./interfaces/user/user.interfaces";
7
+ export { IStudy } from "./interfaces/study/study.interfaces";
8
+ export { IFolder } from "./interfaces/folder/folder.interfaces";
9
+ export { IVideo } from "./interfaces/video/video.interfaces";
4
10
  import KnexManager from "./KnexConnection";
5
11
  export { KnexManager };
package/dist/index.js CHANGED
@@ -3,10 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.KnexManager = exports.UserDAO = void 0;
6
+ exports.KnexManager = exports.VideoDAO = exports.FolderDAO = exports.StudyDAO = exports.UserDAO = void 0;
7
7
  // DAOs
8
8
  var user_dao_1 = require("./dao/user/user.dao");
9
9
  Object.defineProperty(exports, "UserDAO", { enumerable: true, get: function () { return user_dao_1.UserDAO; } });
10
+ var study_dao_1 = require("./dao/study/study.dao");
11
+ Object.defineProperty(exports, "StudyDAO", { enumerable: true, get: function () { return study_dao_1.StudyDAO; } });
12
+ var folder_dao_1 = require("./dao/folder/folder.dao");
13
+ Object.defineProperty(exports, "FolderDAO", { enumerable: true, get: function () { return folder_dao_1.FolderDAO; } });
14
+ var video_dao_1 = require("./dao/video/video.dao");
15
+ Object.defineProperty(exports, "VideoDAO", { enumerable: true, get: function () { return video_dao_1.VideoDAO; } });
10
16
  const KnexConnection_1 = __importDefault(require("./KnexConnection"));
11
17
  exports.KnexManager = KnexConnection_1.default;
12
18
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO;AACP,gDAA8C;AAArC,mGAAA,OAAO,OAAA;AAMhB,sEAA2C;AAClC,sBADF,wBAAW,CACE"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO;AACP,gDAA8C;AAArC,mGAAA,OAAO,OAAA;AAChB,mDAAiD;AAAxC,qGAAA,QAAQ,OAAA;AACjB,sDAAoD;AAA3C,uGAAA,SAAS,OAAA;AAClB,mDAAiD;AAAxC,qGAAA,QAAQ,OAAA;AASjB,sEAA2C;AAClC,sBADF,wBAAW,CACE"}
@@ -1,3 +1,4 @@
1
+ import type { IStudy } from "../study/study.interfaces";
1
2
  export interface IFolder {
2
3
  id: number;
3
4
  uuid: string;
@@ -7,4 +8,5 @@ export interface IFolder {
7
8
  studyId: number;
8
9
  created_at: string;
9
10
  updated_at: string;
11
+ study?: IStudy;
10
12
  }
@@ -1,3 +1,4 @@
1
+ import type { IUser } from "../user/user.interfaces";
1
2
  export interface IStudy {
2
3
  id: number;
3
4
  uuid: string;
@@ -6,4 +7,5 @@ export interface IStudy {
6
7
  status: 'COMPLETE' | 'IN PROGRESS' | 'FAILED';
7
8
  created_at: string;
8
9
  updated_at: string;
10
+ user?: IUser;
9
11
  }
@@ -1,3 +1,4 @@
1
+ import type { IFolder } from "../folder/folder.interfaces";
1
2
  export interface IVideo {
2
3
  id: number;
3
4
  uuid: string;
@@ -10,4 +11,5 @@ export interface IVideo {
10
11
  results: Record<string, any>;
11
12
  created_at: string;
12
13
  updated_at: string;
14
+ folder?: IFolder;
13
15
  }
package/package.json CHANGED
@@ -1,47 +1,47 @@
1
- {
2
- "name": "@trafficgroup/knex-rel",
3
- "version": "0.0.9",
4
- "description": "Knex Module",
5
- "main": "dist/index.js",
6
- "scripts": {
7
- "test": "jest",
8
- "format": "prettier --write .",
9
- "build": "tsc",
10
- "clean": "rimraf dist && npm run format && npm run build",
11
- "npm:publish": "npm run clean && npm publish",
12
- "migrate:create": "knex migrate:make migration -x ts",
13
- "migrate:deploy": "knex migrate:latest",
14
- "seed:create": "knex seed:make seed -x ts",
15
- "seed:run": "knex seed:run"
16
- },
17
- "repository": {
18
- "type": "git",
19
- "url": "git+https://github.com/thetrafficgroup/knex-rel.git"
20
- },
21
- "author": "Genium, Inc",
22
- "license": "ISC",
23
- "bugs": {
24
- "url": "https://github.com/thetrafficgroup/knex-rel/issues"
25
- },
26
- "homepage": "https://github.com/thetrafficgroup/knex-rel#readme",
27
- "devDependencies": {
28
- "@eslint/js": "^9.23.0",
29
- "@types/dotenv": "^6.1.1",
30
- "@types/lodash": "^4.17.16",
31
- "@types/node": "^22.13.13",
32
- "eslint": "^9.23.0",
33
- "globals": "^16.0.0",
34
- "prettier": "^3.5.3",
35
- "rimraf": "^6.0.1",
36
- "ts-node": "^10.9.2",
37
- "typescript": "^5.8.2",
38
- "typescript-eslint": "^8.28.0"
39
- },
40
- "dependencies": {
41
- "dotenv": "^16.4.7",
42
- "knex": "^3.1.0",
43
- "lodash": "^4.17.21",
44
- "pg": "^8.14.1",
45
- "uuid": "^11.1.0"
46
- }
47
- }
1
+ {
2
+ "name": "@trafficgroup/knex-rel",
3
+ "version": "0.0.11",
4
+ "description": "Knex Module",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "test": "jest",
8
+ "format": "prettier --write .",
9
+ "build": "tsc",
10
+ "clean": "rimraf dist && npm run format && npm run build",
11
+ "npm:publish": "npm run clean && npm publish",
12
+ "migrate:create": "knex migrate:make migration -x ts",
13
+ "migrate:deploy": "knex migrate:latest",
14
+ "seed:create": "knex seed:make seed -x ts",
15
+ "seed:run": "knex seed:run"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/thetrafficgroup/knex-rel.git"
20
+ },
21
+ "author": "Genium, Inc",
22
+ "license": "ISC",
23
+ "bugs": {
24
+ "url": "https://github.com/thetrafficgroup/knex-rel/issues"
25
+ },
26
+ "homepage": "https://github.com/thetrafficgroup/knex-rel#readme",
27
+ "devDependencies": {
28
+ "@eslint/js": "^9.23.0",
29
+ "@types/dotenv": "^6.1.1",
30
+ "@types/lodash": "^4.17.16",
31
+ "@types/node": "^22.13.13",
32
+ "eslint": "^9.23.0",
33
+ "globals": "^16.0.0",
34
+ "prettier": "^3.5.3",
35
+ "rimraf": "^6.0.1",
36
+ "ts-node": "^10.9.2",
37
+ "typescript": "^5.8.2",
38
+ "typescript-eslint": "^8.28.0"
39
+ },
40
+ "dependencies": {
41
+ "dotenv": "^16.4.7",
42
+ "knex": "^3.1.0",
43
+ "lodash": "^4.17.21",
44
+ "pg": "^8.14.1",
45
+ "uuid": "^11.1.0"
46
+ }
47
+ }
@@ -0,0 +1,66 @@
1
+ import { Knex } from "knex";
2
+ import { IBaseDAO, IDataPaginator } from "../../d.types";
3
+ import { IFolder } from "../../interfaces/folder/folder.interfaces";
4
+ import KnexManager from "../../KnexConnection";
5
+
6
+ export class FolderDAO implements IBaseDAO<IFolder> {
7
+ private _knex: Knex<any, unknown[]> = KnexManager.getConnection();
8
+
9
+ async create(item: IFolder): Promise<IFolder> {
10
+ const [createdFolder] = await this._knex("folder").insert(item).returning("*");
11
+ return createdFolder;
12
+ }
13
+
14
+ async getById(id: number): Promise<IFolder | null> {
15
+ const folder = await this._knex("folder as f")
16
+ .innerJoin("study as s", "f.studyId", "s.id")
17
+ .select("f.*", this._knex.raw("to_jsonb(s.*) as study"))
18
+ .where("f.id", id)
19
+ .first();
20
+ return folder || null;
21
+ }
22
+
23
+ async getByUuid(uuid: string): Promise<IFolder | null> {
24
+ const folder = await this._knex("folder as f")
25
+ .innerJoin("study as s", "f.studyId", "s.id")
26
+ .select("f.*", this._knex.raw("to_jsonb(s.*) as study"))
27
+ .where("f.uuid", uuid)
28
+ .first();
29
+ return folder || null;
30
+ }
31
+
32
+ async update(id: number, item: Partial<IFolder>): Promise<IFolder | null> {
33
+ const [updatedFolder] = await this._knex("folder").where({ id }).update(item).returning("*");
34
+ return updatedFolder || null;
35
+ }
36
+
37
+ async delete(id: number): Promise<boolean> {
38
+ const result = await this._knex("folder").where({ id }).del();
39
+ return result > 0;
40
+ }
41
+
42
+ async getAll(page: number, limit: number, studyId?: number | null): Promise<IDataPaginator<IFolder>> {
43
+ const offset = (page - 1) * limit;
44
+
45
+ const query = this._knex("folder as f")
46
+ .innerJoin("study as s", "f.studyId", "s.id")
47
+ .select("f.*", this._knex.raw("to_jsonb(s.*) as study"));
48
+ if (studyId !== undefined && studyId !== null) {
49
+ query.where("f.studyId", studyId);
50
+ }
51
+
52
+ const [countResult] = await query.clone().clearSelect().count("* as count");
53
+ const totalCount = +countResult.count;
54
+ const folder = await query.clone().limit(limit).offset(offset);
55
+
56
+ return {
57
+ success: true,
58
+ data: folder,
59
+ page,
60
+ limit,
61
+ count: folder.length,
62
+ totalCount,
63
+ totalPages: Math.ceil(totalCount / limit),
64
+ };
65
+ }
66
+ }
@@ -0,0 +1,66 @@
1
+ import { Knex } from "knex";
2
+ import { IBaseDAO, IDataPaginator } from "../../d.types";
3
+ import { IStudy } from "../../interfaces/study/study.interfaces";
4
+ import KnexManager from "../../KnexConnection";
5
+
6
+ export class StudyDAO implements IBaseDAO<IStudy> {
7
+ private _knex: Knex<any, unknown[]> = KnexManager.getConnection();
8
+
9
+ async create(item: IStudy): Promise<IStudy> {
10
+ const [createdStudy] = await this._knex("study").insert(item).returning("*");
11
+ return createdStudy;
12
+ }
13
+
14
+ async getById(id: number): Promise<IStudy | null> {
15
+ const study = await this._knex("study as s")
16
+ .innerJoin("users as u", "s.createdBy", "u.id")
17
+ .select("s.*", this._knex.raw("to_jsonb(u.*) as user"))
18
+ .where("s.id", id)
19
+ .first();
20
+ return study || null;
21
+ }
22
+
23
+ async getByUuid(uuid: string): Promise<IStudy | null> {
24
+ const study = await this._knex("study as s")
25
+ .innerJoin("users as u", "s.createdBy", "u.id")
26
+ .select("s.*", this._knex.raw("to_jsonb(u.*) as user"))
27
+ .where("s.uuid", uuid)
28
+ .first();
29
+ return study || null;
30
+ }
31
+
32
+ async update(id: number, item: Partial<IStudy>): Promise<IStudy | null> {
33
+ const [updatedStudy] = await this._knex("study").where({ id }).update(item).returning("*");
34
+ return updatedStudy || null;
35
+ }
36
+
37
+ async delete(id: number): Promise<boolean> {
38
+ const result = await this._knex("study").where({ id }).del();
39
+ return result > 0;
40
+ }
41
+
42
+ async getAll(page: number, limit: number, createdBy?: number | null): Promise<IDataPaginator<IStudy>> {
43
+ const offset = (page - 1) * limit;
44
+
45
+ const query = this._knex("study as s")
46
+ .innerJoin("users as u", "s.createdBy", "u.id")
47
+ .select("s.*", this._knex.raw("to_jsonb(u.*) as user"));
48
+ if (createdBy !== undefined && createdBy !== null) {
49
+ query.where("s.createdBy", createdBy);
50
+ }
51
+
52
+ const [countResult] = await query.clone().clearSelect().count("* as count");
53
+ const totalCount = +countResult.count;
54
+ const studies = await query.clone().limit(limit).offset(offset);
55
+
56
+ return {
57
+ success: true,
58
+ data: studies,
59
+ page,
60
+ limit,
61
+ count: studies.length,
62
+ totalCount,
63
+ totalPages: Math.ceil(totalCount / limit),
64
+ };
65
+ }
66
+ }
@@ -0,0 +1,67 @@
1
+ import { Knex } from "knex";
2
+ import { IBaseDAO, IDataPaginator } from "../../d.types";
3
+ import { IVideo } from "../../interfaces/video/video.interfaces";
4
+ import KnexManager from "../../KnexConnection";
5
+
6
+ export class VideoDAO implements IBaseDAO<IVideo> {
7
+ private _knex: Knex<any, unknown[]> = KnexManager.getConnection();
8
+
9
+ async create(item: IVideo): Promise<IVideo> {
10
+ const [createdVideo] = await this._knex("video").insert(item).returning("*");
11
+ return createdVideo;
12
+ }
13
+
14
+ async getById(id: number): Promise<IVideo | null> {
15
+ const video = await this._knex("video as v")
16
+ .innerJoin("folders as f", "v.folderId", "f.id")
17
+ .select("v.*", this._knex.raw("to_jsonb(f.*) as folder"))
18
+ .where("v.id", id)
19
+ .first();
20
+ return video || null;
21
+ }
22
+
23
+ async getByUuid(uuid: string): Promise<IVideo | null> {
24
+ const video = await this._knex("video as v")
25
+ .innerJoin("folders as f", "v.folderId", "f.id")
26
+ .select("v.*", this._knex.raw("to_jsonb(f.*) as folder"))
27
+ .where("v.uuid", uuid)
28
+ .first();
29
+ return video || null;
30
+ }
31
+
32
+ async update(id: number, item: Partial<IVideo>): Promise<IVideo | null> {
33
+ const [updatedVideo] = await this._knex("video").where({ id }).update(item).returning("*");
34
+ return updatedVideo || null;
35
+ }
36
+
37
+ async delete(id: number): Promise<boolean> {
38
+ const result = await this._knex("video").where({ id }).del();
39
+ return result > 0;
40
+ }
41
+
42
+ // entityId corresponde al id del folder al que pertenece el video
43
+ async getAll(page: number, limit: number, folderId?: number | null): Promise<IDataPaginator<IVideo>> {
44
+ const offset = (page - 1) * limit;
45
+
46
+ const query = this._knex("video as v")
47
+ .innerJoin("folders as f", "v.folderId", "f.id")
48
+ .select("v.*", this._knex.raw("to_jsonb(f.*) as folder"));
49
+ if (folderId !== undefined && folderId !== null) {
50
+ query.where("v.folderId", folderId);
51
+ }
52
+
53
+ const [countResult] = await query.clone().clearSelect().count("* as count");
54
+ const totalCount = +countResult.count;
55
+ const videos = await query.clone().limit(limit).offset(offset);
56
+
57
+ return {
58
+ success: true,
59
+ data: videos,
60
+ page,
61
+ limit,
62
+ count: videos.length,
63
+ totalCount,
64
+ totalPages: Math.ceil(totalCount / limit),
65
+ };
66
+ }
67
+ }
package/src/index.ts CHANGED
@@ -1,9 +1,15 @@
1
- // DAOs
2
- export { UserDAO } from "./dao/user/user.dao";
3
-
4
- // Interfaces
5
- export { IDataPaginator } from "./d.types";
6
- export { IUser } from "./interfaces/user/user.interfaces";
7
-
8
- import KnexManager from "./KnexConnection";
9
- export { KnexManager };
1
+ // DAOs
2
+ export { UserDAO } from "./dao/user/user.dao";
3
+ export { StudyDAO } from "./dao/study/study.dao";
4
+ export { FolderDAO } from "./dao/folder/folder.dao";
5
+ export { VideoDAO } from "./dao/video/video.dao";
6
+
7
+ // Interfaces
8
+ export { IDataPaginator } from "./d.types";
9
+ export { IUser } from "./interfaces/user/user.interfaces";
10
+ export { IStudy } from "./interfaces/study/study.interfaces";
11
+ export { IFolder } from "./interfaces/folder/folder.interfaces";
12
+ export { IVideo } from "./interfaces/video/video.interfaces";
13
+
14
+ import KnexManager from "./KnexConnection";
15
+ export { KnexManager };
@@ -1,3 +1,5 @@
1
+ import type { IStudy } from "../study/study.interfaces";
2
+
1
3
  export interface IFolder {
2
4
  id: number;
3
5
  uuid: string;
@@ -7,4 +9,5 @@ export interface IFolder {
7
9
  studyId: number; // study.id
8
10
  created_at: string;
9
11
  updated_at: string;
12
+ study?: IStudy;
10
13
  }
@@ -1,3 +1,5 @@
1
+ import type { IUser } from "../user/user.interfaces";
2
+
1
3
  export interface IStudy {
2
4
  id: number;
3
5
  uuid: string;
@@ -6,4 +8,5 @@ export interface IStudy {
6
8
  status: 'COMPLETE' | 'IN PROGRESS' | 'FAILED';
7
9
  created_at: string;
8
10
  updated_at: string;
11
+ user?: IUser;
9
12
  }
@@ -1,3 +1,5 @@
1
+ import type { IFolder } from "../folder/folder.interfaces";
2
+
1
3
  export interface IVideo {
2
4
  id: number;
3
5
  uuid: string;
@@ -10,4 +12,5 @@ export interface IVideo {
10
12
  results: Record<string, any>;
11
13
  created_at: string;
12
14
  updated_at: string;
15
+ folder?: IFolder;
13
16
  }