Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
付智勇
/
koa2_Sequelize_project
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
付智勇
8 years ago
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
304366bad839ebf65b6f79d8efefa64246d60ec9
304366ba
1 parent
e3d2b16a
master
...
20171113
nows
revert-2a1f6481
删除用户
隐藏空白字符变更
内嵌
并排对比
正在显示
4 个修改的文件
包含
42 行增加
和
1 行删除
controller/userController.js
routes/users.js
services/userService.js
util/resTemplate.js
controller/userController.js
查看文件 @
304366b
...
...
@@ -103,4 +103,17 @@ userController.prototype.updateUserByUserId = async(ctx, next) =>{
}
}
userController
.
prototype
.
delUserByUserId
=
async
(
ctx
,
next
)
=>
{
const
userId
=
ctx
.
params
.
userId
;
if
(
!
userId
){
return
status
.
paramError
(
'userId'
);
}
try
{
let
deluser
=
userService
.
delUserByUserId
(
userId
);
return
deluser
}
catch
(
error
)
{
throw
new
Error
(
error
)
}
}
module
.
exports
=
new
userController
();
\ No newline at end of file
...
...
routes/users.js
查看文件 @
304366b
...
...
@@ -41,6 +41,16 @@ router.put('/updateUserByUserId/:userId',async(ctx, next)=>{
}
})
router
.
delete
(
'/delUserByUserId/:userId'
,
async
(
ctx
,
next
)
=>
{
try
{
let
delData
=
await
userContoller
.
delUserByUserId
(
ctx
,
next
);
status
.
successTemp
(
ctx
,
200
,
delData
);
}
catch
(
e
){
console
.
log
(
e
)
status
.
catchError
(
ctx
,
400
,
e
.
message
);
}
})
...
...
services/userService.js
查看文件 @
304366b
...
...
@@ -82,5 +82,23 @@ userService.prototype.updateUserByUserId = async(userId,data)=>{
}
}
userService
.
prototype
.
delUserByUserId
=
async
(
userId
)
=>
{
let
t
=
await
sequelize
.
transaction
({
autocommit
:
true
})
try
{
let
User
=
await
userModel
.
find
({
where
:{
id
:
userId
}},{
transaction
:
t
});
if
(
!
User
){
t
.
rollback
()
return
{
msg
:
'用户不存在'
}
}
let
delUser
=
await
userModel
.
destroy
({
where
:{
id
:
userId
}},{
transaction
:
t
});
await
t
.
commit
();
return
delUser
}
catch
(
error
)
{
t
.
rollback
();
throw
new
Error
(
error
);
}
}
module
.
exports
=
new
userService
();
\ No newline at end of file
...
...
util/resTemplate.js
查看文件 @
304366b
...
...
@@ -31,7 +31,7 @@ module.exports = {
successTemp
:
(
ctx
,
code
,
data
)
=>
{
ctx
.
response
.
status
=
200
;
ctx
.
response
.
body
=
{
code
:
data
.
code
?
data
.
code
:
200
,
code
:
!
data
.
code
?
200
:
data
.
code
,
returnData
:{
data
:
data
}
...
...
请
注册
或
登录
后发表评论