wecat-serve-demo/controllers/index.js

64 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-12-10 14:32:04 +08:00
// 获取标签
var getlist = async (ctx, next) => {
await dbs.find('list').then((res) => {
ctx.body = JSON.stringify(res)
})
next()
}
var addlist = async (ctx,next) =>{
if(ctx.request.body.name == undefined || ctx.request.body.age == undefined){
ctx.body = JSON.stringify({
code:1,
msg:"姓名或年龄不能为空"
})
}else{
await dbs.add('list',{
name:ctx.request.body.name,
age:ctx.request.body.age
}).then((res)=>{
ctx.body = JSON.stringify(res)
})
}
next()
}
var getaddlist = async (ctx,next) =>{
if(ctx.query.name == undefined || ctx.query.age == undefined){
ctx.body = JSON.stringify({
code:1,
msg:"姓名或年龄不能为空"
})
}else{
await dbs.add('list',{
name:ctx.query.name,
age:ctx.query.age
}).then((res)=>{
ctx.body = JSON.stringify(res)
})
}
next()
}
2019-12-10 14:54:01 +08:00
var dellist = async (ctx,next)=>{
2019-12-10 14:56:00 +08:00
if(ctx.query.id == undefined){
ctx.body = JSON.stringify({
code : 1,
msg:"id不能为空"
})
}else{
await dbs.remove('list',{
"num_key":ctx.query.id
}).then((res)=>{
ctx.body = JSON.stringify(res)
}).catch((err)=>{
ctx.body = JSON.stringify(res)
})
}
2019-12-10 14:54:01 +08:00
}
2019-12-10 14:32:04 +08:00
module.exports = {
'GET /getlist':getlist,
'POST /addlist':addlist,
2019-12-10 14:54:01 +08:00
'GET /getaddlist':getaddlist,
'GET /dellist' : dellist
2019-12-10 14:32:04 +08:00
}