backend/lib/seed/services/change-stream/change-stream.model.ts
2025-05-14 21:45:16 +02:00

69 lines
1.7 KiB
TypeScript

import { ObjectType, Field, ArgsType } from 'type-graphql';
import { BaseGraphModel } from '@seed/graphql/BaseGraphModel';
import { Permission } from '@seed/interfaces/permission';
import { GetArgs, GetManyArgs } from '@seed/graphql/Request';
import { AccountTypeEnum } from '@src/accounts/account.components';
import { StreamOperationType, PostHookStatus } from './change-stream.components';
import GraphQLJSON from 'graphql-type-json';
const permissions: Permission = {
c: [AccountTypeEnum.admin],
r: [AccountTypeEnum.admin],
w: [AccountTypeEnum.admin],
d: [AccountTypeEnum.admin],
};
@ObjectType()
export default class ChangeStreamModel<T = any> extends BaseGraphModel {
public constructor() {
super({
//!!\\ Hard coded, do not change !
collectionName: 'stream.changes',
permissions: permissions,
});
}
@Field(() => StreamOperationType)
operation: StreamOperationType;
@Field()
collection: string;
@Field()
documentKey: string;
@Field(() => PostHookStatus)
hookStatus: PostHookStatus;
@Field({ nullable: true })
logMessage?: string;
@Field(() => GraphQLJSON, { nullable: true })
insertedValues?: Partial<T>;
@Field(() => GraphQLJSON, { nullable: true })
updatedValues?: Partial<T>;
@Field(() => GraphQLJSON, { nullable: true })
beforeUpdateValues?: Partial<T>;
logInfo?: any;
searchOptions(): string[] {
return ['documentKey', 'hookStatus'];
}
filterOptions(): string[] {
return ['documentKey', 'hookStatus'];
}
}
@ArgsType()
export class ChangeStreamArgs extends GetManyArgs {
@Field({ nullable: true })
documentKey?: string;
@Field({ nullable: true })
hookStatus?: string;
}