33 lines
695 B
JavaScript
33 lines
695 B
JavaScript
const expres = require('express');
|
|
const bodyParser = require('body-parser');
|
|
const axios = require('axios');
|
|
|
|
|
|
const app = expres();
|
|
app.use(bodyParser.json());
|
|
|
|
app.post('/events', async (req, res) => {
|
|
const { type, data } = req.body;
|
|
|
|
if(type === 'CommentCreated') {
|
|
const status = data.content.includes('orange') ? 'rejected' : 'approved';
|
|
await axios.post('http://localhost:4005/events', {
|
|
type: 'CommentModerated',
|
|
data: {
|
|
id: data.id,
|
|
postId: data.postId,
|
|
status,
|
|
content: data.content
|
|
}
|
|
}).catch(error => console.log(error));
|
|
}
|
|
|
|
res.send({});
|
|
});
|
|
|
|
|
|
app.listen(4003, () => {
|
|
console.log('Listening on 4003');
|
|
});
|
|
|