@trafficgroup/knex-rel 0.0.23 → 0.0.25

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,14 @@
1
+ import { IBaseDAO, IDataPaginator } from "../../d.types";
2
+ import { IUserPushNotificationToken } from "../../interfaces/user-push-notification-token/user-push-notification-token.interfaces";
3
+ export declare class UserPushNotificationTokenDAO implements IBaseDAO<IUserPushNotificationToken> {
4
+ private _knex;
5
+ create(item: IUserPushNotificationToken): Promise<IUserPushNotificationToken>;
6
+ getById(id: number): Promise<IUserPushNotificationToken | null>;
7
+ getByUuid(uuid: string): Promise<IUserPushNotificationToken | null>;
8
+ getByUserId(userId: number): Promise<IUserPushNotificationToken[]>;
9
+ getByToken(token: string): Promise<IUserPushNotificationToken | null>;
10
+ getAvailableByUserId(userId: number): Promise<IUserPushNotificationToken[]>;
11
+ update(id: number, item: Partial<IUserPushNotificationToken>): Promise<IUserPushNotificationToken | null>;
12
+ delete(id: number): Promise<boolean>;
13
+ getAll(page: number, limit: number): Promise<IDataPaginator<IUserPushNotificationToken>>;
14
+ }
@@ -0,0 +1,87 @@
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.UserPushNotificationTokenDAO = void 0;
16
+ const KnexConnection_1 = __importDefault(require("../../KnexConnection"));
17
+ class UserPushNotificationTokenDAO {
18
+ constructor() {
19
+ this._knex = KnexConnection_1.default.getConnection();
20
+ }
21
+ create(item) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ const [createdToken] = yield this._knex("user_push_notification_token").insert(item).returning("*");
24
+ return createdToken;
25
+ });
26
+ }
27
+ getById(id) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const token = yield this._knex("user_push_notification_token").where({ id }).first();
30
+ return token || null;
31
+ });
32
+ }
33
+ getByUuid(uuid) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ throw new Error("Method not implemented. UserPushNotificationToken does not have UUID field.");
36
+ });
37
+ }
38
+ getByUserId(userId) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ const tokens = yield this._knex("user_push_notification_token").where({ userId });
41
+ return tokens;
42
+ });
43
+ }
44
+ getByToken(token) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ const tokenRecord = yield this._knex("user_push_notification_token").where({ token }).first();
47
+ return tokenRecord || null;
48
+ });
49
+ }
50
+ getAvailableByUserId(userId) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ const tokens = yield this._knex("user_push_notification_token").where({ userId, available: true });
53
+ return tokens;
54
+ });
55
+ }
56
+ update(id, item) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ const [updatedToken] = yield this._knex("user_push_notification_token").where({ id }).update(item).returning("*");
59
+ return updatedToken || null;
60
+ });
61
+ }
62
+ delete(id) {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ const result = yield this._knex("user_push_notification_token").where({ id }).del();
65
+ return result > 0;
66
+ });
67
+ }
68
+ getAll(page, limit) {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ const offset = (page - 1) * limit;
71
+ const [countResult] = yield this._knex("user_push_notification_token").count("* as count");
72
+ const totalCount = +countResult.count;
73
+ const tokens = yield this._knex("user_push_notification_token").limit(limit).offset(offset);
74
+ return {
75
+ success: true,
76
+ data: tokens,
77
+ page,
78
+ limit,
79
+ count: tokens.length,
80
+ totalCount,
81
+ totalPages: Math.ceil(totalCount / limit),
82
+ };
83
+ });
84
+ }
85
+ }
86
+ exports.UserPushNotificationTokenDAO = UserPushNotificationTokenDAO;
87
+ //# sourceMappingURL=user-push-notification-token.dao.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-push-notification-token.dao.js","sourceRoot":"","sources":["../../../src/dao/user-push-notification-token/user-push-notification-token.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAGA,0EAA+C;AAE/C,MAAa,4BAA4B;IAAzC;QACY,UAAK,GAAyB,wBAAW,CAAC,aAAa,EAAE,CAAC;IA0DtE,CAAC;IAxDS,MAAM,CAAC,IAAgC;;YACzC,MAAM,CAAC,YAAY,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACpG,OAAO,YAAY,CAAC;QACxB,CAAC;KAAA;IAEK,OAAO,CAAC,EAAU;;YACpB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;YACrF,OAAO,KAAK,IAAI,IAAI,CAAC;QACzB,CAAC;KAAA;IAEK,SAAS,CAAC,IAAY;;YACxB,MAAM,IAAI,KAAK,CAAC,6EAA6E,CAAC,CAAC;QACnG,CAAC;KAAA;IAEK,WAAW,CAAC,MAAc;;YAC5B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;YAClF,OAAO,MAAM,CAAC;QAClB,CAAC;KAAA;IAEK,UAAU,CAAC,KAAa;;YAC1B,MAAM,WAAW,GAAG,MAAM,IAAI,CA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K,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAE5F,OAAO;gBACH,OAAO,EAAE,IAAI;gBACb,IAAI,EAAE,MAAM;gBACZ,IAAI;gBACJ,KAAK;gBACL,KAAK,EAAE,MAAM,CAAC,MAAM;gBACpB,UAAU;gBACV,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;aAC5C,CAAC;QACN,CAAC;KAAA;CACJ;AA3DD,oEA2DC"}
package/dist/index.d.ts CHANGED
@@ -3,11 +3,13 @@ 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
5
  export { AuthDAO } from "./dao/auth/auth.dao";
6
+ export { UserPushNotificationTokenDAO } from "./dao/user-push-notification-token/user-push-notification-token.dao";
6
7
  export { IDataPaginator } from "./d.types";
7
8
  export { IUser } from "./interfaces/user/user.interfaces";
8
9
  export { IStudy } from "./interfaces/study/study.interfaces";
9
10
  export { IFolder } from "./interfaces/folder/folder.interfaces";
10
11
  export { IVideo } from "./interfaces/video/video.interfaces";
11
12
  export { IAuth } from "./interfaces/auth/auth.interfaces";
13
+ export { IUserPushNotificationToken } from "./interfaces/user-push-notification-token/user-push-notification-token.interfaces";
12
14
  import KnexManager from "./KnexConnection";
13
15
  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.AuthDAO = exports.VideoDAO = exports.FolderDAO = exports.StudyDAO = exports.UserDAO = void 0;
6
+ exports.KnexManager = exports.UserPushNotificationTokenDAO = 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; } });
@@ -15,6 +15,8 @@ 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
16
  var auth_dao_1 = require("./dao/auth/auth.dao");
17
17
  Object.defineProperty(exports, "AuthDAO", { enumerable: true, get: function () { return auth_dao_1.AuthDAO; } });
18
+ var user_push_notification_token_dao_1 = require("./dao/user-push-notification-token/user-push-notification-token.dao");
19
+ Object.defineProperty(exports, "UserPushNotificationTokenDAO", { enumerable: true, get: function () { return user_push_notification_token_dao_1.UserPushNotificationTokenDAO; } });
18
20
  const KnexConnection_1 = __importDefault(require("./KnexConnection"));
19
21
  exports.KnexManager = KnexConnection_1.default;
20
22
  //# 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;AACjB,gDAA8C;AAArC,mGAAA,OAAO,OAAA;AAUhB,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;AACjB,gDAA8C;AAArC,mGAAA,OAAO,OAAA;AAChB,wHAAmH;AAA1G,gJAAA,4BAA4B,OAAA;AAWrC,sEAA2C;AAClC,sBADF,wBAAW,CACE"}
@@ -0,0 +1,10 @@
1
+ export interface IUserPushNotificationToken {
2
+ id: number;
3
+ userId: number;
4
+ token: string;
5
+ available: boolean;
6
+ token_type: 'expo' | 'native';
7
+ device_type?: string;
8
+ created_at: string;
9
+ updated_at: string;
10
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=user-push-notification-token.interfaces.js.map
@@ -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,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
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trafficgroup/knex-rel",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "description": "Knex Module",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -0,0 +1,65 @@
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
+ }
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@ 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
6
  export { AuthDAO } from "./dao/auth/auth.dao";
7
+ export { UserPushNotificationTokenDAO } from "./dao/user-push-notification-token/user-push-notification-token.dao";
7
8
 
8
9
  // Interfaces
9
10
  export { IDataPaginator } from "./d.types";
@@ -12,6 +13,7 @@ export { IStudy } from "./interfaces/study/study.interfaces";
12
13
  export { IFolder } from "./interfaces/folder/folder.interfaces";
13
14
  export { IVideo } from "./interfaces/video/video.interfaces";
14
15
  export { IAuth } from "./interfaces/auth/auth.interfaces";
16
+ export { IUserPushNotificationToken } from "./interfaces/user-push-notification-token/user-push-notification-token.interfaces";
15
17
 
16
18
  import KnexManager from "./KnexConnection";
17
19
  export { KnexManager };
@@ -0,0 +1,10 @@
1
+ export interface IUserPushNotificationToken {
2
+ id: number;
3
+ userId: number;
4
+ token: string;
5
+ available: boolean;
6
+ token_type: 'expo' | 'native';
7
+ device_type?: string;
8
+ created_at: string;
9
+ updated_at: string;
10
+ }