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

135 lines
2.8 KiB
TypeScript

import { ObjectType, Field, InputType } from 'type-graphql';
import { ProductRessourceEnum } from '@src/__components/components';
import { GraphQLJSONObject } from 'graphql-type-json';
import { AddOnComponent, LocaleInfo } from '@services/module-payments/components/components.orders';
export interface LineProductInterface {
_id: string;
productRessource: ProductRessourceEnum;
productId: string;
title: string;
price: number;
salesPrice?: number;
quantity: number;
vatClassId?: string;
// vatPrice(): number;
finalPrice(): number;
// linePrice(): number;
organisationId?: string;
parentId?: string;
addOns?: AddOnComponent[];
localeInfo?: LocaleInfo;
}
export interface LineProductFunctionInterface {
validateCartOption?(data: any): any;
getLinePrice?(data: any): any;
}
@ObjectType()
export class LineProductClass implements LineProductInterface {
// linePrice(): number {
// throw new Error('Method not implemented.');
// }
@Field()
_id: string;
@Field(() => ProductRessourceEnum)
productRessource: ProductRessourceEnum;
@Field()
productId: string;
@Field()
title: string;
@Field()
price: number;
@Field()
salesPrice?: number;
@Field()
quantity: number;
@Field()
vatClassId?: string;
@Field({ nullable: true })
parentId?: string;
@Field(() => [AddOnComponent], { nullable: true })
addOns?: AddOnComponent[];
@Field(() => LocaleInfo, { nullable: true })
localeInfo?: LocaleInfo;
@Field({ nullable: true })
promoId?: string;
// @Field()
// vatPrice(): number {
// throw 'Implements on parent';
// }
validateCartOption?(): any;
organisationId?: string;
@Field({ nullable: true })
finalPrice(): number {
if (this.salesPrice) return this.salesPrice;
else return this.price;
}
}
@ObjectType()
@InputType('LineProductBaseInput')
export class LineProductBase {
@Field(() => ProductRessourceEnum)
productRessource: ProductRessourceEnum;
@Field()
productId: string;
@Field()
quantity: number;
@Field({ nullable: true })
parentId?: string;
@Field(() => GraphQLJSONObject, { nullable: true })
options?: any;
@Field(() => [AddOnComponent], { nullable: true })
addOns?: AddOnComponent[];
}
@ObjectType()
@InputType('LineProductBaseSuppInput')
export class LineProductBaseSupp extends LineProductBase {
@Field()
parentId: string;
}
export interface LineProductBaseInterface {
getLineProduct(input: { quantity: number }): LineProductInterface;
getLineProductFunctions(input: any): LineProductFunctionInterface;
}
@InputType('LineItemGenericSchemaInput')
@ObjectType()
export abstract class LineItemGenericSchema extends LineProductClass {
options?: any;
}