(req, res)
| 255 | app.get('/', httpGet); |
| 256 | |
| 257 | const httpPost = async (req, res) => { |
| 258 | pool = pool || (await createPoolAndEnsureSchema()); |
| 259 | // Get the team from the request and record the time of the vote. |
| 260 | const {team} = req.body; |
| 261 | const timestamp = new Date(); |
| 262 | |
| 263 | if (!team || (team !== 'TABS' && team !== 'SPACES')) { |
| 264 | res.status(400).send('Invalid team specified.').end(); |
| 265 | return; |
| 266 | } |
| 267 | |
| 268 | // Create a vote record to be stored in the database. |
| 269 | const vote = { |
| 270 | candidate: team, |
| 271 | time_cast: timestamp, |
| 272 | }; |
| 273 | |
| 274 | // Save the data to the database. |
| 275 | try { |
| 276 | await insertVote(pool, vote); |
| 277 | } catch (err) { |
| 278 | logger.error(`Error while attempting to submit vote:${err}`); |
| 279 | res |
| 280 | .status(500) |
| 281 | .send('Unable to cast vote; see logs for more details.') |
| 282 | .end(); |
| 283 | return; |
| 284 | } |
| 285 | res.status(200).send(`Successfully voted for ${team} at ${timestamp}`).end(); |
| 286 | }; |
| 287 | |
| 288 | app.post('*', httpPost); |
| 289 |
no test coverage detected