Skip to content

Commit

Permalink
Refactor hard-coded event types into enums
Browse files Browse the repository at this point in the history
  • Loading branch information
joonashak committed Aug 8, 2023
1 parent aa222fb commit ed5d0c2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions app-nest/src/bolt/enums/bolt-actions.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enum BoltActions {
SYNC_USERS = "sync_users",
}

export default BoltActions;
6 changes: 6 additions & 0 deletions app-nest/src/bolt/enums/bolt-events.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
enum BoltEvents {
APP_HOME_OPENED = "app_home_opened",
USER_PROFILE_CHANGED = "user_profile_changed",
}

export default BoltEvents;
3 changes: 2 additions & 1 deletion app-nest/src/dev-tools/dev-tools.controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Controller } from "@nestjs/common";
import BoltAction from "../bolt/decorators/bolt-action.decorator";
import BoltActions from "../bolt/enums/bolt-actions.enum";
import { UserSyncService } from "../sync/user-sync.service";

@Controller()
export class DevToolsController {
constructor(private userSyncService: UserSyncService) {}

@BoltAction("sync_users")
@BoltAction(BoltActions.SYNC_USERS)
async syncUsers({ ack }) {
await ack();
await this.userSyncService.syncUsers();
Expand Down
3 changes: 2 additions & 1 deletion app-nest/src/gui/tabs/home-tab.controller.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Controller } from "@nestjs/common";
import BoltEvent from "../../bolt/decorators/bolt-event.decorator";
import BoltEvents from "../../bolt/enums/bolt-events.enum";
import { UserService } from "../../entities/user/user.service";
import devTools from "../dev/dev-tools";

@Controller()
export class HomeTabController {
constructor(private userService: UserService) {}

@BoltEvent("app_home_opened")
@BoltEvent(BoltEvents.APP_HOME_OPENED)
async getView({ event, client, logger }) {
const users = await this.userService.findAll();
const { slackId } = users[0];
Expand Down
3 changes: 2 additions & 1 deletion app-nest/src/sync/sync.controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Controller } from "@nestjs/common";
import BoltEvent from "../bolt/decorators/bolt-event.decorator";
import BoltEvents from "../bolt/enums/bolt-events.enum";
import { UserSyncService } from "./user-sync.service";

@Controller()
export class SyncController {
constructor(private userSyncService: UserSyncService) {}

@BoltEvent("user_profile_changed")
@BoltEvent(BoltEvents.USER_PROFILE_CHANGED)
async userProfileChanged({ event }) {
await this.userSyncService.syncUsers(event.user);
}
Expand Down

0 comments on commit ed5d0c2

Please sign in to comment.