Skip to content

Commit

Permalink
enhancement(expenses): error message for missing host/archived account
Browse files Browse the repository at this point in the history
  • Loading branch information
Betree committed Dec 31, 2024
1 parent 61c1183 commit 3227a1a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions server/graphql/common/expenses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3309,6 +3309,14 @@ export async function quoteExpense(expense_) {
const payoutMethodType = payoutMethod ? payoutMethod.type : expense.getPayoutMethodTypeFromLegacy();

const host = await expense.collective.getHostCollective();
if (!host) {
throw new Error(
expense.collective.deactivatedAt
? `@${expense.collective.slug} has been archived`
: `Host not found for account @${expense.collective.slug}`,
);
}

if (payoutMethodType === PayoutMethodTypes.BANK_ACCOUNT) {
const connectedAccount = await host.getAccountForPaymentProvider(Service.TRANSFERWISE);

Expand Down
8 changes: 8 additions & 0 deletions server/graphql/v2/object/Expense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,14 @@ export const GraphQLExpense = new GraphQLObjectType<ExpenseModel, express.Reques
if (payoutMethod?.type === 'BANK_ACCOUNT' && (await ExpenseLib.canPayExpense(req, expense))) {
const collective = await req.loaders.Collective.byId.load(expense.CollectiveId);
const host = await collective.getHostCollective({ loaders: req.loaders });
if (!host) {
throw new Error(
collective.deactivatedAt
? `@${collective.slug} has been archived`
: `Host not found for account @${collective.slug}`,
);
}

const connectedAccount = await host.getAccountForPaymentProvider(Service.TRANSFERWISE);
return await transferwise.validateTransferRequirements(
connectedAccount,
Expand Down

0 comments on commit 3227a1a

Please sign in to comment.