明树Git Lab

Commit 1b44a342 authored by zfp1's avatar zfp1

update

parent ec88b47b
......@@ -10,7 +10,12 @@ async function createRole(req, res, next) {
}
async function updateRole(req, res, next) {
try {
let body = req.body;
if (!body.id) {
return res.sendError(errorMessage.resourceNotFound)
}
const ret = await userModule.updateOne({ id: body.id }, body);
return res.sendData(ret);
} catch (error) {
next(error);
}
......
const crypto = require('crypto');
const _ = require('lodash');
const CryptoJS = require('crypto-js');
const { Op } = require('sequelize');
const { Op, where } = require('sequelize');
const userModule = require('../module/userModule');
......@@ -10,7 +10,7 @@ const errorMessage = require('../utils/errorMessage');
async function regist(req, res, next) {
try {
const { salt, passwordHash } = utils.saltHashPassword(req.body.password);
const ret = await userModule.create({
const ret = await DB.User.create({
...req.body,
salt,
password: passwordHash,
......@@ -31,7 +31,7 @@ async function login(req, res, next) {
req.body.password = encArr[1];
}
const { mobile, password } = req.body;
const user = await userModule.findOne({ mobile, del: 0, enable: 0 });
const user = await DB.User.findOne({ where: { mobile, del: 0, enable: 0 }, raw: true });
console.log("----------------------", user)
if (!user) {
return res.sendError(errorMessage.loginError);
......@@ -67,7 +67,7 @@ async function login(req, res, next) {
async function addUser(req, res, next) {
try {
const body = req.body;
const ret = await userModule.create(body);
const ret = await DB.User.create(body);
return res.sendData(ret);
} catch (error) {
next(error);
......@@ -84,7 +84,7 @@ async function getUserInfo(req, res, next) {
if (mobile) {
query.mobile = mobile;
}
const ret = await userModule.findOne(query);
const ret = await DB.User.findOne({ where: query, raw: true });
return res.sendData(ret);
} catch (error) {
next(error);
......@@ -97,7 +97,7 @@ async function updateUser(req, res, next) {
if (!body.id) {
return res.sendError(errorMessage.resourceNotFound)
}
const ret = await userModule.updateOne({ id: body.id }, body);
const ret = await DB.User.update(body, { where: { id: body.id } });
return res.sendData(ret);
} catch (error) {
next(error);
......@@ -123,7 +123,7 @@ async function listUser(req, res, next) {
search.limit = limit;
search.offset = offset;
// console.log(JSON.stringify(search), "===")
let ret = await userModule.findAndCountAll(search);
let ret = await DB.User.findAndCountAll(search);
return res.sendData(ret);
} catch (error) {
next(error);
......@@ -143,7 +143,7 @@ async function deleteUser(req, res, next) {
if (_.isEmpty(search)) {
return res.sendError(errorMessage.resourceNotFound);
}
const ret = await userModule.updateOne(search, { del: 1 });//删除标记
const ret = await DB.User.update({ del: 1 }, {where: search} );//删除标记
return res.sendData(ret);
} catch (error) {
next(error);
......@@ -162,7 +162,4 @@ module.exports = {
getUserInfo,
updateUser,
deleteUser,
// checkUserToken,
// changePassword,
// changePwd,
}
\ No newline at end of file
const _ = require("lodash");
const { where } = require("sequelize");
const errorMessage = require("../utils/errorMessage");
async function create(params) {
return DB.User.create(params);
}
async function findOne(params) {
if(_.isEmpty(params)) {
return null;
}
return DB.User.findOne(
{where: params, raw: true}
);
}
async function updateOne(condition, params) {
if(_.isEmpty(condition)) {
return null;
}
return DB.User.update(params, {where: condition});
}
async function findAndCountAll(condition) {
return DB.User.findAndCountAll(condition);
}
module.exports = {
create,
findOne,
updateOne,
findAndCountAll,
}
\ No newline at end of file
......@@ -9,14 +9,11 @@ const roleController = require('../controller/roleController');
router.post('/regist', userController.regist);
router.post('/login', userController.login);
// router.post('/checkUserToken', userController.checkUserToken);
// router.post('/changePassword', userController.changePassword);
router.post('/manage/listUser', userController.listUser);
router.post('/manage/addUser', userController.addUser);
router.post('/manage/updateUser', userController.updateUser); //更新 enable用户
router.post('/manage/getUserInfo', userController.getUserInfo);
router.post('/manage/deleteUser', userController.deleteUser); // 删除
// router.post('/manage/changePwd', userController.changePwd);
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment