guhongwei hace 3 años
padre
commit
e7e1e31615
Se han modificado 1 ficheros con 13 adiciones y 13 borrados
  1. 13 13
      app/service/users/personal.js

+ 13 - 13
app/service/users/personal.js

@@ -20,8 +20,7 @@ class PersonalService extends CrudService {
   }
   async query(condition, { skip = 0, limit = 0 }) {
     const query = await this.dealQueryCondition(_.cloneDeep(condition));
-    console.log(query);
-    const res = await this.model.find(query).skip(parseInt(skip)).limit(parseInt(limit));
+    const res = await this.model.find(query).skip(parseInt(skip)).limit(parseInt(limit).sort({'meta.createdAt':-1})
     return res;
   }
   async count(condition) {
@@ -33,16 +32,17 @@ class PersonalService extends CrudService {
   async dealQueryCondition({ role, code, ...condition } = {}) {
     condition = this.util.dealQuery(condition);
     if (role === '1') {
-      //code查询机构,取出机构的code,用code到model(个人用户)里查询用户,合为一个数组,返回
+      // code查询机构,取出机构的code,用code到model(个人用户)里查询用户,合为一个数组,返回
       const orgRes = await this.adminModel.find({ code }, { _id: 1 });
-      const ids = orgRes.map((i) => i._id);
+      const ids = orgRes.map(i => i._id);
       const res2 = await this.adminModel.find({ pid: ids, role: '2' }, { code });
-      const codes = res2.map((i) => i.code);
+      const codes = res2.map(i => i.code);
       condition.code = codes;
     } else if (code) {
-      //code直接查询用户返回即可
+      // code直接查询用户返回即可
       condition.code = code;
     }
+    condition.sort = '-1';
     return condition;
   }
   /**
@@ -81,7 +81,7 @@ class PersonalService extends CrudService {
     const { secret } = op;
     if (status !== '1') throw new BusinessError(ErrorCode.ACCESS_DENIED, '拒绝访问!');
     if (secret !== password) throw new BusinessError(ErrorCode.BAD_PASSWORD, '密码错误');
-    const data = _.omit(JSON.parse(JSON.stringify(object)), ['meta', 'password', '__v']);
+    const data = _.omit(JSON.parse(JSON.stringify(object)), [ 'meta', 'password', '__v' ]);
     const { secret: secrets } = this.config.jwt;
     const token = jwt.sign(data, secrets);
     // 记录登陆
@@ -106,7 +106,7 @@ class PersonalService extends CrudService {
     assert(id, '缺少个人用户ID');
     const user = await this.model.findOne({ _id: ObjectId(id) }, '+password');
     if (!user) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到用户的信息');
-    data = _.omit(data, ['meta', '__v']);
+    data = _.omit(data, [ 'meta', '__v' ]);
     data.user_id = id;
     // 创建专家
     const is_expert = await this.ctx.model.Expert.count({ user_id: ObjectId(id) });
@@ -132,11 +132,11 @@ class PersonalService extends CrudService {
     for (let i = 0; i < head.length; i++) {
       const e = head[i];
       if (!e) continue;
-      const r = meta.find((f) => f.column === e);
+      const r = meta.find(f => f.column === e);
       if (r) r.index = i;
     }
     // 过滤出列表中不必要且不存在的字段
-    meta = meta.filter((f) => f.required || f.index);
+    meta = meta.filter(f => f.required || f.index);
     const errorList = [];
     const dataList = [];
     sheet.eachRow(async (row, index) => {
@@ -216,7 +216,7 @@ class PersonalService extends CrudService {
     const workbook = new Excel.stream.xlsx.WorkbookWriter(options);
     const sheet = workbook.addWorksheet('sheet');
     const eMeta = this.exportMeta();
-    const eColumn = eMeta.map((i) => i.key);
+    const eColumn = eMeta.map(i => i.key);
     let needDeal = eMeta.map((i, index) => {
       if (_.isFunction(_.get(i, 'method'))) {
         i.index = index;
@@ -226,7 +226,7 @@ class PersonalService extends CrudService {
     needDeal = _.compact(needDeal);
     for (let i = 1; i <= times; i++) {
       if (i === 1) {
-        const head = eMeta.map((i) => i.zh);
+        const head = eMeta.map(i => i.zh);
         sheet.addRow(head).commit();
       }
       const data = await this.model.find({ isdel: 0 }, '+password').skip(skip).limit(limit);
@@ -251,7 +251,7 @@ class PersonalService extends CrudService {
     return [
       { key: 'name', zh: '用户名' },
       { key: 'phone', zh: '手机号' },
-      { key: 'password', zh: '登录密码', method: (i) => _.get(i, 'secret') },
+      { key: 'password', zh: '登录密码', method: i => _.get(i, 'secret') },
       { key: 'code', zh: '邀请码' },
       { key: 'card', zh: '身份证号' },
       { key: 'email', zh: '邮箱' },