Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/ops/ServiceOps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
21 changes: 13 additions & 8 deletions 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 @@ -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<AmServiceSkeleton>;
Expand Down Expand Up @@ -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<AmServiceSkeleton> {
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.
Expand Down Expand Up @@ -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 (
!(
Expand Down Expand Up @@ -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,
Expand All @@ -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({
Expand All @@ -566,7 +570,7 @@ export async function deleteFullService({
state,
});

await Promise.all(
const descendents = await Promise.all(
serviceNextDescendentData.map((nextDescendent) =>
deleteServiceNextDescendent({
serviceId,
Expand All @@ -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 ${
Expand Down Expand Up @@ -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,
Expand Down