import { GetArgs } from '@lib/seed/graphql/Request'; import { ApolloContext } from '@lib/seed/interfaces/context'; import { baseSearchFunction } from '@lib/seed/services/database/DBRequestService'; import { EngineModel } from '../EngineModel'; /* ██████╗ ██╗ ██╗███████╗██████╗ ██╗ ██╗ ██╔═══██╗██║ ██║██╔════╝██╔══██╗╚██╗ ██╔╝ ██║ ██║██║ ██║█████╗ ██████╔╝ ╚████╔╝ ██║▄▄ ██║██║ ██║██╔══╝ ██╔══██╗ ╚██╔╝ ╚██████╔╝╚██████╔╝███████╗██║ ██║ ██║ ╚══▀▀═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ */ export const getOneGeneric = async (model: any, id: string, ctx: ApolloContext): Promise => { try { return await (model as EngineModel).getOne({ query: { _id: id }, ctx }); } catch (error) { throw error; } }; export const getManyGeneric = async (model: any, query: any, pagination: GetArgs | undefined, ctx: ApolloContext | null): Promise => { return baseSearchFunction({ model: model, query: query, pagination: pagination, engine: true, ctx: ctx, }); }; export const getCountGeneric = async (model: any, baseArguments: any, ctx: ApolloContext): Promise => { // eslint-disable-next-line @typescript-eslint/no-unused-vars const { pagination, ...args } = baseArguments; const result = await baseSearchFunction({ model: model, query: args, count: true, engine: true, ctx: ctx, }); return result; }; export const getManyGenericWithArgs = async (model: any, baseArguments: any, ctx: ApolloContext | null): Promise => { try { const { pagination, ...args } = baseArguments; return baseSearchFunction({ model: model, query: args, pagination: pagination, engine: true, ctx: ctx, }); } catch (error) { throw error; } }; // export const editOneGeneric = async (model: T, id: string, body: Partial, ctx: ApolloContext): Promise => { // try { // await model as EngineModel).updateOne({ _id: id } as any, body, ctx); // return model as EngineModel).get(); // } catch (error) { // throw error; // } // }; // export const deleteOneGeneric = async (model: T, id: string, ctx: ApolloContext): Promise => { // try { // await model as EngineModel).deleteOne({ _id: id } as any, ctx); // return model as EngineModel).get(); // } catch (error) { // throw error; // } // }; // export const permissionsAddOne = async (model: any, id: string, input: NewPermissionInput, ctx: ApolloContext): Promise => { // try { // await model as EngineModel).updateOneCustom({ _id: id }, { $addToSet: { [`${input.permissionType}`]: input.permission } }, ctx); // return model as EngineModel).get(); // } catch (error) { // throw error; // } // }; // export const permissionsRemoveOne = async (model: any, id: string, input: NewPermissionInput, ctx: ApolloContext): Promise => { // try { // await model as EngineModel).updateOneCustom({ _id: id }, { $pull: { [`${input.permissionType}`]: input.permission } }, ctx); // return model as EngineModel).get(); // } catch (error) { // throw error; // } // }; // export const publishOneGeneric = async (model: T, id: string, ctx: ApolloContext): Promise => { // try { // const missingInputs: string[] = []; // // TODO THE CHECK OF THE INPUTS // if (missingInputs.length > 0) throw newError('missingInput', '400', missingInputs); // return editOneGeneric(model, id, { published: true, publicationDate: new Date() } as any, ctx); // } catch (error) { // throw error; // } // }; // export const unpublishOneGeneric = async (model: T, id: string, ctx: ApolloContext): Promise => { // try { // return editOneGeneric(model, id, { published: false } as any, ctx); // } catch (error) { // throw error; // } // };