mirror of
https://github.com/glenndehaan/unifi-voucher-site.git
synced 2026-03-31 06:24:02 -04:00
Merge pull request #111 from nickelblack619/api-note
Accept optional note in POST /api/voucher and include note in GET /api/vouchers
This commit is contained in:
11
README.md
11
README.md
@@ -408,6 +408,7 @@ the different endpoints available in the API:
|
||||
{
|
||||
"id": "67bded6766f89f2a7ba6731f",
|
||||
"code": "15695-53133",
|
||||
"note": "Test",
|
||||
"type": "multi",
|
||||
"duration": 60,
|
||||
"data_limit": "200",
|
||||
@@ -417,6 +418,7 @@ the different endpoints available in the API:
|
||||
{
|
||||
"id": "67bdecd166f89f2a7ba67317",
|
||||
"code": "03004-59449",
|
||||
"note": null,
|
||||
"type": "single",
|
||||
"duration": 480,
|
||||
"data_limit": null,
|
||||
@@ -447,6 +449,15 @@ the different endpoints available in the API:
|
||||
}
|
||||
```
|
||||
|
||||
- Generate Voucher and Provide note:
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "480,0,,,",
|
||||
"note": "This is a note"
|
||||
}
|
||||
```
|
||||
|
||||
- Generate Voucher and Send Email *(**Warning**: Email module needs to be setup!)*:
|
||||
|
||||
```json
|
||||
|
||||
@@ -12,6 +12,7 @@ const mail = require('../modules/mail');
|
||||
const {updateCache} = require('../utils/cache');
|
||||
const types = require('../utils/types');
|
||||
const languages = require('../utils/languages');
|
||||
const notes = require('../utils/notes');
|
||||
|
||||
module.exports = {
|
||||
api: {
|
||||
@@ -110,6 +111,7 @@ module.exports = {
|
||||
return {
|
||||
id: voucher.id,
|
||||
code: `${voucher.code.slice(0, 5)}-${voucher.code.slice(5)}`,
|
||||
note: notes(voucher.name).note ? notes(voucher.name).note : null,
|
||||
type: !voucher.authorizedGuestLimit ? 'multi' : voucher.authorizedGuestLimit === 1 ? 'single' : 'multi',
|
||||
duration: voucher.timeLimitMinutes,
|
||||
data_limit: voucher.dataUsageLimitMBytes ? voucher.dataUsageLimitMBytes : null,
|
||||
@@ -180,8 +182,22 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prepare optional note
|
||||
let noteInput = '';
|
||||
if(typeof req.body.note !== 'undefined' && req.body.note !== null) {
|
||||
if(typeof req.body.note !== 'string' && req.body.note === '' && req.body.note.includes('||;;||')) {
|
||||
res.status(400).json({
|
||||
error: 'Invalid Note!',
|
||||
data: {}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
noteInput = req.body.note;
|
||||
}
|
||||
|
||||
// Create voucher code
|
||||
const voucherCode = await unifi.create(types(req.body.type, true), 1, `||;;||api||;;||local||;;||`).catch((e) => {
|
||||
const voucherCode = await unifi.create(types(req.body.type, true), 1, `${noteInput}||;;||api||;;||local||;;||`).catch((e) => {
|
||||
res.status(500).json({
|
||||
error: e,
|
||||
data: {}
|
||||
|
||||
Reference in New Issue
Block a user