import { PresentationModel } from "../models/PresentationModel" ; import uniqid from "uniqid" ; import { PresentationSlide , PresentationInterface , } from "../../types/presentation" ; export function getPresentationsByOrganization ( organization ) { return PresentationModel . find ( { organization , } ) ; } export function getPresentationById ( id ) { return PresentationModel . findOne ( { id , } ) ; } export async function removeExperimentFromPresentations ( experiment ) { const presentations = await PresentationModel . find ( { "slides.id" : experiment , } ) ; await Promise . all ( presentations . map ( async ( presentation ) => { presentation . slides = presentation . slides . filter ( ( obj ) => obj . id !== experiment || obj . type !== "experiment" ) ; presentation . markModified ( "slides" ) ; await presentation . save ( ) ; } ) ) ; } export async function createPresentation ( data ) { if ( ! data . slides || ! data . userId || ! data . organization ) { throw new Error ( "Missing required presentation data" ) ; } const exps = [ ... data . slides ] ; const pres = { slides : exps , title : data ?. title || "" , description : data ?. description || "" , userId : data . userId , organization : data . organization , voting : data ?. voting || true , theme : data ?. theme || "" , id : uniqid ( "pres_" ) , dateCreated : new Date ( ) , dateUpdated : new Date ( ) , } ; if ( data ?. options ) { pres . options = data . options ; } if ( data ?. customTheme ) { pres . customTheme = data . customTheme ; } return PresentationModel . create ( pres ) ; } export function deletePresentationById ( id ) { return PresentationModel . deleteOne ( { id , } ) ; }