62 lines
3.7 KiB
TypeScript
62 lines
3.7 KiB
TypeScript
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);
|
||
}
|
||
}
|