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 { ...@@ -19,15 +19,15 @@ export class Access {
this.vendorId = assertHas(arg, 'vendorId') && arg.vendorId; this.vendorId = assertHas(arg, 'vendorId') && arg.vendorId;
this.login = assertHas(arg, 'login') && arg.login; this.login = assertHas(arg, 'login') && arg.login;
this.enabled = assertHas(arg, 'enabled') && arg.enabled; this.enabled = assertHas(arg, 'enabled') && arg.enabled;
this.label = (maybeHas(arg, 'label') && arg.label) || null;
this.customLabel = (maybeHas(arg, 'customLabel') && arg.customLabel) || 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); let staticBank = banks.find(b => b.uuid === this.vendorId);
assert( assert(
typeof staticBank !== 'undefined', typeof staticBank !== 'undefined',
`Unknown bank linked to access: ${this.vendorId}` `Unknown bank linked to access: ${this.vendorId}`
); );
this.label = staticBank.name;
this.isBankVendorDeprecated = staticBank.deprecated; this.isBankVendorDeprecated = staticBank.deprecated;
assert(!maybeHas(arg, 'fields') || arg.fields instanceof Array); assert(!maybeHas(arg, 'fields') || arg.fields instanceof Array);
......
...@@ -16,6 +16,7 @@ import { ...@@ -16,6 +16,7 @@ import {
isAppriseApiEnabled, isAppriseApiEnabled,
} from '../helpers'; } from '../helpers';
import { bankVendorByUuid } from '../lib/bank-vendors';
import { ConfigGhostSettings } from '../lib/ghost-settings'; import { ConfigGhostSettings } from '../lib/ghost-settings';
import { validatePassword } from '../shared/helpers'; import { validatePassword } from '../shared/helpers';
import DefaultSettings from '../shared/default-settings'; import DefaultSettings from '../shared/default-settings';
...@@ -36,10 +37,13 @@ interface GetAllDataOptions { ...@@ -36,10 +37,13 @@ interface GetAllDataOptions {
// FIXME also contains all the fields from Access. // FIXME also contains all the fields from Access.
interface ClientAccess { interface ClientAccess {
vendorId: string;
enabled?: boolean; enabled?: boolean;
fields: { name: string; value: string }[]; fields: { name: string; value: string }[];
password?: string | null; password?: string | null;
session?: string | null; session?: string | null;
customLabel: string | null;
label?: string | null;
} }
interface AllData { interface AllData {
...@@ -52,7 +56,7 @@ interface AllData { ...@@ -52,7 +56,7 @@ interface AllData {
budgets?: Budget[]; 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 { isExport = false, cleanPassword = true } = options;
const ret: AllData = { const ret: AllData = {
...@@ -84,6 +88,11 @@ async function getAllData(userId: number, options: GetAllDataOptions = {}) { ...@@ -84,6 +88,11 @@ async function getAllData(userId: number, options: GetAllDataOptions = {}) {
delete clientAccess.session; delete clientAccess.session;
} }
const bank = bankVendorByUuid(clientAccess.vendorId);
if (bank && bank.name) {
clientAccess.label = bank.name;
}
ret.accesses.push(clientAccess); 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