// 获取标签 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() } var dellist = async (ctx,next)=>{ 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) }) } } module.exports = { 'GET /getlist':getlist, 'POST /addlist':addlist, 'GET /getaddlist':getaddlist, 'GET /dellist' : dellist }