diff --git a/services/apps/alcs/src/alcs/admin/card-status/card-status.controller.spec.ts b/services/apps/alcs/src/alcs/admin/card-status/card-status.controller.spec.ts index ff9a9ce666..db82fb0db3 100644 --- a/services/apps/alcs/src/alcs/admin/card-status/card-status.controller.spec.ts +++ b/services/apps/alcs/src/alcs/admin/card-status/card-status.controller.spec.ts @@ -123,12 +123,14 @@ describe('CardStatusController', () => { expect(mockBoardService.getBoardsWithStatus).toHaveBeenCalledTimes(1); }); - it('should call the service for delete', async () => { + it('should unlink statuses and then call the service for delete', async () => { mockCardStatusService.delete.mockResolvedValue({} as any); + mockBoardService.unlinkStatus.mockResolvedValue(); const res = await controller.delete('FAKE-CODE'); expect(res).toBeDefined(); expect(mockCardStatusService.delete).toHaveBeenCalledTimes(1); + expect(mockBoardService.unlinkStatus).toHaveBeenCalledTimes(1); }); }); diff --git a/services/apps/alcs/src/alcs/admin/card-status/card-status.controller.ts b/services/apps/alcs/src/alcs/admin/card-status/card-status.controller.ts index ec87e8f11b..a279bb4cd1 100644 --- a/services/apps/alcs/src/alcs/admin/card-status/card-status.controller.ts +++ b/services/apps/alcs/src/alcs/admin/card-status/card-status.controller.ts @@ -85,6 +85,8 @@ export class CardStatusController { @Delete('/:code') @UserRoles(AUTH_ROLE.ADMIN) async delete(@Param('code') code: string) { + //Delete from boards first + await this.boardService.unlinkStatus(code); return await this.cardStatusService.delete(code); } diff --git a/services/apps/alcs/src/alcs/board/board.service.spec.ts b/services/apps/alcs/src/alcs/board/board.service.spec.ts index a1f1baba87..95c34efe0d 100644 --- a/services/apps/alcs/src/alcs/board/board.service.spec.ts +++ b/services/apps/alcs/src/alcs/board/board.service.spec.ts @@ -7,7 +7,6 @@ import { ApplicationService } from '../application/application.service'; import { Card } from '../card/card.entity'; import { CardService } from '../card/card.service'; import { BoardStatus } from './board-status.entity'; -import { BoardStatusDto } from './board.dto'; import { Board } from './board.entity'; import { BoardService } from './board.service'; @@ -114,4 +113,12 @@ describe('BoardsService', () => { new ServiceNotFoundException(`Failed to find Board with code board-code`), ); }); + + it('should call through for unlink status', async () => { + mockBoardStatusRepository.delete.mockResolvedValue({} as any); + + await service.unlinkStatus('code'); + + expect(mockBoardStatusRepository.delete).toHaveBeenCalledTimes(1); + }); }); diff --git a/services/apps/alcs/src/alcs/board/board.service.ts b/services/apps/alcs/src/alcs/board/board.service.ts index 1640907d6d..c377853774 100644 --- a/services/apps/alcs/src/alcs/board/board.service.ts +++ b/services/apps/alcs/src/alcs/board/board.service.ts @@ -87,6 +87,14 @@ export class BoardService { }); } + async unlinkStatus(code: string) { + await this.boardStatusRepository.delete({ + status: { + code, + }, + }); + } + async delete(code: string) { const board = await this.getOneOrFail({ code,