diff --git a/src/ops/ServiceOps.test.ts b/src/ops/ServiceOps.test.ts index cd58e8b28..e2b83c0c0 100644 --- a/src/ops/ServiceOps.test.ts +++ b/src/ops/ServiceOps.test.ts @@ -107,7 +107,7 @@ describe('ServiceOps', () => { //TODO: create tests }); - describe('deleteFullService()', () => { + describe('deleteFullService(descendentOnly: boolean,)', () => { test('0: Method is implemented', async () => { expect(ServiceOps.deleteFullService).toBeDefined(); }); diff --git a/src/ops/ServiceOps.ts b/src/ops/ServiceOps.ts index 56f7117d5..53f66376c 100644 --- a/src/ops/ServiceOps.ts +++ b/src/ops/ServiceOps.ts @@ -8,6 +8,7 @@ import { getServiceDescendents, putService, putServiceNextDescendent, + type ServiceNextDescendent, } from '../api/ServiceApi'; import { State } from '../shared/State'; import { @@ -43,6 +44,7 @@ export type Service = { * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false. */ deleteFullService( + descendentOnly: boolean, serviceId: string, globalConfig?: boolean ): Promise; @@ -119,12 +121,12 @@ export default (state: State): Service => { * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false. */ async deleteFullService( + descendentOnly: boolean, serviceId: string, globalConfig = false ): Promise { - return deleteFullService({ serviceId, globalConfig, state }); + return deleteFullService(descendentOnly,{ serviceId, globalConfig, state }); }, - /** * Deletes all services * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false. @@ -371,7 +373,7 @@ export async function putFullService({ if (clean) { try { debugMessage({ message: `ServiceOps.putFullService: clean`, state }); - await deleteFullService({ serviceId, globalConfig, state }); + await deleteFullService(false ,{ serviceId, globalConfig, state }); } catch (error) { if ( !( @@ -546,7 +548,9 @@ export async function putFullServices({ * @param {string} serviceId The service to delete * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false. */ -export async function deleteFullService({ +export async function deleteFullService( + descendentOnly: boolean, + { serviceId, globalConfig = false, state, @@ -557,7 +561,7 @@ export async function deleteFullService({ }) { try { debugMessage({ - message: `ServiceOps.deleteFullService: start, globalConfig=${globalConfig}`, + message: `ServiceOps.deleteFullService: start, globalConfig=${globalConfig}, delete descendents only is ${descendentOnly}`, state, }); const serviceNextDescendentData = await getServiceDescendents({ @@ -566,7 +570,7 @@ export async function deleteFullService({ state, }); - await Promise.all( + const descendents = await Promise.all( serviceNextDescendentData.map((nextDescendent) => deleteServiceNextDescendent({ serviceId, @@ -579,7 +583,8 @@ export async function deleteFullService({ ); debugMessage({ message: `ServiceOps.deleteFullService: end`, state }); - return deleteService({ serviceId, globalConfig, state }); + if(!descendentOnly) return deleteService({ serviceId, globalConfig, state }); + } catch (error) { throw new FrodoError( `Error deleting ${ @@ -612,7 +617,7 @@ export async function deleteFullServices({ const deleted: AmServiceSkeleton[] = await Promise.all( serviceList.map(async (serviceListItem) => { try { - return deleteFullService({ + return deleteFullService(false,{ serviceId: serviceListItem._id, globalConfig, state,