Skip to content

Commit

Permalink
Type handler function args
Browse files Browse the repository at this point in the history
  • Loading branch information
joonashak committed Aug 8, 2023
1 parent ed5d0c2 commit 29a82f9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
9 changes: 9 additions & 0 deletions app-nest/src/bolt/types/bolt-action-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {
AllMiddlewareArgs,
SlackAction,
SlackActionMiddlewareArgs,
} from "@slack/bolt";
import { StringIndexed } from "@slack/bolt/dist/types/helpers";

export type BoltActionArgs = SlackActionMiddlewareArgs<SlackAction> &
AllMiddlewareArgs<StringIndexed>;
17 changes: 17 additions & 0 deletions app-nest/src/bolt/types/bolt-event-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
AllMiddlewareArgs,
AppHomeOpenedEvent,
SlackEventMiddlewareArgs,
UserProfileChangedEvent,
} from "@slack/bolt";
import { StringIndexed } from "@slack/bolt/dist/types/helpers";

export type AppHomeOpenedArgs = SlackEventMiddlewareArgs<
AppHomeOpenedEvent["type"]
> &
AllMiddlewareArgs<StringIndexed>;

export type UserProfileChangedArgs = SlackEventMiddlewareArgs<
UserProfileChangedEvent["type"]
> &
AllMiddlewareArgs<StringIndexed>;
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,14 +1,15 @@
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 { UserSyncService } from "../sync/user-sync.service";

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

@BoltAction(BoltActions.SYNC_USERS)
async syncUsers({ ack }) {
async syncUsers({ ack }: BoltActionArgs) {
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,6 +1,7 @@
import { Controller } from "@nestjs/common";
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 { UserService } from "../../entities/user/user.service";
import devTools from "../dev/dev-tools";

Expand All @@ -9,7 +10,7 @@ export class HomeTabController {
constructor(private userService: UserService) {}

@BoltEvent(BoltEvents.APP_HOME_OPENED)
async getView({ event, client, logger }) {
async getView({ event, client, logger }: AppHomeOpenedArgs) {
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,14 +1,15 @@
import { Controller } from "@nestjs/common";
import BoltEvent from "../bolt/decorators/bolt-event.decorator";
import BoltEvents from "../bolt/enums/bolt-events.enum";
import { UserProfileChangedArgs } from "../bolt/types/bolt-event-types";
import { UserSyncService } from "./user-sync.service";

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

@BoltEvent(BoltEvents.USER_PROFILE_CHANGED)
async userProfileChanged({ event }) {
async userProfileChanged({ event }: UserProfileChangedArgs) {
await this.userSyncService.syncUsers(event.user);
}
}

0 comments on commit 29a82f9

Please sign in to comment.