2025-05-14 21:45:16 +02:00

62 lines
3.7 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Resolver, Arg, Mutation, Ctx, Authorized, Query, Args } from 'type-graphql';
import AccountModel from '@src/accounts/account.model';
import { ApolloContext } from '@lib/seed/interfaces/context';
import StripeService from '@services/module-payments/services/stripe/StripeService';
@Resolver(AccountModel)
export default class AccountPayoutAccountsResolver {
/*
██████╗ ██╗ ██╗███████╗██████╗ ██╗ ██╗
██╔═══██╗██║ ██║██╔════╝██╔══██╗╚██╗ ██╔╝
██║ ██║██║ ██║█████╗ ██████╔╝ ╚████╔╝
██║▄▄ ██║██║ ██║██╔══╝ ██╔══██╗ ╚██╔╝
╚██████╔╝╚██████╔╝███████╗██║ ██║ ██║
╚══▀▀═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═╝
*/
@Query(() => String)
@Authorized()
async accountsDashboardLinkStripe(@Arg('returnPath', {nullable:true}) returnPath:string | undefined, @Ctx() ctx: ApolloContext): Promise<string> {
const account = ctx.ctx.user;
if (account.payoutInfo?.stripeInfo?.detailsSubmitted) {
// Get dashboard link
return await StripeService.getInstance().createAccountDashboardLink(account);
}
// Get Create Link
else return (await StripeService.getInstance().createAccountLink(account, returnPath, 'create')).url;
}
/*
███╗ ███╗██╗ ██╗████████╗ █████╗ ████████╗ ██████╗ ██████╗ ███████╗
████╗ ████║██║ ██║╚══██╔══╝██╔══██╗╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
██╔████╔██║██║ ██║ ██║ ███████║ ██║ ██║ ██║██████╔╝███████╗
██║╚██╔╝██║██║ ██║ ██║ ██╔══██║ ██║ ██║ ██║██╔══██╗╚════██║
██║ ╚═╝ ██║╚██████╔╝ ██║ ██║ ██║ ██║ ╚██████╔╝██║ ██║███████║
╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
*/
@Mutation(() => String)
@Authorized()
async accountsLinkWithStripe(@Arg('returnPath', {nullable:true}) returnPath:string | undefined, @Ctx() ctx: ApolloContext): Promise<string> {
const account = ctx.ctx.user;
// Check if update of create of the link
let type: 'create' | 'update' = 'create';
if (account.payoutInfo?.stripeInfo?.detailsSubmitted) type = 'update';
// Get the card information from stripe
const stripeAccountLink = await StripeService.getInstance().createAccountLink(account, returnPath, type);
return stripeAccountLink.url;
}
@Mutation(() => AccountModel)
@Authorized()
async accountsRefreshInfoStripe(@Ctx() ctx: ApolloContext): Promise<AccountModel> {
const account = ctx.ctx.user;
// Get the card information from stripe
return await StripeService.getInstance().refreshAccountInfo(account);
}
}