diff --git a/apps/api-gateway/schema.graphql b/apps/api-gateway/schema.graphql index c56111d07b7..782552edb3c 100644 --- a/apps/api-gateway/schema.graphql +++ b/apps/api-gateway/schema.graphql @@ -375,7 +375,7 @@ input LinkActionInput { type Mutation { """blockDelete returns the updated sibling blocks on successful delete""" - blockDelete(id: ID!, journeyId: ID!, parentBlockId: ID!): [Block!]! @join__field(graph: JOURNEYS) + blockDelete(id: ID!, journeyId: ID!, parentBlockId: ID): [Block!]! @join__field(graph: JOURNEYS) blockDeleteAction(id: ID!, journeyId: ID!): Block! @join__field(graph: JOURNEYS) blockOrderUpdate(id: ID!, journeyId: ID!, parentOrder: Int!): [Block!]! @join__field(graph: JOURNEYS) blockUpdateLinkAction(id: ID!, input: LinkActionInput!, journeyId: ID!): LinkAction! @join__field(graph: JOURNEYS) diff --git a/apps/api-journeys/schema.graphql b/apps/api-journeys/schema.graphql index 48d79a0b324..5c60ea3d418 100644 --- a/apps/api-journeys/schema.graphql +++ b/apps/api-journeys/schema.graphql @@ -730,7 +730,7 @@ extend type Mutation { blockUpdateLinkAction(id: ID!, journeyId: ID!, input: LinkActionInput!): LinkAction! """blockDelete returns the updated sibling blocks on successful delete""" - blockDelete(id: ID!, parentBlockId: ID!, journeyId: ID!): [Block!]! + blockDelete(id: ID!, journeyId: ID!, parentBlockId: ID): [Block!]! blockOrderUpdate(id: ID!, journeyId: ID!, parentOrder: Int!): [Block!]! buttonBlockCreate(input: ButtonBlockCreateInput!): ButtonBlock! buttonBlockUpdate(id: ID!, journeyId: ID!, input: ButtonBlockUpdateInput!): ButtonBlock diff --git a/apps/api-journeys/src/app/__generated__/graphql.ts b/apps/api-journeys/src/app/__generated__/graphql.ts index d643778aa8e..62ce468a301 100644 --- a/apps/api-journeys/src/app/__generated__/graphql.ts +++ b/apps/api-journeys/src/app/__generated__/graphql.ts @@ -651,7 +651,7 @@ export abstract class IMutation { abstract blockUpdateLinkAction(id: string, journeyId: string, input: LinkActionInput): LinkAction | Promise; - abstract blockDelete(id: string, parentBlockId: string, journeyId: string): Block[] | Promise; + abstract blockDelete(id: string, journeyId: string, parentBlockId?: Nullable): Block[] | Promise; abstract blockOrderUpdate(id: string, journeyId: string, parentOrder: number): Block[] | Promise; diff --git a/apps/api-journeys/src/app/modules/block/block.graphql b/apps/api-journeys/src/app/modules/block/block.graphql index 187bd190b76..302c71b4b6d 100644 --- a/apps/api-journeys/src/app/modules/block/block.graphql +++ b/apps/api-journeys/src/app/modules/block/block.graphql @@ -13,6 +13,6 @@ extend type Mutation { """ blockDelete returns the updated sibling blocks on successful delete """ - blockDelete(id: ID!, parentBlockId: ID!, journeyId: ID!): [Block!]! + blockDelete(id: ID!, journeyId: ID!, parentBlockId: ID): [Block!]! blockOrderUpdate(id: ID!, journeyId: ID!, parentOrder: Int!): [Block!]! } diff --git a/apps/api-journeys/src/app/modules/block/block.resolver.spec.ts b/apps/api-journeys/src/app/modules/block/block.resolver.spec.ts index 9e27241d9e7..7b58bc0cc48 100644 --- a/apps/api-journeys/src/app/modules/block/block.resolver.spec.ts +++ b/apps/api-journeys/src/app/modules/block/block.resolver.spec.ts @@ -75,13 +75,13 @@ describe('BlockResolver', () => { describe('blockDelete', () => { it('removes the block and its children', async () => { - const data = await resolver.blockDelete('image1', 'card1', '2') + const data = await resolver.blockDelete('image1', '2', 'card1') expect(service.removeBlockAndChildren).toBeCalledTimes(1) expect(service.removeBlockAndChildren).toHaveBeenCalledWith( 'image1', - 'card1', - '2' + '2', + 'card1' ) expect(data).toEqual([image1, image2, image3]) }) diff --git a/apps/api-journeys/src/app/modules/block/block.resolver.ts b/apps/api-journeys/src/app/modules/block/block.resolver.ts index 61c54055ed0..6d968e6097e 100644 --- a/apps/api-journeys/src/app/modules/block/block.resolver.ts +++ b/apps/api-journeys/src/app/modules/block/block.resolver.ts @@ -72,13 +72,13 @@ export class BlockResolver { ) async blockDelete( @Args('id') id: string, - @Args('parentBlockId') parentBlockId: string, - @Args('journeyId') journeyId: string + @Args('journeyId') journeyId: string, + @Args('parentBlockId') parentBlockId?: string ): Promise { return await this.blockService.removeBlockAndChildren( id, - parentBlockId, - journeyId + journeyId, + parentBlockId ) } diff --git a/apps/api-journeys/src/app/modules/block/block.service.spec.ts b/apps/api-journeys/src/app/modules/block/block.service.spec.ts index 95b8c0ac9d9..99fce3b138e 100644 --- a/apps/api-journeys/src/app/modules/block/block.service.spec.ts +++ b/apps/api-journeys/src/app/modules/block/block.service.spec.ts @@ -221,8 +221,8 @@ describe('BlockService', () => { expect( await service.removeBlockAndChildren( block._key, - block.parentBlockId, - journey.id + journey.id, + block.parentBlockId ) ).toEqual([ { _key: block._key, parentOrder: 0 }, @@ -234,6 +234,13 @@ describe('BlockService', () => { ) }) + it('should remove blocks and return empty array', async () => { + expect( + await service.removeBlockAndChildren(block._key, journey.id) + ).toEqual([]) + expect(service.updateChildrenParentOrder).not.toHaveBeenCalled() + }) + it('should update parent order', async () => { ;( service.collection as DeepMockProxy diff --git a/apps/api-journeys/src/app/modules/block/block.service.ts b/apps/api-journeys/src/app/modules/block/block.service.ts index fab841470fd..b301851b986 100644 --- a/apps/api-journeys/src/app/modules/block/block.service.ts +++ b/apps/api-journeys/src/app/modules/block/block.service.ts @@ -84,15 +84,15 @@ export class BlockService extends BaseService { async removeBlockAndChildren( blockId: string, - parentBlockId: string, - journeyId: string + journeyId: string, + parentBlockId?: string ): Promise { const res: Block = await this.remove(blockId) await this.removeAllBlocksForParentId([blockId], [res]) - const result = await this.updateChildrenParentOrder( - journeyId, - parentBlockId - ) + const result = + parentBlockId == null + ? [] + : await this.updateChildrenParentOrder(journeyId, parentBlockId) return result as unknown as Block[] }