import { from , map , Observable } from 'rxjs' ; import { Model } from 'mongoose' ; import { EntityType , EntityUpdate , WatermarkedType , } from '@dark-rush-photography/shared/types' ; import { DocumentModel } from '../schema/document.schema' ; import { loadCreateEntityForFolder , loadCreateImagePostEntity , loadCreateTestEntity , loadDocumentModelsArray , loadUpdateEntity , } from './entity-load-document-model.functions' ; export const createTestEntity$ = ( entityModel ) : Observable < DocumentModel > => from ( new entityModel ( { ... loadCreateTestEntity ( ) , } ) . save ( ) ) ; export const createEntityForFolder$ = ( entityType , googleDriveFolderId , watermarkedType , group , slug , order , entityModel ) : Observable < DocumentModel > => from ( new entityModel ( { ... loadCreateEntityForFolder ( entityType , googleDriveFolderId , watermarkedType , group , slug , order ) , } ) . save ( ) ) ; export const createImagePostEntity$ = ( text , entityModel ) : Observable < DocumentModel > => from ( new entityModel ( { ... loadCreateImagePostEntity ( text ) , } ) . save ( ) ) ; export const updateEntity$ = ( entityId , entityUpdate , entityModel ) : Observable < DocumentModel | null > => from ( entityModel . findByIdAndUpdate ( entityId , { ... loadUpdateEntity ( entityUpdate ) , } ) ) ; export const findEntityById$ = ( entityId , entityModel ) : Observable < DocumentModel | null > => from ( entityModel . findById ( entityId ) ) ; export const findEntityByIdAndUpdateOrder$ = ( entityId , order , entityModel ) : Observable < DocumentModel | null > => from ( entityModel . findByIdAndUpdate ( entityId , { order } ) ) ; export const findEntityByIdAndMakePublic$ = ( entityId , entityModel ) : Observable < DocumentModel | null > => from ( entityModel . findByIdAndUpdate ( entityId , { isPublic : true } ) ) ; export const findPublicEntityById$ = ( entityId , entityModel ) : Observable < DocumentModel | null > => from ( entityModel . findOne ( { _id : entityId , isPublic : true , isDeleted : false , } ) ) ; export const findOneEntity$ = ( entityType , watermarkedType , group , slug , entityModel ) : Observable < DocumentModel | null > => from ( entityModel . findOne ( { type : entityType , watermarkedType , group , slug , } ) ) ; export const findOnePublicEntityForSlug$ = ( entityType , slug , entityModel ) : Observable < DocumentModel | null > => from ( entityModel . findOne ( { type : entityType , slug , isPublic : true , isDeleted : false , } ) ) ; export const findAllEntities$ = ( entityType , watermarkedType , entityModel ) : Observable < DocumentModel [ ] > => from ( entityModel . find ( { type : entityType , watermarkedType , isDeleted : false , } ) ) . pipe ( map ( loadDocumentModelsArray ) ) ; export const findAllEntitiesForWatermarkedGroup$ = ( entityType , watermarkedType , group , entityModel ) : Observable < DocumentModel [ ] > => from ( entityModel . find ( { type : entityType , watermarkedType , group , isDeleted : false , } ) ) . pipe ( map ( loadDocumentModelsArray ) ) ; export const findAllEntitiesForGroup$ = ( entityType , group , entityModel ) : Observable < DocumentModel [ ] > => from ( entityModel . find ( { type : entityType , group , isDeleted : false , } ) ) . pipe ( map ( loadDocumentModelsArray ) ) ; export const findAllTestEntities$ = ( entityModel ) : Observable < DocumentModel [ ] > => from ( entityModel . find ( { type : EntityType . Test , } ) ) . pipe ( map ( loadDocumentModelsArray ) ) ; export const findAllPublicEntities$ = ( entityType , entityModel ) : Observable < DocumentModel [ ] > => from ( entityModel . find ( { type : entityType , isPublic : true , isDeleted : false , } ) ) . pipe ( map ( loadDocumentModelsArray ) ) ; export const findEntityByIdAndSoftDelete$ = ( entityId , entityModel ) : Observable < DocumentModel | null > => from ( entityModel . findByIdAndUpdate ( entityId , { isDeleted : true } ) ) ; export const findEntityByIdAndDelete$ = ( entityId , entityModel ) : Observable < DocumentModel | null > => from ( entityModel . findByIdAndDelete ( entityId ) ) ;