Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit e85d2d3

Browse files
author
sachin-maheshwari
authored
Merge pull request #100 from yoution/feature/CQRS-Standards
feat: add user added topic
2 parents 7efafae + 34b6cbd commit e85d2d3

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

config/default.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ module.exports = {
3535
KAFKA_MESSAGE_ORIGINATOR: process.env.KAFKA_MESSAGE_ORIGINATOR || 'u-bahn-api',
3636

3737
// topics
38+
UBAHN_CREATE_USER_TOPIC: process.env.UBAHN_CREATE_USER_TOPIC || 'user.action.topic.create',
39+
UBAHN_UPDATE_USER_TOPIC: process.env.UBAHN_UPDATE_USER_TOPIC || 'user.action.topic.update',
40+
UBAHN_DELETE_USER_TOPIC: process.env.UBAHN_DELETE_USER_TOPIC || 'user.action.topic.delete',
3841
UBAHN_CREATE_TOPIC: process.env.UBAHN_CREATE_TOPIC || 'u-bahn.action.create',
3942
UBAHN_UPDATE_TOPIC: process.env.UBAHN_UPDATE_TOPIC || 'u-bahn.action.update',
4043
UBAHN_DELETE_TOPIC: process.env.UBAHN_DELETE_TOPIC || 'u-bahn.action.delete',

docker-pgsql-es/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ services:
44
image: "postgres:12.4"
55
volumes:
66
- database-data:/var/lib/postgresql/data/
7-
ports:
7+
ports:
88
- "5432:5432"
99
environment:
1010
POSTGRES_PASSWORD: ${DB_PASSWORD}
1111
POSTGRES_USER: ${DB_USERNAME}
1212
POSTGRES_DB: ${DB_NAME}
1313
esearch:
14-
image: elasticsearch:7.7.1
14+
image: elasticsearch:7.13.4
1515
container_name: ubahn-data-processor-es_es
1616
ports:
1717
- "9200:9200"

src/modules/user/service.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
const joi = require('@hapi/joi')
66
const _ = require('lodash')
7+
const config = require('config')
78

89
const errors = require('../../common/errors')
10+
const logger = require('../../common/logger')
911
const helper = require('../../common/helper')
1012
const dbHelper = require('../../common/db-helper')
1113
const serviceHelper = require('../../common/service-helper')
@@ -33,7 +35,11 @@ async function create (entity, auth) {
3335
const result = await sequelize.transaction(async (t) => {
3436
const userEntity = await dbHelper.create(User, entity, auth, t)
3537
await serviceHelper.createRecordInEs(resource, userEntity.dataValues, true)
36-
return userEntity
38+
try {
39+
await helper.postEvent(config.UBAHN_CREATE_USER_TOPIC, userEntity.dataValues)
40+
} catch (err) {
41+
logger.logFullError(err)
42+
}
3743
})
3844

3945
return result
@@ -62,6 +68,12 @@ async function patch (id, entity, auth, params) {
6268
const result = await sequelize.transaction(async (t) => {
6369
const newEntity = await dbHelper.update(User, id, entity, auth, null, t)
6470
await serviceHelper.patchRecordInEs(resource, newEntity.dataValues, true)
71+
72+
try {
73+
await helper.postEvent(config.UBAHN_UPDATE_USER_TOPIC, newEntity.dataValues)
74+
} catch (err) {
75+
logger.logFullError(err)
76+
}
6577
return newEntity
6678
})
6779

@@ -176,6 +188,11 @@ async function beginCascadeDelete (id, params) {
176188
await serviceHelper.deleteChild(UsersSkill, id, ['userId', 'skillId'], 'UsersSkill', t)
177189
await dbHelper.remove(User, id, null, t)
178190
await serviceHelper.deleteRecordFromEs(id, params, resource, true)
191+
try {
192+
await helper.postEvent(config.UBAHN_DELETE_USER_TOPIC, {id})
193+
} catch (err) {
194+
logger.logFullError(err)
195+
}
179196
})
180197
}
181198

0 commit comments

Comments
 (0)