服务端

lrf cd40025c47 更新 'README.md' 3 years ago
.github 8e97d3d13f 1 4 years ago
.vscode 8e97d3d13f 1 4 years ago
app 2354f2f62c update 3 years ago
config 0e45177d28 update 3 years ago
test 8e97d3d13f 1 4 years ago
.autod.conf.js 8e97d3d13f 1 4 years ago
.eslintignore 8e97d3d13f 1 4 years ago
.eslintrc 8e97d3d13f 1 4 years ago
.gitignore 51dc165bbd update 3 years ago
.travis.yml 8e97d3d13f 1 4 years ago
README.md cd40025c47 更新 'README.md' 3 years ago
app.js 8e97d3d13f 1 4 years ago
appveyor.yml 8e97d3d13f 1 4 years ago
ecosystem.config.js dcbc36fb0a 1 4 years ago
package.json 313a4e11eb update 3 years ago
server.js 4737dddc5f update 3 years ago

README.md

servec-zhwl

此项目没有修改框架,所以model部分如果使用子目录,会引发错误,controller和service,router使用子目录不会产生bug

添加模糊查询

符号及使用=>在parameters中的query{key:value} => {key:%value%}

位置:naf-framework-mongoose>lib>service>crud-service中 lodash引入部分添加 get 函数的引入

querycount操作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

querycount操作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;
  }

如果以上两个查询都添加,则在查询前(find())直接使用下面的代码

filter = this.turnFilter(this.turnDateRangeQuery(filter));