@trafficgroup/knex-rel 0.0.26 → 0.0.27
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 +9 -0
- package/CLAUDE.md +63 -0
- package/dist/KnexConnection.d.ts +17 -0
- package/dist/KnexConnection.js +99 -0
- package/dist/KnexConnection.js.map +1 -0
- package/dist/d.types.d.ts +17 -0
- package/dist/d.types.js +3 -0
- package/dist/d.types.js.map +1 -0
- package/dist/dao/auth/auth.dao.d.ts +13 -0
- package/dist/dao/auth/auth.dao.js +82 -0
- package/dist/dao/auth/auth.dao.js.map +1 -0
- package/dist/dao/chat/chat.dao.d.ts +13 -0
- package/dist/dao/chat/chat.dao.js +138 -0
- package/dist/dao/chat/chat.dao.js.map +1 -0
- package/dist/dao/folder/folder.dao.d.ts +11 -0
- package/dist/dao/folder/folder.dao.js +84 -0
- package/dist/dao/folder/folder.dao.js.map +1 -0
- package/dist/dao/message/message.dao.d.ts +13 -0
- package/dist/dao/message/message.dao.js +118 -0
- package/dist/dao/message/message.dao.js.map +1 -0
- package/dist/dao/study/study.dao.d.ts +11 -0
- package/dist/dao/study/study.dao.js +84 -0
- package/dist/dao/study/study.dao.js.map +1 -0
- package/dist/dao/user/user.dao.d.ts +12 -0
- package/dist/dao/user/user.dao.js +76 -0
- package/dist/dao/user/user.dao.js.map +1 -0
- package/dist/dao/user-push-notification-token/user-push-notification-token.dao.d.ts +14 -0
- package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js +87 -0
- package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js.map +1 -0
- package/dist/dao/video/video.dao.d.ts +13 -0
- package/dist/dao/video/video.dao.js +88 -0
- package/dist/dao/video/video.dao.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/auth/auth.interfaces.d.ts +11 -0
- package/dist/interfaces/auth/auth.interfaces.js +3 -0
- package/dist/interfaces/auth/auth.interfaces.js.map +1 -0
- package/dist/interfaces/chat/chat.interfaces.d.ts +18 -0
- package/dist/interfaces/chat/chat.interfaces.js +3 -0
- package/dist/interfaces/chat/chat.interfaces.js.map +1 -0
- package/dist/interfaces/folder/folder.interfaces.d.ts +12 -0
- package/dist/interfaces/folder/folder.interfaces.js +3 -0
- package/dist/interfaces/folder/folder.interfaces.js.map +1 -0
- package/dist/interfaces/message/message.interfaces.d.ts +16 -0
- package/dist/interfaces/message/message.interfaces.js +3 -0
- package/dist/interfaces/message/message.interfaces.js.map +1 -0
- package/dist/interfaces/study/study.interfaces.d.ts +11 -0
- package/dist/interfaces/study/study.interfaces.js +3 -0
- package/dist/interfaces/study/study.interfaces.js.map +1 -0
- package/dist/interfaces/user/user.interfaces.d.ts +11 -0
- package/dist/interfaces/user/user.interfaces.js +3 -0
- package/dist/interfaces/user/user.interfaces.js.map +1 -0
- package/dist/interfaces/user-push-notification-token/user-push-notification-token.interfaces.d.ts +10 -0
- package/dist/interfaces/user-push-notification-token/user-push-notification-token.interfaces.js +3 -0
- package/dist/interfaces/user-push-notification-token/user-push-notification-token.interfaces.js.map +1 -0
- package/dist/interfaces/video/video.interfaces.d.ts +20 -0
- package/dist/interfaces/video/video.interfaces.js +3 -0
- package/dist/interfaces/video/video.interfaces.js.map +1 -0
- package/knexfile.ts +5 -5
- package/migrations/20250717173228_migration.ts +9 -0
- package/migrations/20250717204731_migration.ts +13 -0
- package/migrations/20250722210109_migration.ts +60 -0
- package/migrations/20250722211019_migration.ts +15 -0
- package/migrations/20250723153852_migration.ts +19 -0
- package/migrations/20250723162257_migration.ts +16 -0
- package/migrations/20250723171109_migration.ts +16 -0
- package/migrations/20250723205331_migration.ts +18 -0
- package/migrations/20250724191345_migration.ts +18 -0
- package/migrations/20250730180932_migration.ts +22 -0
- package/migrations/20250730213625_migration.ts +18 -0
- package/migrations/20250804124509_migration.ts +43 -0
- package/migrations/20250804132053_migration.ts +18 -0
- package/package.json +47 -47
- package/src/d.types.ts +7 -7
- package/src/dao/auth/auth.dao.ts +61 -0
- package/src/dao/chat/chat.dao.ts +124 -0
- package/src/dao/folder/folder.dao.ts +66 -0
- package/src/dao/message/message.dao.ts +102 -0
- package/src/dao/study/study.dao.ts +66 -0
- package/src/dao/user/user.dao.ts +14 -10
- package/src/dao/user-push-notification-token/user-push-notification-token.dao.ts +65 -0
- package/src/dao/video/video.dao.ts +71 -0
- package/src/index.ts +23 -8
- package/src/interfaces/auth/auth.interfaces.ts +11 -0
- package/src/interfaces/chat/chat.interfaces.ts +20 -0
- package/src/interfaces/folder/folder.interfaces.ts +3 -0
- package/src/interfaces/message/message.interfaces.ts +18 -0
- package/src/interfaces/study/study.interfaces.ts +3 -0
- package/src/interfaces/user/user.interfaces.ts +2 -0
- package/src/interfaces/user-push-notification-token/user-push-notification-token.interfaces.ts +10 -0
- package/src/interfaces/video/video.interfaces.ts +9 -1
- package/.env +0 -5
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IStudy } from "../study/study.interfaces";
|
|
2
|
+
export interface IFolder {
|
|
3
|
+
id: number;
|
|
4
|
+
uuid: string;
|
|
5
|
+
name: string;
|
|
6
|
+
createdBy: number;
|
|
7
|
+
status: 'UPLOADING' | 'COMPLETE';
|
|
8
|
+
studyId: number;
|
|
9
|
+
created_at: string;
|
|
10
|
+
updated_at: string;
|
|
11
|
+
study?: IStudy;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"folder.interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/folder/folder.interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface IMessage {
|
|
2
|
+
id?: number;
|
|
3
|
+
chatId: number;
|
|
4
|
+
role: 'user' | 'assistant';
|
|
5
|
+
content: string;
|
|
6
|
+
created_at?: Date;
|
|
7
|
+
updated_at?: Date;
|
|
8
|
+
}
|
|
9
|
+
export interface IMessageCreate {
|
|
10
|
+
chatId: number;
|
|
11
|
+
role: 'user' | 'assistant';
|
|
12
|
+
content: string;
|
|
13
|
+
}
|
|
14
|
+
export interface IMessageUpdate {
|
|
15
|
+
content?: string;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/message/message.interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IUser } from "../user/user.interfaces";
|
|
2
|
+
export interface IStudy {
|
|
3
|
+
id: number;
|
|
4
|
+
uuid: string;
|
|
5
|
+
name: string;
|
|
6
|
+
createdBy: number;
|
|
7
|
+
status: 'COMPLETE' | 'IN PROGRESS' | 'FAILED';
|
|
8
|
+
created_at: string;
|
|
9
|
+
updated_at: string;
|
|
10
|
+
user?: IUser;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"study.interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/study/study.interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/user/user.interfaces.ts"],"names":[],"mappings":""}
|
package/dist/interfaces/user-push-notification-token/user-push-notification-token.interfaces.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video.interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/video/video.interfaces.ts"],"names":[],"mappings":""}
|
package/knexfile.ts
CHANGED
|
@@ -5,11 +5,11 @@ const config: { [key: string]: Knex.Config } = {
|
|
|
5
5
|
development: {
|
|
6
6
|
client: "postgresql",
|
|
7
7
|
connection: {
|
|
8
|
-
database: process.env.
|
|
9
|
-
user: process.env.
|
|
10
|
-
password: process.env.
|
|
11
|
-
host: process.env.
|
|
12
|
-
port: !!process.env.
|
|
8
|
+
database: process.env.SQL_DB_NAME,
|
|
9
|
+
user: process.env.SQL_USER,
|
|
10
|
+
password: process.env.SQL_PASSWORD,
|
|
11
|
+
host: process.env.SQL_HOST,
|
|
12
|
+
port: !!process.env.SQL_PORT ? +process.env.SQL_PORT : 54323,
|
|
13
13
|
ssl: { rejectUnauthorized: false },
|
|
14
14
|
},
|
|
15
15
|
pool: {
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Knex } from "knex";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export async function up(knex: Knex): Promise<void> {
|
|
5
|
+
// Create chat table
|
|
6
|
+
await knex.schema.createTable('chat', (table) => {
|
|
7
|
+
table.increments('id').primary();
|
|
8
|
+
table.integer('userId').unsigned().notNullable();
|
|
9
|
+
table.string('title', 255).notNullable();
|
|
10
|
+
table.enum('status', ['active', 'archived']).defaultTo('active');
|
|
11
|
+
table.timestamps(true, true);
|
|
12
|
+
|
|
13
|
+
// Foreign key
|
|
14
|
+
table.foreign('userId').references('id').inTable('users').onDelete('CASCADE');
|
|
15
|
+
|
|
16
|
+
// Indexes
|
|
17
|
+
table.index('userId');
|
|
18
|
+
table.index('status');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Create message table
|
|
22
|
+
await knex.schema.createTable('message', (table) => {
|
|
23
|
+
table.increments('id').primary();
|
|
24
|
+
table.integer('chatId').unsigned().notNullable();
|
|
25
|
+
table.enum('role', ['user', 'assistant']).notNullable();
|
|
26
|
+
table.text('content').notNullable();
|
|
27
|
+
table.timestamps(true, true);
|
|
28
|
+
|
|
29
|
+
// Foreign key
|
|
30
|
+
table.foreign('chatId').references('id').inTable('chat').onDelete('CASCADE');
|
|
31
|
+
|
|
32
|
+
// Indexes
|
|
33
|
+
table.index('chatId');
|
|
34
|
+
table.index('created_at');
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
export async function down(knex: Knex): Promise<void> {
|
|
40
|
+
await knex.schema.dropTableIfExists('message');
|
|
41
|
+
await knex.schema.dropTableIfExists('chat');
|
|
42
|
+
}
|
|
43
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Knex } from "knex";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export async function up(knex: Knex): Promise<void> {
|
|
5
|
+
// Add uuid column to chat table
|
|
6
|
+
await knex.schema.alterTable('chat', (table) => {
|
|
7
|
+
table.uuid('uuid').defaultTo(knex.raw('gen_random_uuid()')).notNullable();
|
|
8
|
+
table.index('uuid');
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
export async function down(knex: Knex): Promise<void> {
|
|
14
|
+
await knex.schema.alterTable('chat', (table) => {
|
|
15
|
+
table.dropColumn('uuid');
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
package/package.json
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@trafficgroup/knex-rel",
|
|
3
|
-
"version": "0.0.
|
|
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/
|
|
20
|
-
},
|
|
21
|
-
"author": "Genium, Inc",
|
|
22
|
-
"license": "ISC",
|
|
23
|
-
"bugs": {
|
|
24
|
-
"url": "https://github.com/
|
|
25
|
-
},
|
|
26
|
-
"homepage": "https://github.com/
|
|
27
|
-
"devDependencies": {
|
|
28
|
-
"@eslint/js": "^9.23.0",
|
|
29
|
-
"@types/dotenv": "^6.1.1",
|
|
30
|
-
"@types/lodash": "^4.17.
|
|
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.27",
|
|
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.20",
|
|
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
|
+
}
|
package/src/d.types.ts
CHANGED
|
@@ -6,13 +6,13 @@ export interface IDataPaginator<T> {
|
|
|
6
6
|
count: number;
|
|
7
7
|
totalCount: number;
|
|
8
8
|
totalPages: number;
|
|
9
|
-
}
|
|
9
|
+
}
|
|
10
10
|
|
|
11
11
|
export interface IBaseDAO<T> {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
create(item: T): Promise<T>;
|
|
13
|
+
getById(id: number): Promise<T | null>;
|
|
14
|
+
getByUuid(uuid: string): Promise<T | null>;
|
|
15
|
+
getAll(page: number, limit: number, entityId?: any | null): Promise<IDataPaginator<T>>;
|
|
16
|
+
update(id: number, item: T): Promise<T | null>;
|
|
17
|
+
delete(id: number): Promise<boolean>;
|
|
18
18
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
}
|