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

93 lines
1.9 KiB
TypeScript

import { ObjectType, Field, ID, ArgsType, InputType, registerEnumType } from 'type-graphql';
import { BaseGraphModel } from '@seed/graphql/BaseGraphModel';
import { Permission } from '@seed/interfaces/permission';
import { GetArgs } from '@seed/graphql/Request';
import AccountModel from '@src/accounts/account.model';
import { AccountTypeEnum } from '@src/accounts/account.components';
const permissions: Permission = {
c: [AccountTypeEnum.admin],
r: [AccountTypeEnum.public],
w: [AccountTypeEnum.admin],
d: [AccountTypeEnum.admin],
};
export enum FileType {
image = 'image',
document = 'document',
}
registerEnumType(FileType, {
name: 'FileType',
});
@ObjectType()
export default class FileModel extends BaseGraphModel {
public constructor() {
super({
// ...init,
collectionName: 'files',
permissions: permissions,
});
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@Field(() => ID)
readonly _id: string;
@Field()
title: string;
@Field()
accountId: string;
@Field(() => AccountModel, { nullable: true })
account?: AccountModel;
@Field()
fileType: FileType;
@Field()
fileName: string;
@Field()
large: string;
@Field({ nullable: true })
medium?: string;
@Field({ nullable: true })
small?: string;
@Field({ nullable: true })
fileNameMedium?: string;
@Field({ nullable: true })
fileNameSmall?: string;
searchOptions(): string[] {
return ['title'];
}
filterOptions(): string[] {
return ['title'];
}
}
@ArgsType()
export class FileArgs {
@Field(() => GetArgs, { nullable: true })
pagination?: GetArgs;
}
@InputType()
export class NewFileInput {
@Field()
title: string;
@Field()
base64: string;
@Field({ nullable: true })
privateFile?: boolean;
}