lrf cd40025c47 更新 'README.md' | 3 years ago | |
---|---|---|
.github | 4 years ago | |
.vscode | 4 years ago | |
app | 3 years ago | |
config | 3 years ago | |
test | 4 years ago | |
.autod.conf.js | 4 years ago | |
.eslintignore | 4 years ago | |
.eslintrc | 4 years ago | |
.gitignore | 3 years ago | |
.travis.yml | 4 years ago | |
README.md | 3 years ago | |
app.js | 4 years ago | |
appveyor.yml | 4 years ago | |
ecosystem.config.js | 4 years ago | |
package.json | 3 years ago | |
server.js | 3 years ago |
此项目没有修改框架,所以model部分如果使用子目录,会引发错误,controller和service,router使用子目录不会产生bug
添加模糊查询
符号及使用=>在parameters中的query
{key:value} => {key:%value%}
位置:
naf-framework-mongoose>lib>service>crud-service
中 lodash引入部分添加get
函数的引入
query
和count
在操作model前
加上下面的代码
filter = this.turnFilter(filter);
之后添加函数 turnFilter
turnFilter(filter){
let str = /^%\S*%$/;
let keys = Object.keys(filter);
for (const key of keys) {
let res = key.match(str);
if (res) {
let newKey = key.slice(1, key.length - 1);
filter[newKey] = new RegExp(filter[key]);
delete filter[key];
}
}
return filter;
}
添加日期范围查询
符号及使用=>在parameters中的query,
{key:value} => {'${key}@start/end':'${key}@start/end'}
位置:
naf-framework-mongoose>lib>service>crud-service
中
query
和count
在操作model前
加上下面的代码
filter = this.turnDateRangeQuery(filter);
之后添加函数 turnDateRangeQuery
turnDateRangeQuery(filter){
const keys = Object.keys(filter);
for (const k of keys) {
if (k.includes('@')) {
const karr = k.split('@');
// 因为是针对处理范围日期,所以必须只有,开始时间和结束时间
if (karr.length === 2) {
const type = karr[1];
if (type === 'start') filter[karr[0]] = { ...get(filter, karr[0], {}), $gte: filter[k] };
else filter[karr[0]] = { ...get(filter, karr[0], {}), $lte: filter[k] };
delete filter[k]
}
}
}
return filter;
}
filter = this.turnFilter(this.turnDateRangeQuery(filter));