@ewb/mongoose-query-express 0.0.4 → 0.1.0
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/lib/QueryExpress.d.ts +7 -4
- package/lib/QueryExpress.js +67 -56
- package/lib/QueryExpressSub.js +11 -12
- package/lib/declarations.d.ts +9 -7
- package/lib/index.d.ts +5 -4
- package/lib/index.js +11 -9
- package/package.json +1 -1
package/lib/QueryExpress.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { QueryModel } from '@ewb/mongoose-query';
|
|
1
|
+
import { ISearchPaginate, Query, QueryModel } from '@ewb/mongoose-query';
|
|
2
2
|
import { NextFunction, Request, Response } from 'express';
|
|
3
3
|
import mongoose from 'mongoose';
|
|
4
4
|
import { QueryExpressSub } from './QueryExpressSub.js';
|
|
5
5
|
export interface IQueryExpressOptions {
|
|
6
6
|
skipHandlerAction?: 'post' | 'patch' | 'archive' | 'findOne' | 'search' | 'delete' | 'export';
|
|
7
7
|
}
|
|
8
|
-
export interface IQueryExpressHandlerOptions<T extends object> {
|
|
8
|
+
export interface IQueryExpressHandlerOptions<R extends Request, T extends object> {
|
|
9
|
+
queryKey?: keyof R;
|
|
9
10
|
slugKey?: keyof T & string;
|
|
10
11
|
archiveKey?: keyof T;
|
|
11
12
|
history?: {
|
|
@@ -19,8 +20,8 @@ interface BulkProps {
|
|
|
19
20
|
export declare class QueryExpress<R extends Request, T extends mongoose.Document> {
|
|
20
21
|
private param;
|
|
21
22
|
private handler;
|
|
22
|
-
readonly options: IQueryExpressHandlerOptions<T>;
|
|
23
|
-
constructor(param: keyof R, handler: QueryModel<T>, options?: IQueryExpressHandlerOptions<T>);
|
|
23
|
+
readonly options: IQueryExpressHandlerOptions<R, T>;
|
|
24
|
+
constructor(param: keyof R, handler: QueryModel<T>, options?: IQueryExpressHandlerOptions<R, T>);
|
|
24
25
|
post(req: R, res: Response, next: NextFunction): Promise<void>;
|
|
25
26
|
findOne(req: R, _res: Response, next: NextFunction): Promise<void>;
|
|
26
27
|
search(req: R, res: Response, next: NextFunction): Promise<void | Response<any, Record<string, any>>>;
|
|
@@ -46,6 +47,8 @@ export declare class QueryExpress<R extends Request, T extends mongoose.Document
|
|
|
46
47
|
preHistory(req: R): void;
|
|
47
48
|
postHistory(req: R, fetchNew?: boolean): Promise<void>;
|
|
48
49
|
init(req: R): void;
|
|
50
|
+
query(req: R): Query<T, object, import("@ewb/mongoose-query").IMongooseQueryOptions>;
|
|
51
|
+
pageLinkHeader(req: R, data: ISearchPaginate<any>): string;
|
|
49
52
|
private getDoc;
|
|
50
53
|
private validateBody;
|
|
51
54
|
private getFindOpts;
|
package/lib/QueryExpress.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { QueryError } from '@ewb/mongoose-query';
|
|
1
|
+
import { getPageLinkHeader, QueryError, } from '@ewb/mongoose-query';
|
|
2
2
|
import httpStatus from 'http-status';
|
|
3
3
|
import mongoose from 'mongoose';
|
|
4
4
|
import { QueryExpressSub } from './QueryExpressSub.js';
|
|
5
|
-
import { pageLinkHeader } from './utils.js';
|
|
6
5
|
export class QueryExpress {
|
|
7
6
|
constructor(param, handler, options = {}) {
|
|
8
7
|
this.param = param;
|
|
@@ -28,18 +27,18 @@ export class QueryExpress {
|
|
|
28
27
|
}
|
|
29
28
|
async post(req, res, next) {
|
|
30
29
|
try {
|
|
31
|
-
if (req.
|
|
30
|
+
if (req.ewb.queryOptions.skipHandlerAction === 'post') {
|
|
32
31
|
return next();
|
|
33
32
|
}
|
|
34
33
|
this.validateBody(req);
|
|
35
34
|
this.init(req);
|
|
36
|
-
if (req.
|
|
37
|
-
for (const key in req.
|
|
38
|
-
req.body[key] = req.
|
|
35
|
+
if (req.ewb.queryPostBody) {
|
|
36
|
+
for (const key in req.ewb.queryPostBody) {
|
|
37
|
+
req.body[key] = req.ewb.queryPostBody[key];
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
40
|
req[this.param] = (await this.handler.create(req.body));
|
|
42
|
-
await this.handler.populate(req
|
|
41
|
+
await this.handler.populate(this.query(req), this.getDoc(req));
|
|
43
42
|
res.status(201);
|
|
44
43
|
next();
|
|
45
44
|
}
|
|
@@ -49,16 +48,16 @@ export class QueryExpress {
|
|
|
49
48
|
}
|
|
50
49
|
async findOne(req, _res, next) {
|
|
51
50
|
try {
|
|
52
|
-
if (req.
|
|
51
|
+
if (req.ewb.queryOptions.skipHandlerAction === 'findOne') {
|
|
53
52
|
return next();
|
|
54
53
|
}
|
|
55
54
|
this.init(req);
|
|
56
55
|
this.addRootRequest(req);
|
|
57
|
-
req[this.param] = (await this.handler.findOne(req
|
|
56
|
+
req[this.param] = (await this.handler.findOne(this.query(req), this.getFindOpts(req)));
|
|
58
57
|
this.preHistory(req);
|
|
59
58
|
this.removeRootRequest(req, this.options.slugKey);
|
|
60
59
|
this.validateReq(req);
|
|
61
|
-
await this.handler.populate(req
|
|
60
|
+
await this.handler.populate(this.query(req), this.getDoc(req), 'onFindOne');
|
|
62
61
|
next();
|
|
63
62
|
}
|
|
64
63
|
catch (e) {
|
|
@@ -67,11 +66,11 @@ export class QueryExpress {
|
|
|
67
66
|
}
|
|
68
67
|
async search(req, res, next) {
|
|
69
68
|
try {
|
|
70
|
-
if (req.
|
|
69
|
+
if (req.ewb.queryOptions.skipHandlerAction === 'search') {
|
|
71
70
|
return next();
|
|
72
71
|
}
|
|
73
72
|
const data = await this._search(req, res);
|
|
74
|
-
if (req.query.as === 'array' || req.
|
|
73
|
+
if (req.query.as === 'array' || this.query(req).page > 0) {
|
|
75
74
|
return res.json(data.data);
|
|
76
75
|
}
|
|
77
76
|
return res.json(data);
|
|
@@ -82,10 +81,10 @@ export class QueryExpress {
|
|
|
82
81
|
}
|
|
83
82
|
async searchNext(req, res, next) {
|
|
84
83
|
try {
|
|
85
|
-
if (req.
|
|
84
|
+
if (req.ewb.queryOptions.skipHandlerAction === 'search') {
|
|
86
85
|
return next();
|
|
87
86
|
}
|
|
88
|
-
req.
|
|
87
|
+
req.ewb.querySearchJson = await this._search(req, res);
|
|
89
88
|
next();
|
|
90
89
|
}
|
|
91
90
|
catch (e) {
|
|
@@ -94,23 +93,23 @@ export class QueryExpress {
|
|
|
94
93
|
}
|
|
95
94
|
async _search(req, res) {
|
|
96
95
|
this.init(req);
|
|
97
|
-
req.
|
|
98
|
-
const data = await this.handler.search(req
|
|
99
|
-
res.setHeader('Link', pageLinkHeader(req, data));
|
|
96
|
+
this.query(req).removeQuery('as');
|
|
97
|
+
const data = await this.handler.search(this.query(req));
|
|
98
|
+
res.setHeader('Link', this.pageLinkHeader(req, data));
|
|
100
99
|
res.setHeader('X-Total-Count', data.count);
|
|
101
100
|
return data;
|
|
102
101
|
}
|
|
103
102
|
async export(req, res, next) {
|
|
104
103
|
try {
|
|
105
|
-
if (req.
|
|
104
|
+
if (req.ewb.queryOptions.skipHandlerAction === 'export') {
|
|
106
105
|
return next();
|
|
107
106
|
}
|
|
108
107
|
this.init(req);
|
|
109
|
-
req.
|
|
110
|
-
const paginate = await this.handler.search(req
|
|
111
|
-
res.setHeader('Link', pageLinkHeader(req, paginate));
|
|
108
|
+
this.query(req).export = true;
|
|
109
|
+
const paginate = await this.handler.search(this.query(req));
|
|
110
|
+
res.setHeader('Link', this.pageLinkHeader(req, paginate));
|
|
112
111
|
res.setHeader('X-Total-Count', paginate.count);
|
|
113
|
-
req.
|
|
112
|
+
req.ewb.queryExportJson = paginate.data;
|
|
114
113
|
next();
|
|
115
114
|
}
|
|
116
115
|
catch (e) {
|
|
@@ -119,16 +118,16 @@ export class QueryExpress {
|
|
|
119
118
|
}
|
|
120
119
|
async patch(req, _res, next) {
|
|
121
120
|
try {
|
|
122
|
-
if (req.
|
|
121
|
+
if (req.ewb.queryOptions.skipHandlerAction === 'patch') {
|
|
123
122
|
return next();
|
|
124
123
|
}
|
|
125
124
|
this.validateReq(req);
|
|
126
125
|
this.validateBody(req);
|
|
127
126
|
this.init(req);
|
|
128
|
-
const query = req
|
|
127
|
+
const query = this.query(req);
|
|
129
128
|
req[this.param] = (await this.handler.findOneAndUpdate(query, { _id: this.getDoc(req)._id }, { $set: req.body }));
|
|
130
129
|
this.postHistory(req).then();
|
|
131
|
-
await this.handler.populate(req
|
|
130
|
+
await this.handler.populate(this.query(req), this.getDoc(req), 'onPatch');
|
|
132
131
|
next();
|
|
133
132
|
}
|
|
134
133
|
catch (e) {
|
|
@@ -137,12 +136,12 @@ export class QueryExpress {
|
|
|
137
136
|
}
|
|
138
137
|
async archive(req, _res, next) {
|
|
139
138
|
try {
|
|
140
|
-
if (req.
|
|
139
|
+
if (req.ewb.queryOptions.skipHandlerAction === 'archive') {
|
|
141
140
|
return next();
|
|
142
141
|
}
|
|
143
142
|
this.validateReq(req);
|
|
144
143
|
this.init(req);
|
|
145
|
-
req[this.param] = (await this.handler.findOneAndUpdate(req
|
|
144
|
+
req[this.param] = (await this.handler.findOneAndUpdate(this.query(req), { _id: this.getDoc(req)._id }, { [this.options.archiveKey]: true }));
|
|
146
145
|
this.postHistory(req).then();
|
|
147
146
|
next();
|
|
148
147
|
}
|
|
@@ -152,7 +151,7 @@ export class QueryExpress {
|
|
|
152
151
|
}
|
|
153
152
|
async delete(req, _res, next) {
|
|
154
153
|
try {
|
|
155
|
-
if (req.
|
|
154
|
+
if (req.ewb.queryOptions.skipHandlerAction === 'delete') {
|
|
156
155
|
return next();
|
|
157
156
|
}
|
|
158
157
|
this.validateReq(req);
|
|
@@ -187,9 +186,9 @@ export class QueryExpress {
|
|
|
187
186
|
const ids = this.validateIdsInBody(req);
|
|
188
187
|
delete req.body.ids;
|
|
189
188
|
this.handler.validateBody(req.body);
|
|
190
|
-
await this.handler.updateMany(req.
|
|
191
|
-
req.
|
|
192
|
-
req.
|
|
189
|
+
await this.handler.updateMany(this.query(req).root || {}, ids, req.body);
|
|
190
|
+
this.query(req).addRoot({ _id: { $in: ids } });
|
|
191
|
+
this.query(req).setSkipAndLimit(0, ids.length);
|
|
193
192
|
req.query.as = 'array';
|
|
194
193
|
return this.search(req, res, next);
|
|
195
194
|
}
|
|
@@ -201,7 +200,7 @@ export class QueryExpress {
|
|
|
201
200
|
return async (req, res, next) => {
|
|
202
201
|
try {
|
|
203
202
|
const ids = this.validateIdsInBody(req);
|
|
204
|
-
const deleted = await this.handler.deleteMany(req.
|
|
203
|
+
const deleted = await this.handler.deleteMany(this.query(req).root || {}, ids);
|
|
205
204
|
if (runNext) {
|
|
206
205
|
return next();
|
|
207
206
|
}
|
|
@@ -216,7 +215,7 @@ export class QueryExpress {
|
|
|
216
215
|
return async (req, res, next) => {
|
|
217
216
|
try {
|
|
218
217
|
const ids = this.validateIdsInBody(req);
|
|
219
|
-
await this.handler.updateMany(req.
|
|
218
|
+
await this.handler.updateMany(this.query(req).root || {}, ids, {
|
|
220
219
|
[this.options.archiveKey]: true,
|
|
221
220
|
});
|
|
222
221
|
if (runNext) {
|
|
@@ -234,7 +233,7 @@ export class QueryExpress {
|
|
|
234
233
|
try {
|
|
235
234
|
const data = fn(req);
|
|
236
235
|
if (data) {
|
|
237
|
-
req.
|
|
236
|
+
this.query(req).addRootNext(data);
|
|
238
237
|
}
|
|
239
238
|
next();
|
|
240
239
|
}
|
|
@@ -247,12 +246,12 @@ export class QueryExpress {
|
|
|
247
246
|
try {
|
|
248
247
|
this.validateReq(req);
|
|
249
248
|
this.init(req);
|
|
250
|
-
if (!req.
|
|
251
|
-
req.
|
|
249
|
+
if (!req.ewb.queryPostBody) {
|
|
250
|
+
req.ewb.queryPostBody = {};
|
|
252
251
|
}
|
|
253
252
|
const doc = this.getDoc(req);
|
|
254
|
-
req.
|
|
255
|
-
req.
|
|
253
|
+
req.ewb.queryPostBody[this.param] = doc._id;
|
|
254
|
+
this.query(req).addRoot({
|
|
256
255
|
[this.param]: doc._id,
|
|
257
256
|
});
|
|
258
257
|
next();
|
|
@@ -265,7 +264,7 @@ export class QueryExpress {
|
|
|
265
264
|
return new QueryExpressSub(this.handler, this, reqKey, subArrayKey);
|
|
266
265
|
}
|
|
267
266
|
addRootRequest(req) {
|
|
268
|
-
req.
|
|
267
|
+
this.query(req).addRoot(this.getRootQuery(req));
|
|
269
268
|
}
|
|
270
269
|
getRootQuery(req) {
|
|
271
270
|
const param = this.getParam(req);
|
|
@@ -283,14 +282,11 @@ export class QueryExpress {
|
|
|
283
282
|
});
|
|
284
283
|
}
|
|
285
284
|
removeRootRequest(req, slugKey) {
|
|
286
|
-
req.
|
|
287
|
-
'_id',
|
|
288
|
-
...(slugKey ? [slugKey] : []),
|
|
289
|
-
]);
|
|
285
|
+
this.query(req).deleteKeysFromRoot(['_id', ...(slugKey ? [slugKey] : [])]);
|
|
290
286
|
}
|
|
291
287
|
addToQuery(req, _res, next) {
|
|
292
288
|
try {
|
|
293
|
-
req.
|
|
289
|
+
this.query(req).addRoot({
|
|
294
290
|
[this.param]: this.getDoc(req)._id,
|
|
295
291
|
});
|
|
296
292
|
next();
|
|
@@ -302,10 +298,10 @@ export class QueryExpress {
|
|
|
302
298
|
addToPost(req, _res, next) {
|
|
303
299
|
try {
|
|
304
300
|
this.validateReq(req);
|
|
305
|
-
if (!req.
|
|
306
|
-
req.
|
|
301
|
+
if (!req.ewb.queryPostBody) {
|
|
302
|
+
req.ewb.queryPostBody = {};
|
|
307
303
|
}
|
|
308
|
-
req.
|
|
304
|
+
req.ewb.queryPostBody[this.param] = this.getDoc(req)._id;
|
|
309
305
|
next();
|
|
310
306
|
}
|
|
311
307
|
catch (e) {
|
|
@@ -324,26 +320,41 @@ export class QueryExpress {
|
|
|
324
320
|
return req.params[param];
|
|
325
321
|
}
|
|
326
322
|
preHistory(req) {
|
|
327
|
-
if (this.options.history?.active && req.
|
|
323
|
+
if (this.options.history?.active && req.ewb.queryHistory) {
|
|
328
324
|
if (this.options.history.ignoreFields) {
|
|
329
|
-
req.
|
|
325
|
+
req.ewb.queryHistory.setIgnoreFields(this.options.history.ignoreFields);
|
|
330
326
|
}
|
|
331
|
-
req.
|
|
332
|
-
req.
|
|
327
|
+
req.ewb.queryHistory.setModel(this.handler.model);
|
|
328
|
+
req.ewb.queryHistory.setOldDoc(this.getDoc(req).toObject());
|
|
333
329
|
}
|
|
334
330
|
}
|
|
335
331
|
async postHistory(req, fetchNew) {
|
|
336
|
-
if (this.options.history?.active && req.
|
|
332
|
+
if (this.options.history?.active && req.ewb.queryHistory) {
|
|
337
333
|
let doc = this.getDoc(req);
|
|
338
334
|
if (fetchNew) {
|
|
339
|
-
doc = await req.
|
|
335
|
+
doc = await req.ewb.queryHistory.findUpdated();
|
|
340
336
|
}
|
|
341
|
-
req.
|
|
342
|
-
req.
|
|
337
|
+
req.ewb.queryHistory.setUpdatedDoc(doc);
|
|
338
|
+
req.ewb.queryHistory.setDiff(doc._id).then();
|
|
343
339
|
}
|
|
344
340
|
}
|
|
345
341
|
init(req) {
|
|
346
|
-
req.
|
|
342
|
+
this.query(req).parameter = this.param;
|
|
343
|
+
}
|
|
344
|
+
query(req) {
|
|
345
|
+
if (this.options.queryKey in req) {
|
|
346
|
+
return req[this.options.queryKey];
|
|
347
|
+
}
|
|
348
|
+
if (!req.ewb.query) {
|
|
349
|
+
throw new QueryError(httpStatus.INTERNAL_SERVER_ERROR, 'Query not init', {
|
|
350
|
+
detail: `ewb.query missing or queryKey option missing in QueryExpress ${String(this.param)}`,
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
return req.ewb.query;
|
|
354
|
+
}
|
|
355
|
+
pageLinkHeader(req, data) {
|
|
356
|
+
const rootUrl = req.protocol + '://' + req.get('host') + req.originalUrl;
|
|
357
|
+
return getPageLinkHeader(rootUrl, this.query(req), data);
|
|
347
358
|
}
|
|
348
359
|
getDoc(req, param = this.param) {
|
|
349
360
|
return req[param];
|
package/lib/QueryExpressSub.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { QueryError } from '@ewb/mongoose-query';
|
|
2
2
|
import httpStatus from 'http-status';
|
|
3
3
|
import mongoose from 'mongoose';
|
|
4
|
-
import { pageLinkHeader } from './utils.js';
|
|
5
4
|
export class QueryExpressSub {
|
|
6
5
|
constructor(handler, express, reqKey, param) {
|
|
7
6
|
this.handler = handler;
|
|
@@ -18,11 +17,11 @@ export class QueryExpressSub {
|
|
|
18
17
|
async post(req, _res, next) {
|
|
19
18
|
try {
|
|
20
19
|
this.express.addRootRequest(req);
|
|
21
|
-
req[this.reqKey] = (await this.handler.subCreate(this.param, req
|
|
20
|
+
req[this.reqKey] = (await this.handler.subCreate(this.param, this.express.query(req), req.body));
|
|
22
21
|
this.validateReq(req);
|
|
23
22
|
this.express.postHistory(req, true).then();
|
|
24
23
|
this.express.removeRootRequest(req, this.express.options.slugKey);
|
|
25
|
-
await this.handler.subPopulate(req
|
|
24
|
+
await this.handler.subPopulate(this.express.query(req), this.getSubDoc(req), this.param, 'onPost');
|
|
26
25
|
next();
|
|
27
26
|
}
|
|
28
27
|
catch (e) {
|
|
@@ -31,11 +30,11 @@ export class QueryExpressSub {
|
|
|
31
30
|
}
|
|
32
31
|
async search(req, res, next) {
|
|
33
32
|
try {
|
|
34
|
-
req.
|
|
35
|
-
const results = (await this.handler.subSearch(this.param, req
|
|
36
|
-
res.setHeader('Link', pageLinkHeader(req, results));
|
|
33
|
+
this.express.query(req).removeQuery('as');
|
|
34
|
+
const results = (await this.handler.subSearch(this.param, this.express.query(req), this.express.getRootQuery(req)));
|
|
35
|
+
res.setHeader('Link', this.express.pageLinkHeader(req, results));
|
|
37
36
|
res.setHeader('X-Total-Count', results.count);
|
|
38
|
-
if (req.query.as === 'array' || req.
|
|
37
|
+
if (req.query.as === 'array' || this.express.query(req).page > 0) {
|
|
39
38
|
return res.json(results.data);
|
|
40
39
|
}
|
|
41
40
|
res.json(results);
|
|
@@ -47,10 +46,10 @@ export class QueryExpressSub {
|
|
|
47
46
|
async findOne(req, _res, next) {
|
|
48
47
|
try {
|
|
49
48
|
this.express.addRootRequest(req);
|
|
50
|
-
req[this.reqKey] = (await this.handler.subFindOne(this.param, req
|
|
49
|
+
req[this.reqKey] = (await this.handler.subFindOne(this.param, this.express.query(req), this.getQuery(req)));
|
|
51
50
|
this.validateReq(req);
|
|
52
51
|
this.express.removeRootRequest(req, this.express.options.slugKey);
|
|
53
|
-
await this.handler.subPopulate(req
|
|
52
|
+
await this.handler.subPopulate(this.express.query(req), this.getSubDoc(req), this.param, 'onFindOne');
|
|
54
53
|
next();
|
|
55
54
|
}
|
|
56
55
|
catch (e) {
|
|
@@ -60,11 +59,11 @@ export class QueryExpressSub {
|
|
|
60
59
|
async patch(req, _res, next) {
|
|
61
60
|
try {
|
|
62
61
|
this.express.addRootRequest(req);
|
|
63
|
-
req[this.reqKey] = (await this.handler.subFindOneAndUpdate(this.param, req
|
|
62
|
+
req[this.reqKey] = (await this.handler.subFindOneAndUpdate(this.param, this.express.query(req), this.getQuery(req), req.body));
|
|
64
63
|
this.validateReq(req);
|
|
65
64
|
this.express.postHistory(req, true).then();
|
|
66
65
|
this.express.removeRootRequest(req, this.express.options.slugKey);
|
|
67
|
-
await this.handler.subPopulate(req
|
|
66
|
+
await this.handler.subPopulate(this.express.query(req), this.getSubDoc(req), this.param, 'onPatch');
|
|
68
67
|
next();
|
|
69
68
|
}
|
|
70
69
|
catch (e) {
|
|
@@ -74,7 +73,7 @@ export class QueryExpressSub {
|
|
|
74
73
|
async delete(req, _res, next) {
|
|
75
74
|
try {
|
|
76
75
|
this.express.addRootRequest(req);
|
|
77
|
-
req[this.reqKey] = (await this.handler.subDelete(this.param, req
|
|
76
|
+
req[this.reqKey] = (await this.handler.subDelete(this.param, this.express.query(req), this.getQuery(req)));
|
|
78
77
|
this.express.postHistory(req, true).then();
|
|
79
78
|
this.validateReq(req);
|
|
80
79
|
this.express.removeRootRequest(req, this.express.options.slugKey);
|
package/lib/declarations.d.ts
CHANGED
|
@@ -5,14 +5,16 @@ declare global {
|
|
|
5
5
|
namespace Express {
|
|
6
6
|
interface Request {
|
|
7
7
|
id: string;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
ewb: {
|
|
9
|
+
query: Query<any>;
|
|
10
|
+
queryHistory?: QueryHistory<any>;
|
|
11
|
+
queryOptions: IQueryExpressOptions;
|
|
12
|
+
queryPostBody?: {
|
|
13
|
+
[key: string]: string | mongoose.Types.ObjectId;
|
|
14
|
+
};
|
|
15
|
+
queryExportJson?: any[];
|
|
16
|
+
querySearchJson?: ISearchPaginate<any>;
|
|
13
17
|
};
|
|
14
|
-
mongooseExportJson?: any[];
|
|
15
|
-
mongooseSearchJson?: ISearchPaginate<any>;
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
20
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import './declarations.js';
|
|
2
|
-
import {
|
|
2
|
+
import { NextFunction, Request, Response } from 'express';
|
|
3
|
+
export * from '@ewb/mongoose-query';
|
|
3
4
|
export * from './QueryExpress.js';
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
export
|
|
5
|
+
import { QueryExpress } from './QueryExpress.js';
|
|
6
|
+
export declare function initQueryExpress(): (req: Request, _res: Response, next: NextFunction) => void;
|
|
7
|
+
export default QueryExpress;
|
package/lib/index.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import './declarations.js';
|
|
2
2
|
import { Query } from '@ewb/mongoose-query';
|
|
3
|
+
export * from '@ewb/mongoose-query';
|
|
3
4
|
export * from './QueryExpress.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { QueryExpress } from './QueryExpress.js';
|
|
6
|
+
export function initQueryExpress() {
|
|
7
|
+
return (req, _res, next) => {
|
|
8
|
+
req.ewb = {
|
|
9
|
+
...req.ewb,
|
|
10
|
+
query: new Query(req.query),
|
|
11
|
+
queryOptions: {},
|
|
12
|
+
};
|
|
7
13
|
next();
|
|
8
|
-
}
|
|
9
|
-
catch (e) {
|
|
10
|
-
next(e);
|
|
11
|
-
}
|
|
14
|
+
};
|
|
12
15
|
}
|
|
13
|
-
export default
|
|
14
|
-
export { queryExpress };
|
|
16
|
+
export default QueryExpress;
|