|
@@ -9,7 +9,7 @@ const jwt = require('jsonwebtoken');
|
|
|
|
|
|
class UserService extends CrudService {
|
|
|
constructor(ctx) {
|
|
|
- super(ctx, 'user');
|
|
|
+ super(ctx, "user");
|
|
|
this.model = this.ctx.model.User;
|
|
|
this.rmodel = this.ctx.model.Role;
|
|
|
}
|
|
@@ -18,8 +18,8 @@ class UserService extends CrudService {
|
|
|
async create(data) {
|
|
|
const { name, phone, passwd } = data;
|
|
|
console.log(data);
|
|
|
- assert(name && phone && passwd, '缺少部分信息项');
|
|
|
- assert(/^\d{11}$/i.test(phone), 'phone无效');
|
|
|
+ assert(name && phone && passwd, "缺少部分信息项");
|
|
|
+ assert(/^\d{11}$/i.test(phone), "phone无效");
|
|
|
// const user = await this.model.findOne({ phone });
|
|
|
// if (user) {
|
|
|
// throw new BusinessError(ErrorCode.DATA_EXISTED);
|
|
@@ -40,8 +40,20 @@ class UserService extends CrudService {
|
|
|
|
|
|
// 重写修改方法
|
|
|
async update({ id }, data) {
|
|
|
- const { name, phone, passwd, openid, role, menus, remark, uid, deptid, deptname, pid } = data;
|
|
|
- const user = await this.model.findById(id, '+passwd');
|
|
|
+ const {
|
|
|
+ name,
|
|
|
+ phone,
|
|
|
+ passwd,
|
|
|
+ openid,
|
|
|
+ role,
|
|
|
+ menus,
|
|
|
+ remark,
|
|
|
+ uid,
|
|
|
+ deptid,
|
|
|
+ deptname,
|
|
|
+ pid,
|
|
|
+ } = data;
|
|
|
+ const user = await this.model.findById(id, "+passwd");
|
|
|
if (name) {
|
|
|
user.name = name;
|
|
|
}
|
|
@@ -82,9 +94,9 @@ class UserService extends CrudService {
|
|
|
// 用户修改密码
|
|
|
async uppasswd(data) {
|
|
|
const { id, oldpasswd, newpasswd } = data;
|
|
|
- assert(id && oldpasswd && newpasswd, '缺少部分信息项');
|
|
|
+ assert(id && oldpasswd && newpasswd, "缺少部分信息项");
|
|
|
// 根据用户id查询其他用户表中是否存在相应数据
|
|
|
- const user = await this.model.findById(id, '+passwd');
|
|
|
+ const user = await this.model.findById(id, "+passwd");
|
|
|
// 如果用户不存在抛出异常
|
|
|
if (!user) {
|
|
|
throw new BusinessError(ErrorCode.USER_NOT_EXIST);
|
|
@@ -141,12 +153,27 @@ class UserService extends CrudService {
|
|
|
}
|
|
|
|
|
|
async finduserlist({ skip, limit, ...info }) {
|
|
|
- const query = { ...info, $or: [{ role: '4' }, { role: '5' }, { role: '6' }] };
|
|
|
+ const query = {
|
|
|
+ ...info,
|
|
|
+ $or: [{ role: "4" }, { role: "5" }, { role: "6" }],
|
|
|
+ };
|
|
|
const total = await this.model.count(query);
|
|
|
- const data = await this.model.find(query).skip(Number(skip)).limit(Number(limit));
|
|
|
+ const data = await this.model
|
|
|
+ .find(query)
|
|
|
+ .skip(Number(skip))
|
|
|
+ .limit(Number(limit));
|
|
|
+ return { data, total };
|
|
|
+ }
|
|
|
+ async businessuser({ pid, skip, limit }) {
|
|
|
+ const query = { code: { $regex: /^.{9}$/ } };
|
|
|
+ pid ? (query.pid = pid) : "";
|
|
|
+ const total = await this.model.count(query);
|
|
|
+ const data = await this.model
|
|
|
+ .find(query)
|
|
|
+ .skip(Number(skip))
|
|
|
+ .limit(Number(limit));
|
|
|
return { data, total };
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
module.exports = UserService;
|