Return scoped carriers and speech creds in /SP GET call (#96)

* return scoped carriers and speech creds in /SP GET call

* apply review comments

Co-authored-by: eglehelms <e.helms@cognigy.com>
This commit is contained in:
EgleH
2023-01-19 16:53:37 +01:00
committed by GitHub
parent 274377960e
commit 80ee1d06d7
2 changed files with 12 additions and 3 deletions

View File

@@ -127,8 +127,13 @@ router.get('/:sid/VoipCarriers', async(req, res) => {
try {
await validateRetrieve(req);
const service_provider_sid = parseServiceProviderSid(req);
const results = await VoipCarrier.retrieveAllForSP(service_provider_sid);
res.status(200).json(results);
const carriers = await VoipCarrier.retrieveAllForSP(service_provider_sid);
if (req.user.hasScope('account')) {
return res.status(200).json(carriers.filter((c) => c.account_sid === req.user.account_sid || !c.account_sid));
}
res.status(200).json(carriers);
} catch (err) {
sysError(logger, res, err);
}

View File

@@ -151,10 +151,14 @@ router.get('/', async(req, res) => {
if (!account_sid) service_provider_sid = parseServiceProviderSid(req);
const logger = req.app.locals.logger;
try {
const creds = account_sid ?
let creds = account_sid ?
await SpeechCredential.retrieveAll(account_sid) :
await SpeechCredential.retrieveAllForSP(service_provider_sid);
if (req.user.hasScope('account')) {
creds = creds.filter((c) => c.account_sid === req.user.account_sid || !c.account_sid);
}
res.status(200).json(creds.map((c) => {
const {credential, ...obj} = c;
if ('google' === obj.vendor) {