|
@@ -68,7 +68,7 @@ class CrudService extends NafService {
|
|
|
.map((f) => ({ [f]: desc ? -1 : 1 }))
|
|
|
.reduce((p, c) => ({ ...p, ...c }), {});
|
|
|
}
|
|
|
- filter = this.turnFilter(this.turnDateRangeQuery(filter));
|
|
|
+ filter = this.dealFilter(filter);
|
|
|
const rs = await this.model
|
|
|
.find(trimData(filter), projection, { skip, limit, sort })
|
|
|
.exec();
|
|
@@ -76,19 +76,23 @@ class CrudService extends NafService {
|
|
|
}
|
|
|
|
|
|
async count(filter) {
|
|
|
- filter = this.turnFilter(this.turnDateRangeQuery(filter));
|
|
|
+ filter = this.dealFilter(filter);
|
|
|
const res = await this.model.countDocuments(trimData(filter)).exec();
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
async queryAndCount(filter, options) {
|
|
|
- filter = this.turnFilter(this.turnDateRangeQuery(filter));
|
|
|
+ filter = this.dealFilter(filter);
|
|
|
const total = await this.count(filter);
|
|
|
if (total === 0) return { total, data: [] };
|
|
|
const rs = await this.query(filter, options);
|
|
|
return { total, data: rs };
|
|
|
}
|
|
|
|
|
|
+ dealFilter(filter) {
|
|
|
+ return this.turnFilter(this.turnDateRangeQuery(filter));
|
|
|
+ }
|
|
|
+
|
|
|
turnFilter(filter) {
|
|
|
let str = /^%\S*%$/;
|
|
|
let keys = Object.keys(filter);
|
|
@@ -96,7 +100,7 @@ class CrudService extends NafService {
|
|
|
let res = key.match(str);
|
|
|
if (res) {
|
|
|
let newKey = key.slice(1, key.length - 1);
|
|
|
- filter[newKey] = new RegExp(filter[key]);
|
|
|
+ if(!ObjectId.isValid(filter[key])) filter[newKey] = new RegExp(filter[key]);
|
|
|
delete filter[key];
|
|
|
}
|
|
|
}
|