diff --git a/app/jest.config.ts b/app/jest.config.ts index fb8b718..30b8e66 100644 --- a/app/jest.config.ts +++ b/app/jest.config.ts @@ -15,6 +15,7 @@ const config: Config = { ".module.ts$", ".model.ts$", ".dto.ts$", + ".type.ts$", "src/database/migrations", "src/database/migration-config.ts", "src/main.ts", diff --git a/app/src/bolt/decorators/bolt-action.decorator.spec.ts b/app/src/bolt/decorators/bolt-action.decorator.spec.ts index 87d5d30..84e7798 100644 --- a/app/src/bolt/decorators/bolt-action.decorator.spec.ts +++ b/app/src/bolt/decorators/bolt-action.decorator.spec.ts @@ -1,20 +1,20 @@ -import BoltActions from "../enums/bolt-actions.enum"; +import Action from "../enums/action.enum"; import BoltAction, { BOLT_ACTION_KEY } from "./bolt-action.decorator"; describe("@BoltAction", () => { class TestController { - @BoltAction(BoltActions.SYNC_USERS) + @BoltAction(Action.SYNC_USERS) public static syncUsers() {} - @BoltAction(BoltActions.SET_OFFICE_PRESENCE) + @BoltAction(Action.SET_OFFICE_PRESENCE) public static setOfficePresence() {} } it("Assigns correct metadata to decorated class", () => { const metaValueForSync = Reflect.getMetadata(BOLT_ACTION_KEY, TestController.syncUsers); - expect(metaValueForSync).toEqual(BoltActions.SYNC_USERS); + expect(metaValueForSync).toEqual(Action.SYNC_USERS); const metaValueForSet = Reflect.getMetadata(BOLT_ACTION_KEY, TestController.setOfficePresence); - expect(metaValueForSet).toEqual(BoltActions.SET_OFFICE_PRESENCE); + expect(metaValueForSet).toEqual(Action.SET_OFFICE_PRESENCE); }); }); diff --git a/app/src/bolt/decorators/bolt-action.decorator.ts b/app/src/bolt/decorators/bolt-action.decorator.ts index a7d769c..de948ff 100644 --- a/app/src/bolt/decorators/bolt-action.decorator.ts +++ b/app/src/bolt/decorators/bolt-action.decorator.ts @@ -1,8 +1,8 @@ import { SetMetadata } from "@nestjs/common"; -import BoltActions from "../enums/bolt-actions.enum"; +import Action from "../enums/action.enum"; export const BOLT_ACTION_KEY = "BoltAction"; -const BoltAction = (actionName: BoltActions) => SetMetadata(BOLT_ACTION_KEY, actionName); +const BoltAction = (actionName: Action) => SetMetadata(BOLT_ACTION_KEY, actionName); export default BoltAction; diff --git a/app/src/bolt/decorators/bolt-event.decorator.spec.ts b/app/src/bolt/decorators/bolt-event.decorator.spec.ts index 267a775..6f057ae 100644 --- a/app/src/bolt/decorators/bolt-event.decorator.spec.ts +++ b/app/src/bolt/decorators/bolt-event.decorator.spec.ts @@ -1,20 +1,20 @@ -import BoltEvents from "../enums/bolt-events.enum"; +import Event from "../enums/event.enum"; import BoltEvent, { BOLT_EVENT_KEY } from "./bolt-event.decorator"; describe("@BoltEvent", () => { class TestController { - @BoltEvent(BoltEvents.APP_HOME_OPENED) + @BoltEvent(Event.APP_HOME_OPENED) public static appHomeOpened() {} - @BoltEvent(BoltEvents.USER_PROFILE_CHANGED) + @BoltEvent(Event.USER_PROFILE_CHANGED) public static userProfileChanged() {} } it("Assigns correct metadata to decorated class", () => { const metaValueForSync = Reflect.getMetadata(BOLT_EVENT_KEY, TestController.appHomeOpened); - expect(metaValueForSync).toEqual(BoltEvents.APP_HOME_OPENED); + expect(metaValueForSync).toEqual(Event.APP_HOME_OPENED); const metaValueForSet = Reflect.getMetadata(BOLT_EVENT_KEY, TestController.userProfileChanged); - expect(metaValueForSet).toEqual(BoltEvents.USER_PROFILE_CHANGED); + expect(metaValueForSet).toEqual(Event.USER_PROFILE_CHANGED); }); }); diff --git a/app/src/bolt/decorators/bolt-event.decorator.ts b/app/src/bolt/decorators/bolt-event.decorator.ts index 2c969d6..8aa32ec 100644 --- a/app/src/bolt/decorators/bolt-event.decorator.ts +++ b/app/src/bolt/decorators/bolt-event.decorator.ts @@ -1,8 +1,8 @@ import { SetMetadata } from "@nestjs/common"; -import BoltEvents from "../enums/bolt-events.enum"; +import Event from "../enums/event.enum"; export const BOLT_EVENT_KEY = "BoltEvent"; -const BoltEvent = (eventName: BoltEvents) => SetMetadata(BOLT_EVENT_KEY, eventName); +const BoltEvent = (eventName: Event) => SetMetadata(BOLT_EVENT_KEY, eventName); export default BoltEvent; diff --git a/app/src/bolt/enums/bolt-actions.enum.ts b/app/src/bolt/enums/action.enum.ts similarity index 85% rename from app/src/bolt/enums/bolt-actions.enum.ts rename to app/src/bolt/enums/action.enum.ts index 4727085..3144535 100644 --- a/app/src/bolt/enums/bolt-actions.enum.ts +++ b/app/src/bolt/enums/action.enum.ts @@ -1,4 +1,4 @@ -enum BoltActions { +enum Action { SYNC_USERS = "sync_users", SET_OFFICE_PRESENCE = "set_office_presence", SET_REMOTE_PRESENCE = "set_remote_presence", @@ -7,4 +7,4 @@ enum BoltActions { SET_VISIBLE_OFFICE = "set_visible_office", } -export default BoltActions; +export default Action; diff --git a/app/src/bolt/enums/bolt-events.enum.ts b/app/src/bolt/enums/event.enum.ts similarity index 66% rename from app/src/bolt/enums/bolt-events.enum.ts rename to app/src/bolt/enums/event.enum.ts index 61470d6..6c85f24 100644 --- a/app/src/bolt/enums/bolt-events.enum.ts +++ b/app/src/bolt/enums/event.enum.ts @@ -1,6 +1,6 @@ -enum BoltEvents { +enum Event { APP_HOME_OPENED = "app_home_opened", USER_PROFILE_CHANGED = "user_profile_changed", } -export default BoltEvents; +export default Event; diff --git a/app/src/bolt/types/app-home-opened.type.ts b/app/src/bolt/types/app-home-opened.type.ts new file mode 100644 index 0000000..2993ed3 --- /dev/null +++ b/app/src/bolt/types/app-home-opened.type.ts @@ -0,0 +1,5 @@ +import { AllMiddlewareArgs, AppHomeOpenedEvent, SlackEventMiddlewareArgs } from "@slack/bolt"; +import { StringIndexed } from "@slack/bolt/dist/types/helpers"; + +export type AppHomeOpenedArgs = SlackEventMiddlewareArgs & + AllMiddlewareArgs; diff --git a/app/src/bolt/types/bolt-action-types.ts b/app/src/bolt/types/bolt-action-args.type.ts similarity index 100% rename from app/src/bolt/types/bolt-action-types.ts rename to app/src/bolt/types/bolt-action-args.type.ts diff --git a/app/src/bolt/types/bolt-event-types.ts b/app/src/bolt/types/bolt-event-types.ts deleted file mode 100644 index 9184554..0000000 --- a/app/src/bolt/types/bolt-event-types.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { - AllMiddlewareArgs, - AppHomeOpenedEvent, - SlackEventMiddlewareArgs, - UserProfileChangedEvent, -} from "@slack/bolt"; -import { StringIndexed } from "@slack/bolt/dist/types/helpers"; - -export type AppHomeOpenedArgs = SlackEventMiddlewareArgs & - AllMiddlewareArgs; - -export type UserProfileChangedArgs = SlackEventMiddlewareArgs & - AllMiddlewareArgs; diff --git a/app/src/bolt/types/user-profile-changed.type.ts b/app/src/bolt/types/user-profile-changed.type.ts new file mode 100644 index 0000000..31f1fe8 --- /dev/null +++ b/app/src/bolt/types/user-profile-changed.type.ts @@ -0,0 +1,5 @@ +import { AllMiddlewareArgs, SlackEventMiddlewareArgs, UserProfileChangedEvent } from "@slack/bolt"; +import { StringIndexed } from "@slack/bolt/dist/types/helpers"; + +export type UserProfileChangedArgs = SlackEventMiddlewareArgs & + AllMiddlewareArgs; diff --git a/app/src/dev-tools/dev-tools.controller.ts b/app/src/dev-tools/dev-tools.controller.ts index 5d8ecb5..e3e39f9 100644 --- a/app/src/dev-tools/dev-tools.controller.ts +++ b/app/src/dev-tools/dev-tools.controller.ts @@ -1,14 +1,14 @@ import { Controller } from "@nestjs/common"; import BoltAction from "../bolt/decorators/bolt-action.decorator"; -import BoltActions from "../bolt/enums/bolt-actions.enum"; -import { BoltActionArgs } from "../bolt/types/bolt-action-types"; +import Action from "../bolt/enums/action.enum"; +import { BoltActionArgs } from "../bolt/types/bolt-action-args.type"; import { UserSyncService } from "../sync/user-sync.service"; @Controller() export class DevToolsController { constructor(private userSyncService: UserSyncService) {} - @BoltAction(BoltActions.SYNC_USERS) + @BoltAction(Action.SYNC_USERS) async syncUsers({ ack }: BoltActionArgs) { await ack(); await this.userSyncService.syncUsers(); diff --git a/app/src/entities/presence/presence.controller.ts b/app/src/entities/presence/presence.controller.ts index a4bd40b..13cee91 100644 --- a/app/src/entities/presence/presence.controller.ts +++ b/app/src/entities/presence/presence.controller.ts @@ -1,8 +1,8 @@ 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"; -import { BoltActionArgs } from "../../bolt/types/bolt-action-types"; +import Action from "../../bolt/enums/action.enum"; +import { BoltActionArgs } from "../../bolt/types/bolt-action-args.type"; import { PresenceType } from "./presence.model"; import { PresenceService } from "./presence.service"; @@ -10,7 +10,7 @@ import { PresenceService } from "./presence.service"; export class PresenceController { constructor(private presenceService: PresenceService) {} - @BoltAction(BoltActions.SET_OFFICE_PRESENCE) + @BoltAction(Action.SET_OFFICE_PRESENCE) async setOfficePresence({ ack, body, payload }: BoltActionArgs) { await ack(); const date = dayjs(payload["value"]).toDate(); @@ -21,7 +21,7 @@ export class PresenceController { }); } - @BoltAction(BoltActions.SET_REMOTE_PRESENCE) + @BoltAction(Action.SET_REMOTE_PRESENCE) async setRemotePresence({ ack, body, payload }: BoltActionArgs) { await ack(); const date = dayjs(payload["value"]).toDate(); @@ -32,7 +32,7 @@ export class PresenceController { }); } - @BoltAction(BoltActions.SELECT_OFFICE_FOR_DATE) + @BoltAction(Action.SELECT_OFFICE_FOR_DATE) async selectOfficeForDate({ ack, body, payload }: BoltActionArgs) { await ack(); const { value, date } = JSON.parse(payload["selected_option"].value); @@ -44,7 +44,7 @@ export class PresenceController { } // TODO: Should this be moved? - @BoltAction(BoltActions.DAY_LIST_ITEM_OVERFLOW) + @BoltAction(Action.DAY_LIST_ITEM_OVERFLOW) async dayListItemOverflow({ ack, body, payload }: BoltActionArgs) { await ack(); const { type, date } = JSON.parse(payload["selected_option"].value); diff --git a/app/src/entities/user-settings/user-settings.controller.ts b/app/src/entities/user-settings/user-settings.controller.ts index c774675..79cd655 100644 --- a/app/src/entities/user-settings/user-settings.controller.ts +++ b/app/src/entities/user-settings/user-settings.controller.ts @@ -1,14 +1,14 @@ import { Controller } from "@nestjs/common"; import BoltAction from "../../bolt/decorators/bolt-action.decorator"; -import BoltActions from "../../bolt/enums/bolt-actions.enum"; -import { BoltActionArgs } from "../../bolt/types/bolt-action-types"; +import Action from "../../bolt/enums/action.enum"; +import { BoltActionArgs } from "../../bolt/types/bolt-action-args.type"; import { UserSettingsService } from "./user-settings.service"; @Controller() export class UserSettingsController { constructor(private userSettingsService: UserSettingsService) {} - @BoltAction(BoltActions.SET_VISIBLE_OFFICE) + @BoltAction(Action.SET_VISIBLE_OFFICE) // eslint-disable-next-line @typescript-eslint/no-unused-vars async setVisibleOffice({ ack, payload, body }: BoltActionArgs) { await ack(); diff --git a/app/src/gui/dev/dev-ui.builder.ts b/app/src/gui/dev/dev-ui.builder.ts index 16cf917..981e56f 100644 --- a/app/src/gui/dev/dev-ui.builder.ts +++ b/app/src/gui/dev/dev-ui.builder.ts @@ -1,6 +1,6 @@ import { Injectable } from "@nestjs/common"; import { Actions, Button, Context, Divider, Header, ViewBlockBuilder } from "slack-block-builder"; -import BoltActions from "../../bolt/enums/bolt-actions.enum"; +import Action from "../../bolt/enums/action.enum"; import { BlockBuilder } from "../block-builder.interface"; @Injectable() @@ -11,7 +11,7 @@ export class DevUiBuilder implements BlockBuilder { Actions().elements( Button({ text: ":recycle: Sync Users", - actionId: BoltActions.SYNC_USERS, + actionId: Action.SYNC_USERS, }), ), Context().elements( diff --git a/app/src/gui/tabs/home/day-list-item.builder.ts b/app/src/gui/tabs/home/day-list-item.builder.ts index 8f7dd43..d128761 100644 --- a/app/src/gui/tabs/home/day-list-item.builder.ts +++ b/app/src/gui/tabs/home/day-list-item.builder.ts @@ -9,7 +9,7 @@ import { StaticSelect, ViewBlockBuilder, } from "slack-block-builder"; -import BoltActions from "../../../bolt/enums/bolt-actions.enum"; +import Action from "../../../bolt/enums/action.enum"; import { Office } from "../../../entities/office/office.model"; import { BlockBuilder } from "../../block-builder.interface"; @@ -29,16 +29,16 @@ export class DayListItemBuilder implements BlockBuilder { Actions().elements( Button({ text: "Toimistolla", - actionId: BoltActions.SET_OFFICE_PRESENCE, + actionId: Action.SET_OFFICE_PRESENCE, value: dateString, }), Button({ text: "Etänä", - actionId: BoltActions.SET_REMOTE_PRESENCE, + actionId: Action.SET_REMOTE_PRESENCE, value: dateString, }), this.getOfficeBlocks(props), - OverflowMenu({ actionId: BoltActions.DAY_LIST_ITEM_OVERFLOW }).options( + OverflowMenu({ actionId: Action.DAY_LIST_ITEM_OVERFLOW }).options( Option({ text: "Poista ilmoittautuminen", value: JSON.stringify({ @@ -66,7 +66,7 @@ export class DayListItemBuilder implements BlockBuilder { return StaticSelect({ placeholder: "Valitse toimipiste", - actionId: BoltActions.SELECT_OFFICE_FOR_DATE, + actionId: Action.SELECT_OFFICE_FOR_DATE, }) .initialOption(Options[0]) .options(Options); diff --git a/app/src/gui/tabs/home/home-tab.controller.ts b/app/src/gui/tabs/home/home-tab.controller.ts index cfc451a..09816d6 100644 --- a/app/src/gui/tabs/home/home-tab.controller.ts +++ b/app/src/gui/tabs/home/home-tab.controller.ts @@ -1,15 +1,15 @@ import { Controller } from "@nestjs/common"; import { HomeTab } from "slack-block-builder"; import BoltEvent from "../../../bolt/decorators/bolt-event.decorator"; -import BoltEvents from "../../../bolt/enums/bolt-events.enum"; -import { AppHomeOpenedArgs } from "../../../bolt/types/bolt-event-types"; +import Event from "../../../bolt/enums/event.enum"; +import { AppHomeOpenedArgs } from "../../../bolt/types/app-home-opened.type"; import { HomeTabBuilder } from "./home-tab.builder"; @Controller() export class HomeTabController { constructor(private homeTabBlocks: HomeTabBuilder) {} - @BoltEvent(BoltEvents.APP_HOME_OPENED) + @BoltEvent(Event.APP_HOME_OPENED) async getView({ event, client, logger }: AppHomeOpenedArgs) { const blocks = await this.homeTabBlocks.build(); const view = HomeTab() diff --git a/app/src/gui/tabs/home/visible-office-select.builder.ts b/app/src/gui/tabs/home/visible-office-select.builder.ts index 9cf5a6c..7cedac9 100644 --- a/app/src/gui/tabs/home/visible-office-select.builder.ts +++ b/app/src/gui/tabs/home/visible-office-select.builder.ts @@ -1,6 +1,6 @@ import { Injectable } from "@nestjs/common"; import { Option, Section, StaticSelect, ViewBlockBuilder } from "slack-block-builder"; -import BoltActions from "../../../bolt/enums/bolt-actions.enum"; +import Action from "../../../bolt/enums/action.enum"; import { OfficeService } from "../../../entities/office/office.service"; import { BlockBuilder } from "../../block-builder.interface"; @@ -29,7 +29,7 @@ export class VisibleOfficeSelectBuilder implements BlockBuilder