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

Shapeup4 - CQRS standards update (user object) #103

Merged
merged 21 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
common error topic, no aggregation needed during error publishing
  • Loading branch information
Sachin Maheshwari committed Jul 27, 2021
commit ebc0a4df04e281b841ba0f0cc54a6150a3c798d7
5 changes: 2 additions & 3 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ module.exports = {
KAFKA_MESSAGE_ORIGINATOR: process.env.KAFKA_MESSAGE_ORIGINATOR || 'u-bahn-api',

// topics
UBAHN_CREATE_USER_TOPIC: process.env.UBAHN_CREATE_USER_TOPIC || 'user.action.topic.create',
UBAHN_UPDATE_USER_TOPIC: process.env.UBAHN_UPDATE_USER_TOPIC || 'user.action.topic.update',
UBAHN_DELETE_USER_TOPIC: process.env.UBAHN_DELETE_USER_TOPIC || 'user.action.topic.delete',
UBAHN_ERROR_TOPIC: process.env.UBAHN_ERROR_TOPIC || 'u-bahn.action.error',

UBAHN_CREATE_TOPIC: process.env.UBAHN_CREATE_TOPIC || 'u-bahn.action.create',
UBAHN_UPDATE_TOPIC: process.env.UBAHN_UPDATE_TOPIC || 'u-bahn.action.update',
UBAHN_DELETE_TOPIC: process.env.UBAHN_DELETE_TOPIC || 'u-bahn.action.delete',
Expand Down
22 changes: 21 additions & 1 deletion src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,25 @@ async function postEvent (topic, payload) {
await busApiClient.postEvent(message)
}

/**
* Send error event to Kafka
* @params {String} topic the topic name
* @params {Object} payload the payload
* @params {String} action for which operation error occurred
*/
async function publishError (topic, payload, action) {
logger.debug(`Publish error to Kafka topic ${topic}, ${JSON.stringify(payload, null, 2)}`)
_.set(payload, 'apiAction', action)
const message = {
topic,
originator: config.KAFKA_MESSAGE_ORIGINATOR,
timestamp: new Date().toISOString(),
'mime-type': 'application/json',
payload
}
await busApiClient.postEvent(message)
}

module.exports = {
validProperties,
getAuthUser,
Expand All @@ -168,5 +187,6 @@ module.exports = {
injectSearchMeta,
getControllerMethods,
getSubControllerMethods,
postEvent
postEvent,
publishError
}
8 changes: 3 additions & 5 deletions src/modules/user/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function create (entity, auth) {
return result
} catch (e) {
if (payload) {
helper.postEvent(config.UBAHN_CREATE_USER_TOPIC, payload)
helper.publishError(config.UBAHN_ERROR_TOPIC, payload, 'user.create')
}
throw e
}
Expand Down Expand Up @@ -74,16 +74,14 @@ async function patch (id, entity, auth, params) {
const result = await sequelize.transaction(async (t) => {
const newEntity = await dbHelper.update(User, id, entity, auth, null, t)
payload = newEntity.dataValues

await serviceHelper.patchRecordInEs(resource, newEntity.dataValues, true)

return newEntity
})

return result
} catch (e) {
if (payload) {
helper.postEvent(config.UBAHN_UPDATE_USER_TOPIC, payload)
helper.publishError(config.UBAHN_ERROR_TOPIC, payload, 'user.update')
}
throw e
}
Expand Down Expand Up @@ -203,7 +201,7 @@ async function beginCascadeDelete (id, params) {
})

} catch (e) {
helper.postEvent(config.UBAHN_DELETE_USER_TOPIC, payload)
helper.publishError(config.UBAHN_ERROR_TOPIC, payload, 'user.delete')
throw e
}
}
Expand Down