import { IdeaDocument , IdeaModel } from "../models/IdeasModel" ; import uniqid from "uniqid" ; import { addTags } from "./tag" ; import { IdeaInterface } from "../../types/idea" ; import { FilterQuery } from "mongoose" ; export function getIdeasByOrganization ( organization , project ? ) { const query = { organization , } ; if ( project ) { query . project = project ; } return IdeaModel . find ( query ) ; } export function getIdeasByQuery ( query ) { return IdeaModel . find ( query ) ; } export async function createIdea ( data ) { const idea = await IdeaModel . create ( { ... data , id : uniqid ( "idea_" ) , dateCreated : new Date ( ) , dateUpdated : new Date ( ) , } ) ; if ( idea . tags ) { await addTags ( idea . organization , idea . tags ) ; } return idea ; } export function getIdeaById ( id ) { return IdeaModel . findOne ( { id , } ) ; } export function getIdeasByIds ( ids ) { return IdeaModel . find ( { id : { $in : ids } , } ) ; } export function getIdeasByExperimentIds ( ids ) { const tmp = [ ] ; ids . map ( ( id ) => { tmp . push ( { experimentId : id } ) ; } ) ; return IdeaModel . find ( { evidence : { $in : tmp } , } ) ; } export function deleteIdeaById ( id ) { return IdeaModel . deleteOne ( { id , } ) ; }