Skip to content

Commit

Permalink
Remove presence through UI
Browse files Browse the repository at this point in the history
  • Loading branch information
joonashak committed Aug 9, 2023
1 parent e1898b0 commit d731d42
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions app-nest/src/bolt/enums/bolt-actions.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
18 changes: 17 additions & 1 deletion app-nest/src/entities/presence/presence.controller.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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(),
});
}
}
4 changes: 4 additions & 0 deletions app-nest/src/entities/presence/presence.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ export class PresenceService {
.orUpdate(updatableCols, primaryKeys)
.execute();
}

async remove(presence: Pick<Presence, "userId" | "date">) {
return this.presenceRepository.delete(presence);
}
}
7 changes: 5 additions & 2 deletions app-nest/src/gui/tabs/home/day-list-item.blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
],
},
Expand Down

0 comments on commit d731d42

Please sign in to comment.