Skip to content
Merged
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 apps/api-gateway/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion apps/api-journeys/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/api-journeys/src/app/__generated__/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/api-journeys/src/app/modules/block/block.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!]!
}
Original file line number Diff line number Diff line change
Expand Up @@ -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])
})
Expand Down
8 changes: 4 additions & 4 deletions apps/api-journeys/src/app/modules/block/block.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Block[]> {
return await this.blockService.removeBlockAndChildren(
id,
parentBlockId,
journeyId
journeyId,
parentBlockId
)
}

Expand Down
11 changes: 9 additions & 2 deletions apps/api-journeys/src/app/modules/block/block.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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<DocumentCollection>
Expand Down
12 changes: 6 additions & 6 deletions apps/api-journeys/src/app/modules/block/block.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ export class BlockService extends BaseService {

async removeBlockAndChildren(
blockId: string,
parentBlockId: string,
journeyId: string
journeyId: string,
parentBlockId?: string
): Promise<Block[]> {
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[]
}

Expand Down