Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion src/ops/ServiceOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getServiceDescendents,
putService,
putServiceNextDescendent,
type ServiceNextDescendent,
} from '../api/ServiceApi';
import { State } from '../shared/State';
import {
Expand Down Expand Up @@ -46,6 +47,10 @@ export type Service = {
serviceId: string,
globalConfig?: boolean
): Promise<AmServiceSkeleton>;
deleteServiceNextDescendentOnly(
serviceId: string,
globalConfig?: boolean
): Promise<ServiceNextDescendent>;
/**
* Deletes all services
* @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.
Expand Down Expand Up @@ -124,7 +129,16 @@ export default (state: State): Service => {
): Promise<AmServiceSkeleton> {
return deleteFullService({ serviceId, globalConfig, state });
},

async deleteServiceNextDescendentOnly(
serviceId: string,
globalConfig = false
): Promise<ServiceNextDescendent> {
return deleteServiceNextDescentdentOnly({
serviceId,
globalConfig,
state,
});
},
/**
* Deletes all services
* @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.
Expand Down Expand Up @@ -590,6 +604,46 @@ export async function deleteFullService({
}
}

export async function deleteServiceNextDescentdentOnly({
serviceId,
globalConfig = false,
state,
}: {
serviceId: string;
globalConfig: boolean;
state: State;
}): Promise<ServiceNextDescendent> {
try {
debugMessage({
message: `ServiceOps.deleteServiceDescendentOnly: start, globalConfig=${globalConfig}`,
state,
});
const serviceNextDescendentData = await getServiceDescendents({
serviceId,
globalConfig,
state,
});

return await Promise.all(
serviceNextDescendentData.map((nextDescendent) =>
deleteServiceNextDescendent({
serviceId,
serviceType: nextDescendent._type._id,
serviceNextDescendentId: nextDescendent._id,
globalConfig,
state,
})
)
);
} catch (error) {
throw new FrodoError(
`Error deleting ${
globalConfig ? 'global' : 'realm'
} full service config ${serviceId}`,
error
);
}
}
/**
* Deletes all services
* @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.
Expand Down