Skip to content

Commit

Permalink
Sort columns and implement column delete
Browse files Browse the repository at this point in the history
* Sort columns while mapping them
* Hook up delete button and add to controller
  • Loading branch information
Daniel Haselhan committed Aug 4, 2023
1 parent 4fbf260 commit b80e09f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h4>{{ isEdit ? 'Edit' : 'Create' }} Column</h4>

<div class="split">
<div [matTooltip]="canDeleteReason" [matTooltipDisabled]="canDelete">
<button [disabled]="!canDelete" mat-stroked-button color="warn" mat-dialog-close="false">Delete</button>
<button [disabled]="!canDelete" (click)='onDelete()' mat-stroked-button color="warn">Delete</button>
</div>
<div class="button-container">
<button mat-stroked-button color="primary" mat-dialog-close="false">Close</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ export class CardStatusDialogComponent implements OnInit {
this.canDeleteReason = res.reason;
}
}

async onDelete() {
await this.cardStatusService.delete(this.code);
this.dialogRef.close(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,13 @@ describe('CardStatusController', () => {
expect(res.canDelete).toBeTruthy();
expect(mockBoardService.getBoardsWithStatus).toHaveBeenCalledTimes(1);
});

it('should call the service for delete', async () => {
mockCardStatusService.delete.mockResolvedValue({} as any);

const res = await controller.delete('FAKE-CODE');

expect(res).toBeDefined();
expect(mockCardStatusService.delete).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Body,
Controller,
Delete,
Get,
Param,
Patch,
Expand Down Expand Up @@ -81,6 +82,12 @@ export class CardStatusController {
return await this.cardStatusService.update(code, updateDto);
}

@Delete('/:code')
@UserRoles(AUTH_ROLE.ADMIN)
async delete(@Param('code') code: string) {
return await this.cardStatusService.delete(code);
}

@Post('')
@UserRoles(AUTH_ROLE.ADMIN)
async create(@Body() createDto: CardStatusDto) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,10 @@ export class CardStatusService {
const cards = await this.cardService.getByCardStatus(code);
return cards.length;
}

async delete(code: string) {
const cardStatus = await this.getOneOrFail(code);

return await this.cardStatusRepository.remove(cardStatus);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export class BoardAutomapperProfile extends AutomapperProfile {
forMember(
(ad) => ad.statuses,
mapFrom((a) =>
this.mapper.mapArray(a.statuses, BoardStatus, BoardStatusDto),
this.mapper
.mapArray(a.statuses, BoardStatus, BoardStatusDto)
.sort((a1, b) => a1.order - b.order),
),
),
forMember(
Expand Down

0 comments on commit b80e09f

Please sign in to comment.