@trafficgroup/knex-rel 0.1.10 → 0.1.11-rc0
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/dist/constants/video.constants.d.ts +2 -2
- package/dist/constants/video.constants.js +9 -5
- package/dist/constants/video.constants.js.map +1 -1
- package/dist/dao/VideoMinuteResultDAO.d.ts +1 -1
- package/dist/dao/VideoMinuteResultDAO.js +29 -23
- package/dist/dao/VideoMinuteResultDAO.js.map +1 -1
- package/dist/dao/auth/auth.dao.js +4 -1
- package/dist/dao/auth/auth.dao.js.map +1 -1
- package/dist/dao/batch/batch.dao.js +13 -14
- package/dist/dao/batch/batch.dao.js.map +1 -1
- package/dist/dao/camera/camera.dao.js +10 -7
- package/dist/dao/camera/camera.dao.js.map +1 -1
- package/dist/dao/chat/chat.dao.d.ts +5 -2
- package/dist/dao/chat/chat.dao.js +37 -38
- package/dist/dao/chat/chat.dao.js.map +1 -1
- package/dist/dao/folder/folder.dao.js +7 -2
- package/dist/dao/folder/folder.dao.js.map +1 -1
- package/dist/dao/location/location.dao.js +16 -9
- package/dist/dao/location/location.dao.js.map +1 -1
- package/dist/dao/message/message.dao.d.ts +1 -1
- package/dist/dao/message/message.dao.js +18 -26
- package/dist/dao/message/message.dao.js.map +1 -1
- package/dist/dao/report-configuration/report-configuration.dao.js +32 -31
- package/dist/dao/report-configuration/report-configuration.dao.js.map +1 -1
- package/dist/dao/study/study.dao.js +7 -2
- package/dist/dao/study/study.dao.js.map +1 -1
- package/dist/dao/user/user.dao.js +4 -1
- package/dist/dao/user/user.dao.js.map +1 -1
- package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js +26 -8
- package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js.map +1 -1
- package/dist/dao/video/video.dao.js +30 -28
- package/dist/dao/video/video.dao.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js.map +1 -1
- package/dist/interfaces/batch/batch.interfaces.d.ts +1 -1
- package/dist/interfaces/camera/camera.interfaces.d.ts +1 -1
- package/dist/interfaces/chat/chat.interfaces.d.ts +3 -3
- package/dist/interfaces/folder/folder.interfaces.d.ts +1 -1
- package/dist/interfaces/message/message.interfaces.d.ts +2 -2
- package/dist/interfaces/study/study.interfaces.d.ts +2 -2
- package/dist/interfaces/user/user.interfaces.d.ts +1 -1
- package/dist/interfaces/user-push-notification-token/user-push-notification-token.interfaces.d.ts +1 -1
- package/dist/interfaces/video/video.interfaces.d.ts +2 -2
- package/package.json +1 -1
- package/src/dao/chat/chat.dao.ts +32 -12
- package/src/index.ts +1 -1
- package/.env.prod +0 -5
package/src/dao/chat/chat.dao.ts
CHANGED
|
@@ -3,6 +3,10 @@ import { IBaseDAO, IDataPaginator } from "../../d.types";
|
|
|
3
3
|
import { IChat, IChatCreate, IChatUpdate } from '../../interfaces/chat/chat.interfaces';
|
|
4
4
|
import KnexManager from "../../KnexConnection";
|
|
5
5
|
|
|
6
|
+
export interface IChatPaginatorResponse extends IDataPaginator<IChat> {
|
|
7
|
+
hasMore: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
6
10
|
export class ChatDAO implements IBaseDAO<IChat> {
|
|
7
11
|
private _knex: Knex<any, unknown[]> = KnexManager.getConnection();
|
|
8
12
|
|
|
@@ -29,7 +33,7 @@ export class ChatDAO implements IBaseDAO<IChat> {
|
|
|
29
33
|
|
|
30
34
|
async getAll(page = 1, limit = 10): Promise<IDataPaginator<IChat>> {
|
|
31
35
|
const offset = (page - 1) * limit;
|
|
32
|
-
|
|
36
|
+
|
|
33
37
|
const [results, [{ count }]] = await Promise.all([
|
|
34
38
|
this._knex('chat')
|
|
35
39
|
.orderBy('created_at', 'desc')
|
|
@@ -70,7 +74,7 @@ export class ChatDAO implements IBaseDAO<IChat> {
|
|
|
70
74
|
|
|
71
75
|
async getByUserId(userId: number, page = 1, limit = 10): Promise<IDataPaginator<IChat>> {
|
|
72
76
|
const offset = (page - 1) * limit;
|
|
73
|
-
|
|
77
|
+
|
|
74
78
|
const [results, [{ count }]] = await Promise.all([
|
|
75
79
|
this._knex('chat')
|
|
76
80
|
.where('userId', userId)
|
|
@@ -94,23 +98,38 @@ export class ChatDAO implements IBaseDAO<IChat> {
|
|
|
94
98
|
};
|
|
95
99
|
}
|
|
96
100
|
|
|
97
|
-
async getActiveByUserId(userId: number, page = 1, limit = 10): Promise<
|
|
101
|
+
async getActiveByUserId(userId: number, page = 1, limit = 10, query?: string): Promise<IChatPaginatorResponse> {
|
|
98
102
|
const offset = (page - 1) * limit;
|
|
99
|
-
|
|
103
|
+
|
|
104
|
+
// Build data query
|
|
105
|
+
let dataQuery = this._knex('chat')
|
|
106
|
+
.where('userId', userId)
|
|
107
|
+
.where('status', 'active');
|
|
108
|
+
|
|
109
|
+
// Build count query
|
|
110
|
+
let countQuery = this._knex('chat')
|
|
111
|
+
.where('userId', userId)
|
|
112
|
+
.where('status', 'active');
|
|
113
|
+
|
|
114
|
+
// Apply search filter if query is provided
|
|
115
|
+
if (query && query.trim()) {
|
|
116
|
+
const searchTerm = `%${query.trim()}%`;
|
|
117
|
+
dataQuery = dataQuery.where('title', 'ILIKE', searchTerm);
|
|
118
|
+
countQuery = countQuery.where('title', 'ILIKE', searchTerm);
|
|
119
|
+
}
|
|
120
|
+
|
|
100
121
|
const [results, [{ count }]] = await Promise.all([
|
|
101
|
-
|
|
102
|
-
.where('userId', userId)
|
|
103
|
-
.where('status', 'active')
|
|
122
|
+
dataQuery
|
|
104
123
|
.orderBy('created_at', 'desc')
|
|
105
124
|
.limit(limit)
|
|
106
125
|
.offset(offset),
|
|
107
|
-
|
|
108
|
-
.where('userId', userId)
|
|
109
|
-
.where('status', 'active')
|
|
110
|
-
.count('* as count')
|
|
126
|
+
countQuery.count('* as count')
|
|
111
127
|
]);
|
|
112
128
|
|
|
113
129
|
const totalCount = parseInt(count as string);
|
|
130
|
+
const totalPages = Math.ceil(totalCount / limit);
|
|
131
|
+
const hasMore = page < totalPages;
|
|
132
|
+
|
|
114
133
|
return {
|
|
115
134
|
success: true,
|
|
116
135
|
data: results,
|
|
@@ -118,7 +137,8 @@ export class ChatDAO implements IBaseDAO<IChat> {
|
|
|
118
137
|
limit,
|
|
119
138
|
count: results.length,
|
|
120
139
|
totalCount,
|
|
121
|
-
totalPages
|
|
140
|
+
totalPages,
|
|
141
|
+
hasMore
|
|
122
142
|
};
|
|
123
143
|
}
|
|
124
144
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export { AuthDAO } from "./dao/auth/auth.dao";
|
|
3
3
|
export { BatchDAO } from "./dao/batch/batch.dao";
|
|
4
4
|
export { CameraDAO } from "./dao/camera/camera.dao";
|
|
5
|
-
export { ChatDAO } from "./dao/chat/chat.dao";
|
|
5
|
+
export { ChatDAO, IChatPaginatorResponse } from "./dao/chat/chat.dao";
|
|
6
6
|
export { FolderDAO } from "./dao/folder/folder.dao";
|
|
7
7
|
export { LocationDAO } from "./dao/location/location.dao";
|
|
8
8
|
export { MessageDAO } from "./dao/message/message.dao";
|