Commit 5414b0c3 authored by Nicolas Frandeboeuf's avatar Nicolas Frandeboeuf Committed by Benjamin Bouvier
Browse files

API: return accesses label

parent e6b51aee
Pipeline #318879 passed with stages
in 16 minutes and 25 seconds
......@@ -19,15 +19,15 @@ export class Access {
this.vendorId = assertHas(arg, 'vendorId') && arg.vendorId;
this.login = assertHas(arg, 'login') && arg.login;
this.enabled = assertHas(arg, 'enabled') && arg.enabled;
this.label = (maybeHas(arg, 'label') && arg.label) || null;
this.customLabel = (maybeHas(arg, 'customLabel') && arg.customLabel) || null;
// Retrieve bank access' name and custom fields from the static bank information.
// Retrieve bank access' custom fields from the static bank information.
let staticBank = banks.find(b => b.uuid === this.vendorId);
assert(
typeof staticBank !== 'undefined',
`Unknown bank linked to access: ${this.vendorId}`
);
this.label = staticBank.name;
this.isBankVendorDeprecated = staticBank.deprecated;
assert(!maybeHas(arg, 'fields') || arg.fields instanceof Array);
......
......@@ -16,6 +16,7 @@ import {
isAppriseApiEnabled,
} from '../helpers';
import { bankVendorByUuid } from '../lib/bank-vendors';
import { ConfigGhostSettings } from '../lib/ghost-settings';
import { validatePassword } from '../shared/helpers';
import DefaultSettings from '../shared/default-settings';
......@@ -36,10 +37,13 @@ interface GetAllDataOptions {
// FIXME also contains all the fields from Access.
interface ClientAccess {
vendorId: string;
enabled?: boolean;
fields: { name: string; value: string }[];
password?: string | null;
session?: string | null;
customLabel: string | null;
label?: string | null;
}
interface AllData {
......@@ -52,7 +56,7 @@ interface AllData {
budgets?: Budget[];
}
async function getAllData(userId: number, options: GetAllDataOptions = {}) {
async function getAllData(userId: number, options: GetAllDataOptions = {}): Promise<AllData> {
const { isExport = false, cleanPassword = true } = options;
const ret: AllData = {
......@@ -84,6 +88,11 @@ async function getAllData(userId: number, options: GetAllDataOptions = {}) {
delete clientAccess.session;
}
const bank = bankVendorByUuid(clientAccess.vendorId);
if (bank && bank.name) {
clientAccess.label = bank.name;
}
ret.accesses.push(clientAccess);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment