@trafficgroup/knex-rel 0.1.10 → 0.1.11
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/dao/chat/chat.dao.d.ts +4 -1
- package/dist/dao/chat/chat.dao.js +21 -9
- package/dist/dao/chat/chat.dao.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- 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
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { IBaseDAO, IDataPaginator } from "../../d.types";
|
|
2
2
|
import { IChat, IChatCreate, IChatUpdate } from '../../interfaces/chat/chat.interfaces';
|
|
3
|
+
export interface IChatPaginatorResponse extends IDataPaginator<IChat> {
|
|
4
|
+
hasMore: boolean;
|
|
5
|
+
}
|
|
3
6
|
export declare class ChatDAO implements IBaseDAO<IChat> {
|
|
4
7
|
private _knex;
|
|
5
8
|
create(item: IChatCreate): Promise<IChat>;
|
|
@@ -9,5 +12,5 @@ export declare class ChatDAO implements IBaseDAO<IChat> {
|
|
|
9
12
|
update(id: number, item: IChatUpdate): Promise<IChat | null>;
|
|
10
13
|
delete(id: number): Promise<boolean>;
|
|
11
14
|
getByUserId(userId: number, page?: number, limit?: number): Promise<IDataPaginator<IChat>>;
|
|
12
|
-
getActiveByUserId(userId: number, page?: number, limit?: number): Promise<
|
|
15
|
+
getActiveByUserId(userId: number, page?: number, limit?: number, query?: string): Promise<IChatPaginatorResponse>;
|
|
13
16
|
}
|
|
@@ -107,21 +107,32 @@ class ChatDAO {
|
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
getActiveByUserId(userId_1) {
|
|
110
|
-
return __awaiter(this, arguments, void 0, function* (userId, page = 1, limit = 10) {
|
|
110
|
+
return __awaiter(this, arguments, void 0, function* (userId, page = 1, limit = 10, query) {
|
|
111
111
|
const offset = (page - 1) * limit;
|
|
112
|
+
// Build data query
|
|
113
|
+
let dataQuery = this._knex('chat')
|
|
114
|
+
.where('userId', userId)
|
|
115
|
+
.where('status', 'active');
|
|
116
|
+
// Build count query
|
|
117
|
+
let countQuery = this._knex('chat')
|
|
118
|
+
.where('userId', userId)
|
|
119
|
+
.where('status', 'active');
|
|
120
|
+
// Apply search filter if query is provided
|
|
121
|
+
if (query && query.trim()) {
|
|
122
|
+
const searchTerm = `%${query.trim()}%`;
|
|
123
|
+
dataQuery = dataQuery.where('title', 'ILIKE', searchTerm);
|
|
124
|
+
countQuery = countQuery.where('title', 'ILIKE', searchTerm);
|
|
125
|
+
}
|
|
112
126
|
const [results, [{ count }]] = yield Promise.all([
|
|
113
|
-
|
|
114
|
-
.where('userId', userId)
|
|
115
|
-
.where('status', 'active')
|
|
127
|
+
dataQuery
|
|
116
128
|
.orderBy('created_at', 'desc')
|
|
117
129
|
.limit(limit)
|
|
118
130
|
.offset(offset),
|
|
119
|
-
|
|
120
|
-
.where('userId', userId)
|
|
121
|
-
.where('status', 'active')
|
|
122
|
-
.count('* as count')
|
|
131
|
+
countQuery.count('* as count')
|
|
123
132
|
]);
|
|
124
133
|
const totalCount = parseInt(count);
|
|
134
|
+
const totalPages = Math.ceil(totalCount / limit);
|
|
135
|
+
const hasMore = page < totalPages;
|
|
125
136
|
return {
|
|
126
137
|
success: true,
|
|
127
138
|
data: results,
|
|
@@ -129,7 +140,8 @@ class ChatDAO {
|
|
|
129
140
|
limit,
|
|
130
141
|
count: results.length,
|
|
131
142
|
totalCount,
|
|
132
|
-
totalPages
|
|
143
|
+
totalPages,
|
|
144
|
+
hasMore
|
|
133
145
|
};
|
|
134
146
|
});
|
|
135
147
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.dao.js","sourceRoot":"","sources":["../../../src/dao/chat/chat.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAGA,0EAA+C;
|
|
1
|
+
{"version":3,"file":"chat.dao.js","sourceRoot":"","sources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C,CAAC;gBAC1D,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;YAC9D,CAAC;YAED,MAAM,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;gBAC/C,SAAS;qBACN,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC;qBAC7B,KAAK,CAAC,KAAK,CAAC;qBACZ,MAAM,CAAC,MAAM,CAAC;gBACjB,UAAU,CAAC,KAAK,CAAC,YAAY,CAAC;aAC/B,CAAC,CAAC;YAEH,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAe,CAAC,CAAC;YAC7C,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,CAAC;YACjD,MAAM,OAAO,GAAG,IAAI,GAAG,UAAU,CAAC;YAElC,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,IAAI,EAAE,OAAO;gBACb,IAAI;gBACJ,KAAK;gBACL,KAAK,EAAE,OAAO,CAAC,MAAM;gBACrB,UAAU;gBACV,UAAU;gBACV,OAAO;aACR,CAAC;QACJ,CAAC;KAAA;CACF;AAtID,0BAsIC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { AuthDAO } from "./dao/auth/auth.dao";
|
|
2
2
|
export { BatchDAO } from "./dao/batch/batch.dao";
|
|
3
3
|
export { CameraDAO } from "./dao/camera/camera.dao";
|
|
4
|
-
export { ChatDAO } from "./dao/chat/chat.dao";
|
|
4
|
+
export { ChatDAO, IChatPaginatorResponse } from "./dao/chat/chat.dao";
|
|
5
5
|
export { FolderDAO } from "./dao/folder/folder.dao";
|
|
6
6
|
export { LocationDAO } from "./dao/location/location.dao";
|
|
7
7
|
export { MessageDAO } from "./dao/message/message.dao";
|
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,
|
|
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,gDAAsE;AAA7D,mGAAA,OAAO,OAAA;AAChB,sDAAoD;AAA3C,uGAAA,SAAS,OAAA;AAClB,4DAA0D;AAAjD,2GAAA,WAAW,OAAA;AACpB,yDAAuD;AAA9C,yGAAA,UAAU,OAAA;AACnB,gGAA6F;AAApF,kIAAA,sBAAsB,OAAA;AAC/B,mDAAiD;AAAxC,qGAAA,QAAQ,OAAA;AACjB,gDAA8C;AAArC,mGAAA,OAAO,OAAA;AAChB,wHAAmH;AAA1G,gJAAA,4BAA4B,OAAA;AACrC,mDAAiD;AAAxC,qGAAA,QAAQ,OAAA;AACjB,mEAAkE;AAAzD,4HAAA,oBAAoB,OAAA;AAE7B,YAAY;AACZ,+DAIqC;AAHjC,0HAAA,uBAAuB,OAAA;AACvB,oHAAA,iBAAiB,OAAA;AACjB,wHAAA,qBAAqB,OAAA;AAkCzB,sEAA2C;AAClC,sBADF,wBAAW,CACE"}
|
package/package.json
CHANGED
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";
|