141 lines
3.9 KiB
TypeScript
141 lines
3.9 KiB
TypeScript
import { ObjectType, Field, InputType, ID, Ctx } from 'type-graphql';
|
|
|
|
import { IEngineSchema, MetaBy, MetaPermissions } from '@lib/seed/engine/EngineSchema';
|
|
import { AvailableTranslation, BuyerInfoComponent, TranslatableComponent } from '@src/__components/components';
|
|
import { ProviderSchema } from './provider.schema';
|
|
import { Type } from 'class-transformer';
|
|
import { LocaleInfo, OrderStatusEnum } from '@services/module-payments/components/components.orders';
|
|
import {
|
|
PaymentIntentInfo,
|
|
PaymentStatusEnum,
|
|
PaymentInfo,
|
|
InvoiceInfo,
|
|
CurrencyEnum,
|
|
} from '@services/module-payments/components/components.payments';
|
|
import { ApolloContext } from '@seed/interfaces/context';
|
|
import { getTotalPrice, getSubTotalPrice, getVatPrice } from '../helpers/OrderHelper';
|
|
import { PromoType } from '@services/module-payments/functions/promos/component';
|
|
import PromoModel from '@services/module-payments/functions/promos/promo.model';
|
|
import { LineItemSchema } from '@src/orders/components/line.schema';
|
|
import { EnginePathComponent } from '@seed/interfaces/components';
|
|
|
|
@InputType()
|
|
@ObjectType()
|
|
export class OrderEngineBaseSchema {
|
|
/*
|
|
LINES
|
|
*/
|
|
|
|
@Field(() => [LineItemSchema])
|
|
@Type(() => LineItemSchema)
|
|
lines: LineItemSchema[];
|
|
|
|
/*
|
|
CURRENCY & LOCALE
|
|
*/
|
|
|
|
@Field(() => LocaleInfo)
|
|
localeInfo: LocaleInfo;
|
|
|
|
@Field(() => CurrencyEnum)
|
|
currency: CurrencyEnum;
|
|
|
|
@Field(() => Boolean)
|
|
vatExempt = false;
|
|
|
|
/*
|
|
CONTACTS
|
|
*/
|
|
|
|
@Field()
|
|
accountId: string;
|
|
|
|
@Field(() => BuyerInfoComponent, { nullable: true })
|
|
contactInfo?: BuyerInfoComponent;
|
|
|
|
@Field(() => BuyerInfoComponent, { nullable: true })
|
|
billingInfo?: BuyerInfoComponent;
|
|
|
|
/*
|
|
PROMOTIONS
|
|
*/
|
|
|
|
@Field(() => ID, { nullable: true })
|
|
promoId?: string;
|
|
|
|
/*
|
|
INVOICING
|
|
*/
|
|
|
|
@Field(() => InvoiceInfo, { nullable: true })
|
|
@Type(() => InvoiceInfo)
|
|
invoiceInfo?: InvoiceInfo;
|
|
|
|
/*
|
|
PROVIDERS
|
|
*/
|
|
@Field(() => [ProviderSchema], { nullable: true })
|
|
@Type(() => ProviderSchema)
|
|
providerOrderItems?: ProviderSchema[];
|
|
|
|
@Field(() => TranslatableComponent, { nullable: true })
|
|
orderName?: TranslatableComponent;
|
|
}
|
|
|
|
@ObjectType()
|
|
export class OrderEngineDBInterfaceSchema extends OrderEngineBaseSchema {
|
|
@Field(() => OrderStatusEnum)
|
|
orderStatus: OrderStatusEnum;
|
|
|
|
@Field(() => PaymentIntentInfo)
|
|
paymentIntent: PaymentIntentInfo;
|
|
|
|
@Field(() => PaymentStatusEnum, { nullable: true })
|
|
paymentStatus?: PaymentStatusEnum;
|
|
@Field(() => PaymentInfo, { nullable: true })
|
|
paymentInfo?: PaymentInfo;
|
|
|
|
inputData?: any;
|
|
}
|
|
|
|
@ObjectType()
|
|
export class OrderEngineDBSchema extends OrderEngineDBInterfaceSchema {
|
|
@Field(() => Number)
|
|
async subTotalPrice(@Ctx() ctx: ApolloContext): Promise<number> {
|
|
return await getSubTotalPrice(this, ctx);
|
|
}
|
|
|
|
@Field(() => Number)
|
|
async vatPrice(@Ctx() ctx: ApolloContext): Promise<number> {
|
|
return await getVatPrice(this, ctx);
|
|
}
|
|
|
|
@Field(() => Number)
|
|
async finalPrice(@Ctx() ctx: ApolloContext): Promise<number> {
|
|
if (this.vatExempt) return getSubTotalPrice(this, ctx);
|
|
return await getTotalPrice(this, ctx);
|
|
}
|
|
|
|
@Field(() => Number)
|
|
async totalPrice(@Ctx() ctx: ApolloContext): Promise<number> {
|
|
return this.finalPrice(ctx)
|
|
}
|
|
|
|
@Field(() => PromoModel, { nullable: true })
|
|
async promo(@Ctx() ctx: ApolloContext): Promise<PromoModel | undefined> {
|
|
if (this.promoId) return await ctx.ctx.loaders.promoLoader.load(this.promoId);
|
|
return;
|
|
}
|
|
}
|
|
|
|
@ObjectType({ implements: IEngineSchema })
|
|
export class OrderEngineSchema extends OrderEngineDBSchema implements IEngineSchema {
|
|
_id: string;
|
|
organisationId?: string | undefined;
|
|
by?: MetaBy | undefined;
|
|
paths?: EnginePathComponent[];
|
|
permissions: MetaPermissions;
|
|
createdAt: Date;
|
|
updatedAt: Date;
|
|
}
|