Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@urbanisierung
Created December 9, 2020 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save urbanisierung/6d0f895a7ce0a8c8b28d908f19217c5f to your computer and use it in GitHub Desktop.
Save urbanisierung/6d0f895a7ce0a8c8b28d908f19217c5f to your computer and use it in GitHub Desktop.
const express = require('express')
import { NextFunction, Request, Response } from 'express'
import { StorageController } from '../../controller/storage.controller'
import { ZeebeController } from '../../controller/zeebe.controller'
import { TrelloBoardType } from '../../types/TrelloBoard.type'
import { Error, ErrorType } from '../../utils/Error'
export class TrelloWebhookRouter {
public router = express.Router({ mergeParams: true })
constructor(store: StorageController) {
this.router.post(
'/',
async (req: Request, res: Response, next: NextFunction) => {
const payload: TrelloBoardType = req.body as TrelloBoardType
try {
if (
payload &&
payload.action &&
payload.action.type === 'updateCard' &&
payload.action.data.listAfter.name === 'Done'
) {
const id = payload.action.data.card.id
const zeebeController = new ZeebeController()
await zeebeController.publishMessage(id, 'Card done')
}
res.send()
} catch (error) {
throw new Error(ErrorType.Internal)
}
},
)
this.router.get(
'/',
async (req: Request, res: Response, next: NextFunction) => {
res.send()
},
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment