Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
const router = require('koa-router')();
const koaBody = require('koa-body');
const static = require('koa-static')
const Koa = require('koa');
const app = module.exports = new Koa();
var path = require('path')
var user = require('./modules/user')
var movie = require('./modules/movie')
var send = require('./modules/send')
// "database"
const posts = [];
app.use(static(
path.join( __dirname, 'public')
))
// middleware
app.use(koaBody());
// route definitions
router.get('/login', login)
.get('/admin', admin)
.get('/register', register)
.get('/movies',allmovie)
.get('/addMovie',addMovie)
.get('/editMovie',editMovie)
.get('/delMovie',delMovie)
.get('/pay',sendE)
app.use(router.routes());
async function login(ctx,next) {
const name = ctx.query.name;
const password = ctx.query.password;
ctx.response.body = await user.login(String(name),String(password)).then(res => res)
ctx.response.status = 200
await next()
}
async function register(ctx,next) {
const name = ctx.query.name;
const password = ctx.query.password;
const email = ctx.query.email;
const card = ctx.query.card;
ctx.response.body = await user.register(String(name),String(password),String(email),String(card)).then(res => res)
ctx.response.status = 200
await next()
}
async function allmovie(ctx,next) {
ctx.response.body = await movie.all().then(res => res)
ctx.response.status = 200
await next()
}
async function addMovie(ctx,next) {
const name = ctx.query.name;
const time = ctx.query.time;
const price = ctx.query.price;
const picture = ctx.query.picture;
const sale = ctx.query.sale;
ctx.response.body = await movie.addMovie(name,time,price,picture,sale).then(res => res)
ctx.response.status = 200
await next()
}
async function editMovie(ctx,next) {
const id = ctx.query.id;
const name = ctx.query.name;
const time = ctx.query.time;
const price = ctx.query.price;
const picture = ctx.query.picture;
const sale = ctx.query.sale;
ctx.response.body = await movie.editMovie(id,name,time,price,picture,sale).then(res => res)
ctx.response.status = 200
await next()
}
async function delMovie(ctx,next) {
const id = ctx.query.id;
ctx.response.body = await movie.delMovie(id).then(res => res)
ctx.response.status = 200
await next()
}
async function admin(ctx,next) {
const name = ctx.query.name;
ctx.response.body = await user.admin(name).then(res => res)
ctx.response.status = 200
await next()
}
async function sendE(ctx,next) {
send()
ctx.response.body = 'ok'
ctx.response.status = 200
await next()
}
if (!module.parent) app.listen(3000);