const newBlog = (blogData = {}) => {
const {
title,
content,
author,
} = blogData
const createtime = Date.now()
const sql = `
insert into blogs (title, content, createtime, author)
values ('${title}', '${content}', '${createtime}', '${author}');
`
return exec(sql).then((result) => {
return {
id: result.insertId
}
})
}
const {
path,
body,
query
} = req
const {
id,
} = query
if (path === '/api/blog/new') {
body.author = 'givencui_mock'
return newBlog(body).then((data) => {
return new SuccessModel(data)
}).catch(err => {
return new ErrorModel(err)
})
}