first commit

This commit is contained in:
2021-03-04 09:01:42 +08:00
commit a8ff4b4990
7 changed files with 397 additions and 0 deletions

52
controllers/index.js Normal file
View File

@@ -0,0 +1,52 @@
let index = async (ctx,next)=>{
ctx.body = ""
}
let login = async (ctx,next)=>{
let res = await dbs.find("user",{user: ctx.query.user,pwd: ctx.query.pwd})
if(res.data.length == 0){
ctx.body = JSON.stringify({
code: 500,
msg: "用户名或密码错误"
})
}else{
ctx.body = JSON.stringify({
code: 200,
msg: "登录成功",
data: {
username:res.data[0].user,
token:res.data[0]._id
}
})
}
}
let register = async (ctx,next)=>{
const msg = dbs.add("user",{user: ctx.query.user,pwd: ctx.query.pwd})
ctx.body = JSON.stringify(msg)
}
let getlist = async (ctx,next)=>{
const list = await dbs.find("user")
ctx.body = JSON.stringify(list)
}
let deluser = async (ctx,next)=>{
const res = await dbs.remove("user",{num_key: parseInt(ctx.query.id)})
ctx.body = JSON.stringify({...res,id:ctx.query.id})
}
let update = async (ctx,nex)=>{
console.log(ctx.request.body)
const res = await dbs.update("user",{num_key: ctx.request.body.id},{user: ctx.request.body.user,pwd:ctx.request.body.pwd})
ctx.body = JSON.stringify(res)
}
module.exports = {
"GET /":index,
"GET /login": login,
"GET /register": register,
"GET /getlist": getlist,
"GET /deluser": deluser ,
"POST /update": update
}