mirror of
https://github.com/glenndehaan/unifi-voucher-site.git
synced 2026-03-31 06:24:00 -04:00
Ensure note field is always present within vouchers api call. Cleanup older comments. Simplify code. Implement separator check. Updated README.md
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
|
||||
|
||||
@@ -111,12 +111,12 @@ 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,
|
||||
download_limit: voucher.rxRateLimitKbps ? voucher.rxRateLimitKbps : null,
|
||||
upload_limit: voucher.txRateLimitKbps ? voucher.txRateLimitKbps : null,
|
||||
note: notes(voucher.name).note
|
||||
upload_limit: voucher.txRateLimitKbps ? voucher.txRateLimitKbps : null
|
||||
};
|
||||
}),
|
||||
updated: cache.updated
|
||||
@@ -182,25 +182,22 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prepare optional note (sanitize to avoid breaking internal separator format)
|
||||
// Prepare optional note
|
||||
let noteInput = '';
|
||||
if(typeof req.body.note !== 'undefined' && req.body.note !== null) {
|
||||
if(typeof req.body.note !== 'string') {
|
||||
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;
|
||||
|
||||
noteInput = req.body.note;
|
||||
}
|
||||
|
||||
// Build the note string expected by utils/notes.js
|
||||
const finalNote = `${noteInput}||;;||api||;;||local||;;||`;
|
||||
|
||||
// Create voucher code
|
||||
const voucherCode = await unifi.create(types(req.body.type, true), 1, finalNote).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