2019-09-27 14:04:01 +08:00

105 lines
2.0 KiB
JavaScript

/* 推广系统-广告专用 */
import {Router} from 'express'
import GameList from '../../models/admin/GameList'
import cors from 'cors'
const router = new Router()
// 获取游戏列表
router.get('/', async (req, res, next) => {
try {
const query = req.query
const currentPage = parseInt(query.currentPage)
const pageSize = parseInt(query.pageSize)
const platform_id = parseInt(query.platform_id)
const offset = (currentPage - 1) * pageSize
const limit = pageSize
const opt = {}
if (platform_id) opt.platform_id = platform_id
const result = await GameList.find(opt)
.skip(offset)
.limit(limit)
.sort({createdAt: 'desc'})
const total = await GameList.find(opt).countDocuments()
res.send({
errcode: 0,
result,
total,
})
} catch (err) {
next(err)
}
})
// 添加游戏
router.post('/', async (req, res, next) => {
try {
const body = req.body
const game_name = body.game_name
const platform_id = body.platform_id
const appid = body.appid
const newGameList = new GameList({
game_name,
platform_id,
appid,
})
const result = await newGameList.save()
res.send({
errcode: 0,
})
} catch (err) {
next(err)
}
})
// 修改游戏
router.put('/', async (req, res, next) => {
try {
const body = req.body
const _id = body._id
const game_name = body.game_name
const platform_id = body.platform_id
const appid = body.appid
const result = await GameList.updateOne(
{_id},
{
game_name,
platform_id,
appid,
}
)
res.send({
errcode: 0,
})
} catch (err) {
next(err)
}
})
// 删除游戏
router.delete('/', async (req, res, next) => {
try {
const body = req.body
const _id = body._id
const result = await GameList.deleteOne({_id})
res.send({
errcode: 0,
})
} catch (err) {
next(err)
}
})
export default router