diff --git a/bin/dbVersion.json b/bin/dbVersion.json index c7ef116..c580866 100644 --- a/bin/dbVersion.json +++ b/bin/dbVersion.json @@ -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": [] } \ No newline at end of file diff --git a/route/api/twitch/index.js b/route/api/twitch/index.js index b227401..07c897b 100644 --- a/route/api/twitch/index.js +++ b/route/api/twitch/index.js @@ -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 diff --git a/schema/20180826-1.sql b/schema/20180826-1.sql new file mode 100644 index 0000000..537886f --- /dev/null +++ b/schema/20180826-1.sql @@ -0,0 +1 @@ +ALTER TABLE public.donate_setting ADD start_amount int DEFAULT 0 NOT NULL; \ No newline at end of file