backend/lib/seed/graphql/baseModels/BaseContentModel.ts
2025-05-14 21:45:16 +02:00

107 lines
3.4 KiB
TypeScript

import { ObjectType, Field, ID, ArgsType, InputType, Int } from 'type-graphql';
import { BaseGraphModel } from '@seed/graphql/BaseGraphModel';
import ImageComponent, { SEOField } from '@seed/interfaces/components';
import { GetArgs, GetManyArgs } from '@seed/graphql/Request';
import { TranslatableComponent } from '@src/__components/components';
import { Permission } from '@seed/interfaces/permission';
import BaseSEOModel, { NewBaseSEOInput, EditBaseSEOInput } from './BaseSeoModel';
import CategoryModel from '@services/module-cms/functions/categories/category.model';
import { AccountTypeEnum } from '@src/accounts/account.components';
const permissions: Permission = {
c: [AccountTypeEnum.admin],
r: [AccountTypeEnum.public],
w: [AccountTypeEnum.admin],
d: [AccountTypeEnum.admin],
};
@ObjectType()
export default class BaseContentModel extends BaseSEOModel {
public constructor(collectionName?: string, perm?: Permission) {
const cName = collectionName ? collectionName : 'articles';
const permission = perm ? perm : permissions;
super(cName, permission);
}
@Field()
published?: boolean;
@Field({ nullable: true })
publicationDate?: Date;
@Field({ nullable: true })
private?: boolean;
@Field(() => [String], { nullable: true })
categoryIds?: string[];
@Field(() => [CategoryModel], { nullable: 'itemsAndList' })
getCategories?: CategoryModel[];
@Field(() => [ImageComponent], { nullable: true })
downloadableRessources?: ImageComponent[];
@Field(() => TranslatableComponent, { nullable: true })
testimonials?: TranslatableComponent;
searchOptions(): string[] {
return [];
}
}
@ArgsType()
export class BaseContentArgs extends GetManyArgs {}
@InputType()
export class NewBaseContentInput extends NewBaseSEOInput implements Partial<BaseContentModel> {
@Field(() => TranslatableComponent, { nullable: true })
title?: TranslatableComponent;
@Field(() => TranslatableComponent, { nullable: true })
teaser?: TranslatableComponent;
@Field(() => ImageComponent, { nullable: true })
cover?: ImageComponent;
@Field(() => ImageComponent, { nullable: true })
thumbnail?: ImageComponent;
@Field(() => [String], { nullable: true })
categoryIds?: string[];
@Field(() => [ImageComponent], { nullable: true })
downloadableRessources?: ImageComponent[];
published = false;
@Field({ nullable: true })
private?: boolean;
@Field(() => TranslatableComponent, { nullable: true })
testimonials?: TranslatableComponent;
}
@InputType()
export class EditBaseContentInput extends EditBaseSEOInput implements Partial<BaseContentModel> {
@Field(() => TranslatableComponent, { nullable: true })
title?: TranslatableComponent;
@Field(() => TranslatableComponent, { nullable: true })
teaser?: TranslatableComponent;
@Field(() => TranslatableComponent, { nullable: true })
content?: TranslatableComponent;
@Field(() => ImageComponent, { nullable: true })
cover?: ImageComponent;
@Field(() => ImageComponent, { nullable: true })
thumbnail?: ImageComponent;
@Field(() => [String], { nullable: true })
categoryIds?: string[];
@Field(() => [ImageComponent], { nullable: true })
downloadableRessources?: ImageComponent[];
@Field({ nullable: true })
private?: boolean;
@Field(() => TranslatableComponent, { nullable: true })
testimonials?: TranslatableComponent;
}