diff --git a/app-nest/src/bolt/enums/bolt-actions.enum.ts b/app-nest/src/bolt/enums/bolt-actions.enum.ts index dca1ab2..e80493e 100644 --- a/app-nest/src/bolt/enums/bolt-actions.enum.ts +++ b/app-nest/src/bolt/enums/bolt-actions.enum.ts @@ -3,6 +3,7 @@ enum BoltActions { SET_OFFICE_PRESENCE = "set_office_presence", SET_REMOTE_PRESENCE = "set_remote_presence", SELECT_OFFICE_FOR_DATE = "select_office_for_date", + DAY_LIST_ITEM_OVERFLOW = "day_list_item_overflow", } export default BoltActions; diff --git a/app-nest/src/entities/presence/presence.controller.ts b/app-nest/src/entities/presence/presence.controller.ts index 03f4b45..af5ea21 100644 --- a/app-nest/src/entities/presence/presence.controller.ts +++ b/app-nest/src/entities/presence/presence.controller.ts @@ -1,4 +1,4 @@ -import { Controller } from "@nestjs/common"; +import { Controller, InternalServerErrorException } from "@nestjs/common"; import dayjs from "dayjs"; import BoltAction from "../../bolt/decorators/bolt-action.decorator"; import BoltActions from "../../bolt/enums/bolt-actions.enum"; @@ -42,4 +42,20 @@ export class PresenceController { office: value, }); } + + // TODO: Should this be moved? + @BoltAction(BoltActions.DAY_LIST_ITEM_OVERFLOW) + async dayListItemOverflow({ ack, body, payload }: BoltActionArgs) { + await ack(); + const { type, date } = JSON.parse(payload["selected_option"].value); + + if (type !== "remove_presence") { + throw new InternalServerErrorException("Not implemented."); + } + + await this.presenceService.remove({ + userId: body.user.id, + date: dayjs(date).toDate(), + }); + } } diff --git a/app-nest/src/entities/presence/presence.service.ts b/app-nest/src/entities/presence/presence.service.ts index 6c3ae5c..2a9bd92 100644 --- a/app-nest/src/entities/presence/presence.service.ts +++ b/app-nest/src/entities/presence/presence.service.ts @@ -26,4 +26,8 @@ export class PresenceService { .orUpdate(updatableCols, primaryKeys) .execute(); } + + async remove(presence: Pick) { + return this.presenceRepository.delete(presence); + } } diff --git a/app-nest/src/gui/tabs/home/day-list-item.blocks.ts b/app-nest/src/gui/tabs/home/day-list-item.blocks.ts index a13df3a..c8d5fc4 100644 --- a/app-nest/src/gui/tabs/home/day-list-item.blocks.ts +++ b/app-nest/src/gui/tabs/home/day-list-item.blocks.ts @@ -74,10 +74,13 @@ const getDayListItemBlocks = ({ date }: DayListItemProps) => [ type: "plain_text", text: "Poista ilmoittautuminen", }, - value: "value-0", + value: JSON.stringify({ + type: "remove_presence", + date: date.toISOString(), + }), }, ], - action_id: "overflow", + action_id: BoltActions.DAY_LIST_ITEM_OVERFLOW, }, ], },