This commit is contained in:
pplokijuhyg 2019-12-26 10:50:33 +08:00
commit 4aa55730e1
2 changed files with 22 additions and 4 deletions

2
app.js
View File

@ -1,6 +1,6 @@
const Koa = require("koa"); const Koa = require("koa");
const requter = require("./bin/router.js"); const requter = require("./bin/router.js");
dbs = require("./bin/mongodb.js")('mongodb://localhost:27017/myblog',"wecatdemo") dbs = require("./bin/mongodb.js")('mongodb://localhost:27017/wecatdemo',"wecatdemo")
// console.log(requter) // console.log(requter)
// import requter from "./bin/router" // import requter from "./bin/router"
const app = new Koa(); const app = new Koa();

View File

@ -41,6 +41,7 @@ var getaddlist = async (ctx,next) =>{
next() next()
} }
var dellist = async (ctx,next)=>{ var dellist = async (ctx,next)=>{
console.log(ctx.query.id)
if(ctx.query.id == undefined){ if(ctx.query.id == undefined){
ctx.body = JSON.stringify({ ctx.body = JSON.stringify({
code : 1, code : 1,
@ -48,20 +49,37 @@ var dellist = async (ctx,next)=>{
}) })
}else{ }else{
await dbs.remove('list',{ await dbs.remove('list',{
"num_key":ctx.query.id "num_key":parseInt(ctx.query.id)
}).then((res)=>{
ctx.body = JSON.stringify(res)
}).catch((err)=>{
ctx.body = JSON.stringify(res)
})
}
}
var findlist = async (ctx,next)=>{
// console.log(ctx.query.id)
if(ctx.query.name == undefined){
ctx.body = JSON.stringify({
code : 1,
msg:"id不能为空"
})
}else{
await dbs.find('list',{
"name":ctx.query.name
}).then((res)=>{ }).then((res)=>{
ctx.body = JSON.stringify(res) ctx.body = JSON.stringify(res)
}).catch((err)=>{ }).catch((err)=>{
ctx.body = JSON.stringify(res) ctx.body = JSON.stringify(res)
}) })
} }
} }
module.exports = { module.exports = {
'GET /getlist':getlist, 'GET /getlist':getlist,
'POST /addlist':addlist, 'POST /addlist':addlist,
'GET /getaddlist':getaddlist, 'GET /getaddlist':getaddlist,
'GET /dellist' : dellist, 'GET /dellist' : dellist,
'GET /getdata' :getimg 'GET /getdata' :getimg,
'GET /findlsit':findlist
} }