Created
December 9, 2020 19:36
-
-
Save urbanisierung/6d0f895a7ce0a8c8b28d908f19217c5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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