import { Resolver, Query, FieldResolver, Root, Arg, Mutation, Ctx, Args, Authorized, ResolverInterface } from 'type-graphql'; import AccountModel, { NewAccountInput } from '@src/accounts/account.model'; import { ApolloContext } from '@lib/seed/interfaces/context'; import { signinGeneric } from '@services/module-accounts/services/AccountService'; import { AccountTypeEnum } from '@src/accounts/account.components'; import { BillingAddressComponent, BillingAddressInput } from '@services/module-payments/components/components'; @Resolver(AccountModel) export default class AccountBillingInfoResolver { /* ██████╗ ██╗ ██╗███████╗██████╗ ██╗ ██╗ ██╔═══██╗██║ ██║██╔════╝██╔══██╗╚██╗ ██╔╝ ██║ ██║██║ ██║█████╗ ██████╔╝ ╚████╔╝ ██║▄▄ ██║██║ ██║██╔══╝ ██╔══██╗ ╚██╔╝ ╚██████╔╝╚██████╔╝███████╗██║ ██║ ██║ ╚══▀▀═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ */ /* ███╗ ███╗██╗ ██╗████████╗ █████╗ ████████╗ ██████╗ ██████╗ ███████╗ ████╗ ████║██║ ██║╚══██╔══╝██╔══██╗╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝ ██╔████╔██║██║ ██║ ██║ ███████║ ██║ ██║ ██║██████╔╝███████╗ ██║╚██╔╝██║██║ ██║ ██║ ██╔══██║ ██║ ██║ ██║██╔══██╗╚════██║ ██║ ╚═╝ ██║╚██████╔╝ ██║ ██║ ██║ ██║ ╚██████╔╝██║ ██║███████║ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ */ @Mutation(() => BillingAddressComponent) @Authorized() async accountsBillingInfosAddOne(@Arg('input') input: BillingAddressInput, @Ctx() ctx: ApolloContext): Promise { const model = ctx.ctx.user; if (input.default && model.paymentInfo && model.paymentInfo.billingInfos) { // Remove all default from others await model.updateOneCustom( { _id: model._id }, { $set: { 'paymentInfo.billingInfos.$[].default': false }, }, ctx, ); } else input.default = false; return await model.addOneSubRessource({ _id: model._id }, 'paymentInfo.billingInfos', input, ctx); } @Mutation(() => BillingAddressComponent) @Authorized() async accountsBillingInfosEditOne( @Arg('id') id: string, @Arg('input') input: BillingAddressInput, @Ctx() ctx: ApolloContext, ): Promise { const model = ctx.ctx.user; if (input.default) { // Remove all default from others await model.updateOneCustom( { _id: model._id }, { $set: { 'paymentInfo.billingInfos.$[].default': false }, }, ctx, ); } else input.default = false; return await model.editOneSubRessource({ _id: model._id }, 'paymentInfo.billingInfos', id, input, ctx); } @Mutation(() => String) @Authorized() async accountsBillingInfosDeleteOne(@Arg('id') id: string, @Ctx() ctx: ApolloContext): Promise { const model = ctx.ctx.user; return await model.deleteOneSubRessource({ _id: model._id }, 'paymentInfo.billingInfos', id, ctx); } }