77 lines
2.3 KiB
TypeScript
77 lines
2.3 KiB
TypeScript
import { IEngineSchema, MetaBy, MetaPermissions } from '@seed/engine/EngineSchema';
|
|
import { EnginePathComponent, StatusEnum } from '@seed/interfaces/components';
|
|
import { DateRangeComponent, SlotComponent } from '@seed/interfaces/components.dates';
|
|
import { ApolloContext } from '@seed/interfaces/context';
|
|
import AccountModel from '@src/accounts/account.model';
|
|
import { Type } from 'class-transformer';
|
|
import { ValidateNested, IsNotEmpty, ValidateIf } from 'class-validator';
|
|
import { Ctx, Field, InputType, Int, ObjectType } from 'type-graphql';
|
|
import { DurationTypeEnum } from '../../components';
|
|
|
|
@ObjectType()
|
|
@InputType()
|
|
export class BookingEngineBaseSchema {
|
|
@Field(() => DurationTypeEnum)
|
|
@IsNotEmpty()
|
|
durationType: DurationTypeEnum;
|
|
|
|
@Field(() => DateRangeComponent, { nullable: true })
|
|
@Type(() => DateRangeComponent)
|
|
@ValidateIf((o: BookingEngineBaseSchema) => {
|
|
return o.durationType == DurationTypeEnum.startToEnd;
|
|
})
|
|
@IsNotEmpty()
|
|
@ValidateNested()
|
|
startToEnd?: DateRangeComponent;
|
|
|
|
@Field(() => SlotComponent, { nullable: true })
|
|
@Type(() => SlotComponent)
|
|
@ValidateIf((o: BookingEngineBaseSchema) => {
|
|
return o.durationType == DurationTypeEnum.slot;
|
|
})
|
|
@IsNotEmpty()
|
|
@ValidateNested()
|
|
slot?: SlotComponent;
|
|
|
|
@Field(() => Int, { nullable: true })
|
|
capacity?: number;
|
|
|
|
@Field({ nullable: true })
|
|
comments?: string;
|
|
}
|
|
|
|
@ObjectType()
|
|
export class BookingEngineDBInterfaceSchema extends BookingEngineBaseSchema {
|
|
@Field(() => StatusEnum)
|
|
status: StatusEnum;
|
|
|
|
@Field(() => [EnginePathComponent])
|
|
paths: EnginePathComponent[];
|
|
|
|
@Field()
|
|
@IsNotEmpty()
|
|
ownerId: string;
|
|
|
|
@Field(() => [DateRangeComponent])
|
|
@IsNotEmpty()
|
|
dates: DateRangeComponent[];
|
|
}
|
|
|
|
@ObjectType()
|
|
export class BookingEngineDBSchema extends BookingEngineDBInterfaceSchema {
|
|
@Field(() => AccountModel)
|
|
async owner(@Ctx() ctx: ApolloContext): Promise<AccountModel> {
|
|
return ctx.ctx.loaders.accountLoader.load(this.ownerId);
|
|
}
|
|
}
|
|
|
|
@ObjectType({ implements: IEngineSchema })
|
|
export class BookingEngineSchema extends BookingEngineDBSchema implements IEngineSchema {
|
|
_id: string;
|
|
organisationId?: string | undefined;
|
|
by?: MetaBy | undefined;
|
|
permissions: MetaPermissions;
|
|
createdAt: Date;
|
|
updatedAt: Date;
|
|
}
|