add schema

This commit is contained in:
Jay 2018-08-26 21:27:36 +08:00
parent 909d67ce19
commit aacba6024f
3 changed files with 15 additions and 11 deletions

View File

@ -15,7 +15,8 @@
{"file": "20180807-1.sql", "version": 13},
{"file": "20180811-1.sql", "version": 14},
{"file": "20180815-1.sql", "version": 15},
{"file": "20180816-1.sql", "version": 16}
{"file": "20180816-1.sql", "version": 16},
{"file": "20180826-1.sql", "version": 17}
],
"test": []
}

View File

@ -115,23 +115,24 @@ r.get('/channel/:chid/opay/setting', checkSession, getChannelList, hasChannel('c
})
r.put('/channel/:chid/opay/setting', checkSession, getChannelList, hasChannel('chid'), koaBody(), async (c, n) => {
if (!c.chkBody('start', 'number') || !c.chkBody('end', 'number') || !c.chkBody('title', 'string') || !c.chkBody('amount', 'number')) throw genError('DataFormat')
if (!c.chkBody('end', 'number') || !c.chkBody('title', 'string') || !c.chkBody('amount', 'number')) throw genError('DataFormat')
let sts = toInt(c.request.body.start, 0, 0)
let ets = toInt(c.request.body.end, 0, 0)
let amount = toInt(c.request.body.amount, 0, 0)
let sd = new Date(sts)
let startAmount = toInt(c.request.body.start_amount, 0, 0)
let ed = new Date(ets)
let text = `insert into "public"."donate_setting" ("twitch", "start_date", "end_date", "target_amount", "title") values
($1, $2, $3, $4, $5)
let text = `insert into "public"."donate_setting"
("twitch", "start_date", "end_date", "target_amount", "title", "start_amount") values
($1, now(), $2, $3, $4, $5)
on CONFLICT ("twitch") DO UPDATE
set
"start_date" = $2,
"end_date" = $3,
"target_amount" = $4,
"title" = $5`
let values = [c.state.channel.id, sd, ed, amount, c.request.body.title]
"start_date" = now(),
"end_date" = $2,
"target_amount" = $3,
"title" = $4,
"start_amount" = $5`
let values = [c.state.channel.id, ed, amount, c.request.body.title, startAmount]
await c.db.query({
text,
values
@ -158,6 +159,7 @@ r.get('/channel/:chid/opay/bar', async (c, n) => {
let setting = {}
if (result.rowCount === 0) setting = {}
setting = result.rows[0]
setting.total = toInt(setting.start_amount, 0, 0)
if (result.rowCount > 0) {
text = `select sum(list.price) as total from "public"."opay_donate_list" list

1
schema/20180826-1.sql Normal file
View File

@ -0,0 +1 @@
ALTER TABLE public.donate_setting ADD start_amount int DEFAULT 0 NOT NULL;