2024-06-13 09:36:02 +02:00
|
|
|
import type { Cloudly } from '../classes.cloudly.js';
|
|
|
|
import * as plugins from '../plugins.js';
|
2024-06-13 10:07:53 +02:00
|
|
|
import { Service } from './classes.service.js';
|
2024-06-13 09:36:02 +02:00
|
|
|
|
|
|
|
export class ServiceManager {
|
|
|
|
public typedrouter = new plugins.typedrequest.TypedRouter();
|
|
|
|
public cloudlyRef: Cloudly;
|
2024-10-27 19:50:39 +01:00
|
|
|
|
2024-06-13 09:36:02 +02:00
|
|
|
get db() {
|
|
|
|
return this.cloudlyRef.mongodbConnector.smartdataDb;
|
|
|
|
}
|
|
|
|
|
|
|
|
public CService = plugins.smartdata.setDefaultManagerForDoc(this, Service);
|
2024-06-13 10:07:53 +02:00
|
|
|
|
|
|
|
constructor(cloudlyRef: Cloudly) {
|
|
|
|
this.cloudlyRef = cloudlyRef;
|
2024-12-14 20:32:17 +01:00
|
|
|
|
|
|
|
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();
|
|
|
|
})
|
|
|
|
),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2025-01-20 02:11:12 +01:00
|
|
|
|
|
|
|
this.typedrouter.addTypedHandler(
|
|
|
|
new plugins.typedrequest.TypedHandler<plugins.servezoneInterfaces.requests.service.IRequest_Any_Cloudly_GetServiceSecretBundlesAsFlatObject>(
|
|
|
|
'getServiceSecretBundlesAsFlatObject',
|
|
|
|
async (dataArg) => {
|
|
|
|
const service = await Service.getInstance({
|
|
|
|
id: dataArg.serviceId,
|
|
|
|
});
|
|
|
|
const flatKeyValueObject = await service.getSecretBundlesAsFlatObject(dataArg.environment);
|
|
|
|
return {
|
|
|
|
flatKeyValueObject: flatKeyValueObject,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
this.typedrouter.addTypedHandler(
|
|
|
|
new plugins.typedrequest.TypedHandler<plugins.servezoneInterfaces.requests.service.IRequest_Any_Cloudly_CreateService>(
|
|
|
|
'createService',
|
|
|
|
async (dataArg) => {
|
|
|
|
const service = await Service.createService(dataArg.serviceData);
|
|
|
|
return {
|
|
|
|
service: await service.createSavableObject(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2025-01-20 02:18:58 +01:00
|
|
|
|
|
|
|
this.typedrouter.addTypedHandler(
|
|
|
|
new plugins.typedrequest.TypedHandler<plugins.servezoneInterfaces.requests.service.IRequest_Any_Cloudly_UpdateService>(
|
|
|
|
'updateService',
|
|
|
|
async (dataArg) => {
|
|
|
|
const service = await Service.getInstance({
|
|
|
|
id: dataArg.serviceId,
|
|
|
|
});
|
|
|
|
service.data = {
|
|
|
|
...service.data,
|
|
|
|
...dataArg.serviceData,
|
|
|
|
};
|
|
|
|
await service.save();
|
|
|
|
return {
|
|
|
|
service: await service.createSavableObject(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
this.typedrouter.addTypedHandler(
|
|
|
|
new plugins.typedrequest.TypedHandler<plugins.servezoneInterfaces.requests.service.IRequest_Any_Cloudly_DeleteServiceById>(
|
|
|
|
'deleteServiceById',
|
|
|
|
async (dataArg) => {
|
|
|
|
const service = await Service.getInstance({
|
|
|
|
id: dataArg.serviceId,
|
|
|
|
});
|
|
|
|
await service.delete();
|
|
|
|
return {
|
|
|
|
success: true,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2024-06-13 10:07:53 +02:00
|
|
|
}
|
2024-10-27 19:50:39 +01:00
|
|
|
}
|