import type { Cloudly } from '../classes.cloudly.js'; import * as plugins from '../plugins.js'; import { Service } from './classes.service.js'; export class ServiceManager { public typedrouter = new plugins.typedrequest.TypedRouter(); public cloudlyRef: Cloudly; get db() { return this.cloudlyRef.mongodbConnector.smartdataDb; } public CService = plugins.smartdata.setDefaultManagerForDoc(this, Service); constructor(cloudlyRef: Cloudly) { this.cloudlyRef = cloudlyRef; this.typedrouter.addTypedHandler( new plugins.typedrequest.TypedHandler( 'getServices', async (reqArg) => { await plugins.smartguard.passGuardsOrReject(reqArg, [ this.cloudlyRef.authManager.validIdentityGuard, ]); const services = await this.CService.getInstances({}); return { services: await Promise.all( services.map((service) => { return service.createSavableObject(); }) ), }; } ) ); } }