@trafficgroup/knex-rel 0.0.25 → 0.0.26
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/.env +5 -0
- package/knexfile.ts +5 -5
- package/package.json +47 -47
- package/src/d.types.ts +7 -7
- package/src/dao/user/user.dao.ts +10 -14
- package/src/index.ts +8 -19
- package/src/interfaces/folder/folder.interfaces.ts +0 -3
- package/src/interfaces/study/study.interfaces.ts +0 -3
- package/src/interfaces/user/user.interfaces.ts +0 -2
- package/src/interfaces/video/video.interfaces.ts +1 -9
- package/.claude/settings.local.json +0 -9
- package/CLAUDE.md +0 -63
- package/dist/KnexConnection.d.ts +0 -17
- package/dist/KnexConnection.js +0 -99
- package/dist/KnexConnection.js.map +0 -1
- package/dist/d.types.d.ts +0 -17
- package/dist/d.types.js +0 -3
- package/dist/d.types.js.map +0 -1
- package/dist/dao/auth/auth.dao.d.ts +0 -13
- package/dist/dao/auth/auth.dao.js +0 -82
- package/dist/dao/auth/auth.dao.js.map +0 -1
- package/dist/dao/folder/folder.dao.d.ts +0 -11
- package/dist/dao/folder/folder.dao.js +0 -84
- package/dist/dao/folder/folder.dao.js.map +0 -1
- package/dist/dao/study/study.dao.d.ts +0 -11
- package/dist/dao/study/study.dao.js +0 -84
- package/dist/dao/study/study.dao.js.map +0 -1
- package/dist/dao/user/user.dao.d.ts +0 -12
- package/dist/dao/user/user.dao.js +0 -76
- package/dist/dao/user/user.dao.js.map +0 -1
- package/dist/dao/user-push-notification-token/user-push-notification-token.dao.d.ts +0 -14
- package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js +0 -87
- package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js.map +0 -1
- package/dist/dao/video/video.dao.d.ts +0 -13
- package/dist/dao/video/video.dao.js +0 -88
- package/dist/dao/video/video.dao.js.map +0 -1
- package/dist/index.d.ts +0 -15
- package/dist/index.js +0 -22
- package/dist/index.js.map +0 -1
- package/dist/interfaces/auth/auth.interfaces.d.ts +0 -11
- package/dist/interfaces/auth/auth.interfaces.js +0 -3
- package/dist/interfaces/auth/auth.interfaces.js.map +0 -1
- package/dist/interfaces/folder/folder.interfaces.d.ts +0 -12
- package/dist/interfaces/folder/folder.interfaces.js +0 -3
- package/dist/interfaces/folder/folder.interfaces.js.map +0 -1
- package/dist/interfaces/study/study.interfaces.d.ts +0 -11
- package/dist/interfaces/study/study.interfaces.js +0 -3
- package/dist/interfaces/study/study.interfaces.js.map +0 -1
- package/dist/interfaces/user/user.interfaces.d.ts +0 -11
- package/dist/interfaces/user/user.interfaces.js +0 -3
- package/dist/interfaces/user/user.interfaces.js.map +0 -1
- package/dist/interfaces/user-push-notification-token/user-push-notification-token.interfaces.d.ts +0 -10
- package/dist/interfaces/user-push-notification-token/user-push-notification-token.interfaces.js +0 -3
- package/dist/interfaces/user-push-notification-token/user-push-notification-token.interfaces.js.map +0 -1
- package/dist/interfaces/video/video.interfaces.d.ts +0 -20
- package/dist/interfaces/video/video.interfaces.js +0 -3
- package/dist/interfaces/video/video.interfaces.js.map +0 -1
- package/migrations/20250717173228_migration.ts +0 -9
- package/migrations/20250717204731_migration.ts +0 -13
- package/migrations/20250722210109_migration.ts +0 -60
- package/migrations/20250722211019_migration.ts +0 -15
- package/migrations/20250723153852_migration.ts +0 -19
- package/migrations/20250723162257_migration.ts +0 -16
- package/migrations/20250723171109_migration.ts +0 -16
- package/migrations/20250723205331_migration.ts +0 -18
- package/migrations/20250724191345_migration.ts +0 -18
- package/migrations/20250730180932_migration.ts +0 -22
- package/migrations/20250730213625_migration.ts +0 -18
- package/src/dao/auth/auth.dao.ts +0 -61
- package/src/dao/folder/folder.dao.ts +0 -66
- package/src/dao/study/study.dao.ts +0 -66
- package/src/dao/user-push-notification-token/user-push-notification-token.dao.ts +0 -65
- package/src/dao/video/video.dao.ts +0 -71
- package/src/interfaces/auth/auth.interfaces.ts +0 -11
- package/src/interfaces/user-push-notification-token/user-push-notification-token.interfaces.ts +0 -10
package/dist/interfaces/user-push-notification-token/user-push-notification-token.interfaces.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user-push-notification-token.interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/user-push-notification-token/user-push-notification-token.interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { IFolder } from "../folder/folder.interfaces";
|
|
2
|
-
export interface IVideo {
|
|
3
|
-
id: number;
|
|
4
|
-
uuid: string;
|
|
5
|
-
folderId: number;
|
|
6
|
-
name: string;
|
|
7
|
-
videoLocation: string;
|
|
8
|
-
videoOutputLocation: string | null;
|
|
9
|
-
generateVideoOutput: boolean;
|
|
10
|
-
videoRate: number;
|
|
11
|
-
videoType: 'TMC' | 'ATR' | 'JUNCTION' | 'ROUNDABOUT' | 'PATHWAY';
|
|
12
|
-
metadata: Record<string, any>;
|
|
13
|
-
status: 'QUEUED' | 'PROCESSING' | 'COMPLETED' | 'FAILED' | 'PENDING';
|
|
14
|
-
progress: number;
|
|
15
|
-
remainingTime: string;
|
|
16
|
-
results: Record<string, any>;
|
|
17
|
-
created_at: string;
|
|
18
|
-
updated_at: string;
|
|
19
|
-
folder?: IFolder;
|
|
20
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"video.interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/video/video.interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Knex } from "knex";
|
|
2
|
-
|
|
3
|
-
export async function up(knex: Knex): Promise<void> {
|
|
4
|
-
await knex.schema.alterTable("video", (table) => {
|
|
5
|
-
table.string("name").notNullable().defaultTo("unnamed");
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export async function down(knex: Knex): Promise<void> {
|
|
10
|
-
await knex.schema.alterTable("video", (table) => {
|
|
11
|
-
table.dropColumn("name");
|
|
12
|
-
});
|
|
13
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { Knex } from "knex";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export async function up(knex: Knex): Promise<void> {
|
|
5
|
-
// 1. Crear el tipo ENUM nativo
|
|
6
|
-
await knex.raw(`CREATE TYPE "video_status" AS ENUM ('QUEUED', 'PROCESSING', 'COMPLETED', 'FAILED', 'PENDING');`);
|
|
7
|
-
|
|
8
|
-
// 2. Normalizar los valores existentes
|
|
9
|
-
await knex.raw(`
|
|
10
|
-
UPDATE "video"
|
|
11
|
-
SET "status" = 'QUEUED'
|
|
12
|
-
WHERE "status" = 'QUEUE';
|
|
13
|
-
`);
|
|
14
|
-
|
|
15
|
-
// 3. Crear columna temporal del tipo ENUM
|
|
16
|
-
await knex.raw(`
|
|
17
|
-
ALTER TABLE "video"
|
|
18
|
-
ADD COLUMN "status_tmp" "video_status" DEFAULT 'PENDING';
|
|
19
|
-
`);
|
|
20
|
-
|
|
21
|
-
// 4. Copiar los valores de la columna original a la temporal
|
|
22
|
-
await knex.raw(`
|
|
23
|
-
UPDATE "video"
|
|
24
|
-
SET "status_tmp" = "status"::text::"video_status";
|
|
25
|
-
`);
|
|
26
|
-
|
|
27
|
-
// 5. Eliminar la columna original
|
|
28
|
-
await knex.raw(`
|
|
29
|
-
ALTER TABLE "video"
|
|
30
|
-
DROP COLUMN "status";
|
|
31
|
-
`);
|
|
32
|
-
|
|
33
|
-
// 6. Renombrar la columna temporal
|
|
34
|
-
await knex.raw(`
|
|
35
|
-
ALTER TABLE "video"
|
|
36
|
-
RENAME COLUMN "status_tmp" TO "status";
|
|
37
|
-
`);
|
|
38
|
-
|
|
39
|
-
// 7. Restaurar el default a 'PENDING'
|
|
40
|
-
await knex.raw(`
|
|
41
|
-
ALTER TABLE "video"
|
|
42
|
-
ALTER COLUMN "status" SET DEFAULT 'PENDING';
|
|
43
|
-
`);
|
|
44
|
-
|
|
45
|
-
// 8. Agregar columnas nuevas
|
|
46
|
-
await knex.schema.alterTable("video", (table) => {
|
|
47
|
-
table.integer("progress").notNullable().defaultTo(0);
|
|
48
|
-
table.string("remainingTime", 255).notNullable().defaultTo("0");
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export async function down(knex: Knex): Promise<void> {
|
|
53
|
-
await knex.schema.alterTable("video", (table) => {
|
|
54
|
-
table.dropColumn("progress");
|
|
55
|
-
table.dropColumn("remainingTime");
|
|
56
|
-
table.specificType("status", "varchar(255)").notNullable().defaultTo("QUEUED").alter();
|
|
57
|
-
});
|
|
58
|
-
await knex.raw('DROP TYPE IF EXISTS "video_status";');
|
|
59
|
-
}
|
|
60
|
-
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Knex } from "knex";
|
|
2
|
-
|
|
3
|
-
export async function up(knex: Knex): Promise<void> {
|
|
4
|
-
await knex.raw(`
|
|
5
|
-
ALTER TABLE "video"
|
|
6
|
-
ALTER COLUMN "status" SET DEFAULT 'PENDING';
|
|
7
|
-
`);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export async function down(knex: Knex): Promise<void> {
|
|
11
|
-
await knex.raw(`
|
|
12
|
-
ALTER TABLE "video"
|
|
13
|
-
ALTER COLUMN "status" SET DEFAULT 'QUEUED';
|
|
14
|
-
`);
|
|
15
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Knex } from "knex";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export async function up(knex: Knex): Promise<void> {
|
|
5
|
-
await knex.schema.createTable('auth', (table) => {
|
|
6
|
-
table.increments('id').primary();
|
|
7
|
-
table.integer('userId').unsigned().notNullable().references('id').inTable('users').onDelete('CASCADE');
|
|
8
|
-
table.string('password', 255).notNullable();
|
|
9
|
-
table.boolean('twofaEnabled').notNullable().defaultTo(false);
|
|
10
|
-
table.string('twofaSecret', 255).nullable();
|
|
11
|
-
table.timestamps(true, true);
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export async function down(knex: Knex): Promise<void> {
|
|
17
|
-
await knex.schema.dropTableIfExists('auth');
|
|
18
|
-
}
|
|
19
|
-
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Knex } from "knex";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export async function up(knex: Knex): Promise<void> {
|
|
5
|
-
await knex.schema.alterTable('video', (table) => {
|
|
6
|
-
table.boolean('generateVideoOutput').notNullable().defaultTo(false);
|
|
7
|
-
});
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export async function down(knex: Knex): Promise<void> {
|
|
12
|
-
await knex.schema.alterTable('video', (table) => {
|
|
13
|
-
table.dropColumn('generateVideoOutput');
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Knex } from "knex";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export async function up(knex: Knex): Promise<void> {
|
|
5
|
-
await knex.schema.alterTable('video', (table) => {
|
|
6
|
-
table.string('videoOutputLocation').nullable();
|
|
7
|
-
});
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export async function down(knex: Knex): Promise<void> {
|
|
12
|
-
await knex.schema.alterTable('video', (table) => {
|
|
13
|
-
table.dropColumn('videoOutputLocation');
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Knex } from "knex";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export async function up(knex: Knex): Promise<void> {
|
|
5
|
-
await knex.schema.alterTable('auth', (table) => {
|
|
6
|
-
table.string('emailToken', 255).nullable();
|
|
7
|
-
table.boolean('emailVerified').notNullable().defaultTo(false);
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export async function down(knex: Knex): Promise<void> {
|
|
13
|
-
await knex.schema.alterTable('auth', (table) => {
|
|
14
|
-
table.dropColumn('emailToken');
|
|
15
|
-
table.dropColumn('emailVerified');
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Knex } from "knex";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export async function up(knex: Knex): Promise<void> {
|
|
5
|
-
await knex.schema.alterTable('users', (table) => {
|
|
6
|
-
table.string('profilePhoto').nullable();
|
|
7
|
-
table.string('company').nullable();
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export async function down(knex: Knex): Promise<void> {
|
|
13
|
-
await knex.schema.alterTable('users', (table) => {
|
|
14
|
-
table.dropColumn('profilePhoto');
|
|
15
|
-
table.dropColumn('company');
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Knex } from "knex";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export async function up(knex: Knex): Promise<void> {
|
|
5
|
-
return knex.schema.createTable('user_push_notification_token', (table) => {
|
|
6
|
-
table.increments('id').primary();
|
|
7
|
-
table.integer('userId').unsigned().notNullable();
|
|
8
|
-
table.string('token').notNullable();
|
|
9
|
-
table.boolean('available').defaultTo(true);
|
|
10
|
-
table.timestamps(true, true);
|
|
11
|
-
|
|
12
|
-
table.foreign('userId').references('id').inTable('users').onDelete('CASCADE');
|
|
13
|
-
table.index(['userId']);
|
|
14
|
-
table.index(['token']);
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export async function down(knex: Knex): Promise<void> {
|
|
20
|
-
return knex.schema.dropTable('user_push_notification_token');
|
|
21
|
-
}
|
|
22
|
-
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Knex } from "knex";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export async function up(knex: Knex): Promise<void> {
|
|
5
|
-
await knex.schema.alterTable('user_push_notification_token', (table) => {
|
|
6
|
-
table.string('token_type').defaultTo('expo').notNullable();
|
|
7
|
-
table.string('device_type');
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export async function down(knex: Knex): Promise<void> {
|
|
13
|
-
await knex.schema.alterTable('user_push_notification_token', (table) => {
|
|
14
|
-
table.dropColumn('token_type');
|
|
15
|
-
table.dropColumn('device_type');
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
package/src/dao/auth/auth.dao.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { Knex } from "knex";
|
|
2
|
-
import { IBaseDAO, IDataPaginator } from "../../d.types";
|
|
3
|
-
import { IAuth } from "../../interfaces/auth/auth.interfaces";
|
|
4
|
-
import KnexManager from "../../KnexConnection";
|
|
5
|
-
|
|
6
|
-
export class AuthDAO implements IBaseDAO<IAuth> {
|
|
7
|
-
private _knex: Knex<any, unknown[]> = KnexManager.getConnection();
|
|
8
|
-
|
|
9
|
-
async create(item: IAuth): Promise<IAuth> {
|
|
10
|
-
const [createdAuth] = await this._knex("auth").insert(item).returning("*");
|
|
11
|
-
return createdAuth;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async getById(id: number): Promise<IAuth | null> {
|
|
15
|
-
const auth = await this._knex("auth").where({ id }).first();
|
|
16
|
-
return auth || null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async getByUuid(uuid: string): Promise<IAuth | null> {
|
|
20
|
-
// Auth table doesn't have uuid, so we'll return null or throw error
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async getByUserId(userId: number): Promise<IAuth | null> {
|
|
25
|
-
const auth = await this._knex("auth").where({ userId }).first();
|
|
26
|
-
return auth || null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async getByEmailToken(emailToken: string): Promise<IAuth | null> {
|
|
30
|
-
const auth = await this._knex("auth").where({ emailToken }).first();
|
|
31
|
-
return auth || null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async update(id: number, item: Partial<IAuth>): Promise<IAuth | null> {
|
|
35
|
-
const [updatedAuth] = await this._knex("auth").where({ id }).update(item).returning("*");
|
|
36
|
-
return updatedAuth || null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async delete(id: number): Promise<boolean> {
|
|
40
|
-
const result = await this._knex("auth").where({ id }).del();
|
|
41
|
-
return result > 0;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async getAll(page: number, limit: number): Promise<IDataPaginator<IAuth>> {
|
|
45
|
-
const offset = (page - 1) * limit;
|
|
46
|
-
|
|
47
|
-
const [countResult] = await this._knex("auth").count("* as count");
|
|
48
|
-
const totalCount = +countResult.count;
|
|
49
|
-
const auths = await this._knex("auth").limit(limit).offset(offset);
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
success: true,
|
|
53
|
-
data: auths,
|
|
54
|
-
page,
|
|
55
|
-
limit,
|
|
56
|
-
count: auths.length,
|
|
57
|
-
totalCount,
|
|
58
|
-
totalPages: Math.ceil(totalCount / limit),
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
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("folders").insert(item).returning("*");
|
|
11
|
-
return createdFolder;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async getById(id: number): Promise<IFolder | null> {
|
|
15
|
-
const folder = await this._knex("folders 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("folders 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("folders").where({ id }).update(item).returning("*");
|
|
34
|
-
return updatedFolder || null;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async delete(id: number): Promise<boolean> {
|
|
38
|
-
const result = await this._knex("folders").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("folders 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 folders = await query.clone().limit(limit).offset(offset);
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
success: true,
|
|
58
|
-
data: folders,
|
|
59
|
-
page,
|
|
60
|
-
limit,
|
|
61
|
-
count: folders.length,
|
|
62
|
-
totalCount,
|
|
63
|
-
totalPages: Math.ceil(totalCount / limit),
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { Knex } from "knex";
|
|
2
|
-
import { IBaseDAO, IDataPaginator } from "../../d.types";
|
|
3
|
-
import { IUserPushNotificationToken } from "../../interfaces/user-push-notification-token/user-push-notification-token.interfaces";
|
|
4
|
-
import KnexManager from "../../KnexConnection";
|
|
5
|
-
|
|
6
|
-
export class UserPushNotificationTokenDAO implements IBaseDAO<IUserPushNotificationToken> {
|
|
7
|
-
private _knex: Knex<any, unknown[]> = KnexManager.getConnection();
|
|
8
|
-
|
|
9
|
-
async create(item: IUserPushNotificationToken): Promise<IUserPushNotificationToken> {
|
|
10
|
-
const [createdToken] = await this._knex("user_push_notification_token").insert(item).returning("*");
|
|
11
|
-
return createdToken;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async getById(id: number): Promise<IUserPushNotificationToken | null> {
|
|
15
|
-
const token = await this._knex("user_push_notification_token").where({ id }).first();
|
|
16
|
-
return token || null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async getByUuid(uuid: string): Promise<IUserPushNotificationToken | null> {
|
|
20
|
-
throw new Error("Method not implemented. UserPushNotificationToken does not have UUID field.");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async getByUserId(userId: number): Promise<IUserPushNotificationToken[]> {
|
|
24
|
-
const tokens = await this._knex("user_push_notification_token").where({ userId });
|
|
25
|
-
return tokens;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async getByToken(token: string): Promise<IUserPushNotificationToken | null> {
|
|
29
|
-
const tokenRecord = await this._knex("user_push_notification_token").where({ token }).first();
|
|
30
|
-
return tokenRecord || null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async getAvailableByUserId(userId: number): Promise<IUserPushNotificationToken[]> {
|
|
34
|
-
const tokens = await this._knex("user_push_notification_token").where({ userId, available: true });
|
|
35
|
-
return tokens;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async update(id: number, item: Partial<IUserPushNotificationToken>): Promise<IUserPushNotificationToken | null> {
|
|
39
|
-
const [updatedToken] = await this._knex("user_push_notification_token").where({ id }).update(item).returning("*");
|
|
40
|
-
return updatedToken || null;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async delete(id: number): Promise<boolean> {
|
|
44
|
-
const result = await this._knex("user_push_notification_token").where({ id }).del();
|
|
45
|
-
return result > 0;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async getAll(page: number, limit: number): Promise<IDataPaginator<IUserPushNotificationToken>> {
|
|
49
|
-
const offset = (page - 1) * limit;
|
|
50
|
-
|
|
51
|
-
const [countResult] = await this._knex("user_push_notification_token").count("* as count");
|
|
52
|
-
const totalCount = +countResult.count;
|
|
53
|
-
const tokens = await this._knex("user_push_notification_token").limit(limit).offset(offset);
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
success: true,
|
|
57
|
-
data: tokens,
|
|
58
|
-
page,
|
|
59
|
-
limit,
|
|
60
|
-
count: tokens.length,
|
|
61
|
-
totalCount,
|
|
62
|
-
totalPages: Math.ceil(totalCount / limit),
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
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
|
-
static getInstance(): Knex<any, unknown[]> {
|
|
10
|
-
return KnexManager.getConnection();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async create(item: IVideo): Promise<IVideo> {
|
|
14
|
-
const [createdVideo] = await this._knex("video").insert(item).returning("*");
|
|
15
|
-
return createdVideo;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async getById(id: number): Promise<IVideo | null> {
|
|
19
|
-
const video = await this._knex("video as v")
|
|
20
|
-
.innerJoin("folders as f", "v.folderId", "f.id")
|
|
21
|
-
.select("v.*", this._knex.raw("to_jsonb(f.*) as folder"))
|
|
22
|
-
.where("v.id", id)
|
|
23
|
-
.first();
|
|
24
|
-
return video || null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async getByUuid(uuid: string): Promise<IVideo | null> {
|
|
28
|
-
const video = await this._knex("video as v")
|
|
29
|
-
.innerJoin("folders as f", "v.folderId", "f.id")
|
|
30
|
-
.select("v.*", this._knex.raw("to_jsonb(f.*) as folder"))
|
|
31
|
-
.where("v.uuid", uuid)
|
|
32
|
-
.first();
|
|
33
|
-
return video || null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async update(id: number, item: Partial<IVideo>): Promise<IVideo | null> {
|
|
37
|
-
const [updatedVideo] = await this._knex("video").where({ id }).update(item).returning("*");
|
|
38
|
-
return updatedVideo || null;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async delete(id: number): Promise<boolean> {
|
|
42
|
-
const result = await this._knex("video").where({ id }).del();
|
|
43
|
-
return result > 0;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// entityId corresponde al id del folder al que pertenece el video
|
|
47
|
-
async getAll(page: number, limit: number, folderId?: number | null): Promise<IDataPaginator<IVideo>> {
|
|
48
|
-
const offset = (page - 1) * limit;
|
|
49
|
-
|
|
50
|
-
const query = this._knex("video as v")
|
|
51
|
-
.innerJoin("folders as f", "v.folderId", "f.id")
|
|
52
|
-
.select("v.*", this._knex.raw("to_jsonb(f.*) as folder"));
|
|
53
|
-
if (folderId !== undefined && folderId !== null) {
|
|
54
|
-
query.where("v.folderId", folderId);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const [countResult] = await query.clone().clearSelect().count("* as count");
|
|
58
|
-
const totalCount = +countResult.count;
|
|
59
|
-
const videos = await query.clone().limit(limit).offset(offset);
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
success: true,
|
|
63
|
-
data: videos,
|
|
64
|
-
page,
|
|
65
|
-
limit,
|
|
66
|
-
count: videos.length,
|
|
67
|
-
totalCount,
|
|
68
|
-
totalPages: Math.ceil(totalCount / limit),
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
}
|