mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2026-10-30 19:34:14 +00:00
merge of features from hosted branch (#7)
major merge of features from the hosted branch that was created temporarily during the initial launch of jambonz.org
This commit is contained in:
1 parent
ab7c69c0e8
commit
ed51d8b13f
105 files changed
+10330
-1601
No files matched your search
@@ -0,0 +1,34 @@
|
||||
const router = require('express').Router();
|
||||
const sysError = require('../error');
|
||||
const {promisePool} = require('../../db');
|
||||
const sqlClaim = `UPDATE beta_invite_codes
|
||||
SET in_use = 1
|
||||
WHERE invite_code = ?
|
||||
AND in_use = 0`;
|
||||
const sqlTest = `SELECT * FROM beta_invite_codes
|
||||
WHERE invite_code = ?
|
||||
AND in_use = 0`;
|
||||
router.post('/', async(req, res) => {
|
||||
const {logger} = req.app.locals;
|
||||
try {
|
||||
const {code, test} = req.body;
|
||||
logger.debug({code}, 'POST /InviteCodes');
|
||||
if ('test' === process.env.NODE_ENV) {
|
||||
if (code.endsWith('0')) return res.sendStatus(404);
|
||||
res.sendStatus(204);
|
||||
return;
|
||||
}
|
||||
if (test) {
|
||||
const [r] = await promisePool.execute(sqlTest, [code]);
|
||||
res.sendStatus(1 === r.length ? 204 : 404);
|
||||
}
|
||||
else {
|
||||
const [r] = await promisePool.execute(sqlClaim, [code]);
|
||||
res.sendStatus(1 === r.affectedRows ? 204 : 404);
|
||||
}
|
||||
} catch (err) {
|
||||
sysError(logger, res, err);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in new issue
Block a user