40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
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<plugins.servezoneInterfaces.requests.service.IRequest_Any_Cloudly_GetServices>(
|
|
'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();
|
|
})
|
|
),
|
|
};
|
|
}
|
|
)
|
|
);
|
|
}
|
|
}
|