@trafficgroup/knex-rel 0.0.16 → 0.0.17
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/dist/dao/auth/auth.dao.d.ts +12 -0
- package/dist/dao/auth/auth.dao.js +76 -0
- package/dist/dao/auth/auth.dao.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/auth/auth.interfaces.d.ts +9 -0
- package/dist/interfaces/auth/auth.interfaces.js +3 -0
- package/dist/interfaces/auth/auth.interfaces.js.map +1 -0
- package/migrations/20250723153852_migration.ts +19 -0
- package/package.json +1 -1
- package/src/dao/auth/auth.dao.ts +56 -0
- package/src/index.ts +2 -0
- package/src/interfaces/auth/auth.interfaces.ts +9 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IBaseDAO, IDataPaginator } from "../../d.types";
|
|
2
|
+
import { IAuth } from "../../interfaces/auth/auth.interfaces";
|
|
3
|
+
export declare class AuthDAO implements IBaseDAO<IAuth> {
|
|
4
|
+
private _knex;
|
|
5
|
+
create(item: IAuth): Promise<IAuth>;
|
|
6
|
+
getById(id: number): Promise<IAuth | null>;
|
|
7
|
+
getByUuid(uuid: string): Promise<IAuth | null>;
|
|
8
|
+
getByUserId(userId: number): Promise<IAuth | null>;
|
|
9
|
+
update(id: number, item: Partial<IAuth>): Promise<IAuth | null>;
|
|
10
|
+
delete(id: number): Promise<boolean>;
|
|
11
|
+
getAll(page: number, limit: number): Promise<IDataPaginator<IAuth>>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
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.AuthDAO = void 0;
|
|
16
|
+
const KnexConnection_1 = __importDefault(require("../../KnexConnection"));
|
|
17
|
+
class AuthDAO {
|
|
18
|
+
constructor() {
|
|
19
|
+
this._knex = KnexConnection_1.default.getConnection();
|
|
20
|
+
}
|
|
21
|
+
create(item) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const [createdAuth] = yield this._knex("auth").insert(item).returning("*");
|
|
24
|
+
return createdAuth;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
getById(id) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const auth = yield this._knex("auth").where({ id }).first();
|
|
30
|
+
return auth || null;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
getByUuid(uuid) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
// Auth table doesn't have uuid, so we'll return null or throw error
|
|
36
|
+
return null;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
getByUserId(userId) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const auth = yield this._knex("auth").where({ userId }).first();
|
|
42
|
+
return auth || null;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
update(id, item) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const [updatedAuth] = yield this._knex("auth").where({ id }).update(item).returning("*");
|
|
48
|
+
return updatedAuth || null;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
delete(id) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const result = yield this._knex("auth").where({ id }).del();
|
|
54
|
+
return result > 0;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
getAll(page, limit) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const offset = (page - 1) * limit;
|
|
60
|
+
const [countResult] = yield this._knex("auth").count("* as count");
|
|
61
|
+
const totalCount = +countResult.count;
|
|
62
|
+
const auths = yield this._knex("auth").limit(limit).offset(offset);
|
|
63
|
+
return {
|
|
64
|
+
success: true,
|
|
65
|
+
data: auths,
|
|
66
|
+
page,
|
|
67
|
+
limit,
|
|
68
|
+
count: auths.length,
|
|
69
|
+
totalCount,
|
|
70
|
+
totalPages: Math.ceil(totalCount / limit),
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.AuthDAO = AuthDAO;
|
|
76
|
+
//# sourceMappingURL=auth.dao.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.dao.js","sourceRoot":"","sources":["../../../src/dao/auth/auth.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAGA,0EAA+C;AAE/C,MAAa,OAAO;IAApB;QACY,UAAK,GAAyB,wBAAW,CAAC,aAAa,EAAE,CAAC;IAiDtE,CAAC;IA/CS,MAAM,CAAC,IAAW;;YACpB,MAAM,CAAC,WAAW,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YAC3E,OAAO,WAAW,CAAC;QACvB,CAAC;KAAA;IAEK,OAAO,CAAC,EAAU;;YACpB,MAAM,IA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,CAAC;YACtC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAEnE,OAAO;gBACH,OAAO,EAAE,IAAI;gBACb,IAAI,EAAE,KAAK;gBACX,IAAI;gBACJ,KAAK;gBACL,KAAK,EAAE,KAAK,CAAC,MAAM;gBACnB,UAAU;gBACV,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;aAC5C,CAAC;QACN,CAAC;KAAA;CACJ;AAlDD,0BAkDC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,10 +2,12 @@ export { UserDAO } from "./dao/user/user.dao";
|
|
|
2
2
|
export { StudyDAO } from "./dao/study/study.dao";
|
|
3
3
|
export { FolderDAO } from "./dao/folder/folder.dao";
|
|
4
4
|
export { VideoDAO } from "./dao/video/video.dao";
|
|
5
|
+
export { AuthDAO } from "./dao/auth/auth.dao";
|
|
5
6
|
export { IDataPaginator } from "./d.types";
|
|
6
7
|
export { IUser } from "./interfaces/user/user.interfaces";
|
|
7
8
|
export { IStudy } from "./interfaces/study/study.interfaces";
|
|
8
9
|
export { IFolder } from "./interfaces/folder/folder.interfaces";
|
|
9
10
|
export { IVideo } from "./interfaces/video/video.interfaces";
|
|
11
|
+
export { IAuth } from "./interfaces/auth/auth.interfaces";
|
|
10
12
|
import KnexManager from "./KnexConnection";
|
|
11
13
|
export { KnexManager };
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ 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.VideoDAO = exports.FolderDAO = exports.StudyDAO = exports.UserDAO = void 0;
|
|
6
|
+
exports.KnexManager = exports.AuthDAO = 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; } });
|
|
@@ -13,6 +13,8 @@ var folder_dao_1 = require("./dao/folder/folder.dao");
|
|
|
13
13
|
Object.defineProperty(exports, "FolderDAO", { enumerable: true, get: function () { return folder_dao_1.FolderDAO; } });
|
|
14
14
|
var video_dao_1 = require("./dao/video/video.dao");
|
|
15
15
|
Object.defineProperty(exports, "VideoDAO", { enumerable: true, get: function () { return video_dao_1.VideoDAO; } });
|
|
16
|
+
var auth_dao_1 = require("./dao/auth/auth.dao");
|
|
17
|
+
Object.defineProperty(exports, "AuthDAO", { enumerable: true, get: function () { return auth_dao_1.AuthDAO; } });
|
|
16
18
|
const KnexConnection_1 = __importDefault(require("./KnexConnection"));
|
|
17
19
|
exports.KnexManager = KnexConnection_1.default;
|
|
18
20
|
//# 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;AAChB,mDAAiD;AAAxC,qGAAA,QAAQ,OAAA;AACjB,sDAAoD;AAA3C,uGAAA,SAAS,OAAA;AAClB,mDAAiD;AAAxC,qGAAA,QAAQ,OAAA;
|
|
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;AACjB,gDAA8C;AAArC,mGAAA,OAAO,OAAA;AAUhB,sEAA2C;AAClC,sBADF,wBAAW,CACE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/auth/auth.interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -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
|
+
|
package/package.json
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
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 update(id: number, item: Partial<IAuth>): Promise<IAuth | null> {
|
|
30
|
+
const [updatedAuth] = await this._knex("auth").where({ id }).update(item).returning("*");
|
|
31
|
+
return updatedAuth || null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async delete(id: number): Promise<boolean> {
|
|
35
|
+
const result = await this._knex("auth").where({ id }).del();
|
|
36
|
+
return result > 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async getAll(page: number, limit: number): Promise<IDataPaginator<IAuth>> {
|
|
40
|
+
const offset = (page - 1) * limit;
|
|
41
|
+
|
|
42
|
+
const [countResult] = await this._knex("auth").count("* as count");
|
|
43
|
+
const totalCount = +countResult.count;
|
|
44
|
+
const auths = await this._knex("auth").limit(limit).offset(offset);
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
success: true,
|
|
48
|
+
data: auths,
|
|
49
|
+
page,
|
|
50
|
+
limit,
|
|
51
|
+
count: auths.length,
|
|
52
|
+
totalCount,
|
|
53
|
+
totalPages: Math.ceil(totalCount / limit),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { UserDAO } from "./dao/user/user.dao";
|
|
|
3
3
|
export { StudyDAO } from "./dao/study/study.dao";
|
|
4
4
|
export { FolderDAO } from "./dao/folder/folder.dao";
|
|
5
5
|
export { VideoDAO } from "./dao/video/video.dao";
|
|
6
|
+
export { AuthDAO } from "./dao/auth/auth.dao";
|
|
6
7
|
|
|
7
8
|
// Interfaces
|
|
8
9
|
export { IDataPaginator } from "./d.types";
|
|
@@ -10,6 +11,7 @@ export { IUser } from "./interfaces/user/user.interfaces";
|
|
|
10
11
|
export { IStudy } from "./interfaces/study/study.interfaces";
|
|
11
12
|
export { IFolder } from "./interfaces/folder/folder.interfaces";
|
|
12
13
|
export { IVideo } from "./interfaces/video/video.interfaces";
|
|
14
|
+
export { IAuth } from "./interfaces/auth/auth.interfaces";
|
|
13
15
|
|
|
14
16
|
import KnexManager from "./KnexConnection";
|
|
15
17
|
export { KnexManager };
|