Skip to content

Commit 38c61ea

Browse files
author
deonbotha
authored
message template changes (#3)
* message template changes * delete .idea/workspace.xml * delete package-lock.json * Fixed a typo
1 parent 5cbfb4a commit 38c61ea

3 files changed

Lines changed: 142 additions & 137 deletions

File tree

‎src/observeables/actions.js‎

Lines changed: 132 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -37,157 +37,157 @@ const Mustache = require('mustache')
3737
const Email = require('../nodeMailer/sendMail')
3838

3939
const createMessageProtocol = (payload, action, state = '', pp = '') => {
40-
return {
41-
id: Uuid(),
42-
from: payload.from,
43-
to: payload.to,
44-
type: 'application/json',
45-
content: {
46-
header: {},
47-
payload
48-
},
49-
metadata: {
50-
event: {
40+
return {
5141
id: Uuid(),
52-
responseTo: '',
53-
type: 'notification',
54-
action,
55-
createdAt: new Date(),
56-
state
57-
}
58-
},
59-
pp
60-
}
42+
from: payload.from,
43+
to: payload.to,
44+
type: 'application/json',
45+
content: {
46+
header: {},
47+
payload
48+
},
49+
metadata: {
50+
event: {
51+
id: Uuid(),
52+
responseTo: '',
53+
type: 'notification',
54+
action,
55+
createdAt: new Date(),
56+
state
57+
}
58+
},
59+
pp
60+
}
6161
}
6262

6363
const dictionary = {
64-
produceToKafkaTopic: async ({ payload, action, eventType = TransferEventType.NOTIFICATION, eventAction = TransferEventAction.EVENT }) => {
65-
try {
66-
await Utility.produceGeneralMessage(eventType, eventAction, createMessageProtocol(payload, action), Utility.ENUMS.STATE.SUCCESS)
67-
} catch (err) {
68-
throw err
69-
}
70-
},
64+
produceToKafkaTopic: async ({payload, action, eventType = TransferEventType.NOTIFICATION, eventAction = TransferEventAction.EVENT}) => {
65+
try {
66+
await Utility.produceGeneralMessage(eventType, eventAction, createMessageProtocol(payload, action), Utility.ENUMS.STATE.SUCCESS)
67+
} catch (err) {
68+
throw err
69+
}
70+
},
7171

72-
sendRequest: ({ method = 'GET', url, payload }) => {
73-
return 'not implemented'
74-
},
72+
sendRequest: ({method = 'GET', url, payload}) => {
73+
return 'not implemented'
74+
},
7575

76-
// {
77-
// "id": "0eed9113-7605-4e5e-952a-a5eb3c77df11",
78-
// "from": "SYSTEM",
79-
// "to": "dfsp1",
80-
// "type": "application/json",
81-
// "content": {
82-
// "header": {},
83-
// "payload": {
84-
// "from": "SYSTEM",
85-
// "to": "dfsp1",
86-
// "recepientDetails": {
87-
// "_id": "5bebfe65617a4e64119c4d4e",
88-
// "name": "dfsp1",
89-
// "type": "NET_DEBIT_CAP_BREACH_MAIL",
90-
// "value": "vg@gm.com",
91-
// "action": "sendEmail",
92-
// "createdDate": "2018-11-14T10:52:21.448Z",
93-
// "__v": 0
94-
// },
95-
// "hubDetails": {
96-
// "_id": "5bebfe65617a4e64119c4d53",
97-
// "name": "Hub",
98-
// "type": "NET_DEBIT_CAP_BREACH_MAIL",
99-
// "value": "vg@gm.com",
100-
// "action": "sendEmail",
101-
// "createdDate": "2018-11-14T10:52:21.475Z",
102-
// "__v": 0
103-
// },
104-
// "messageDetails": {
105-
// "dfsp": "dfsp1",
106-
// "limitType": "NET_DEBIT_CAP",
107-
// "value": 4,
108-
// "position": 2880,
109-
// "triggeredBy": "5bebfec8c2b6177ee36f2403",
110-
// "fromEvent": "5bebfe65617a4e64119c4d54",
111-
// "repetitionsAllowed": 3,
112-
// "action": "sendEmail",
113-
// "notificationEndpointType": "NET_DEBIT_CAP_BREACH_MAIL",
114-
// "notificationInterval": 3,
115-
// "resetPeriod": 60
116-
// }
117-
// }
118-
// },
119-
// "metadata": {
120-
// "event": {
121-
// "id": "281bee59-0500-4882-9e74-e750d82ba522",
122-
// "responseTo": "78ea223d-a5b6-4e97-a00c-07c9a525d8db",
123-
// "type": "notification",
124-
// "action": "event",
125-
// "createdAt": "2018-11-14T10:54:12.811Z",
126-
// "state": {
127-
// "status": "success",
128-
// "code": 0,
129-
// "description": "action successful"
130-
// }
131-
// }
132-
// },
133-
// "pp": ""
134-
// }
76+
// {
77+
// "id": "0eed9113-7605-4e5e-952a-a5eb3c77df11",
78+
// "from": "SYSTEM",
79+
// "to": "dfsp1",
80+
// "type": "application/json",
81+
// "content": {
82+
// "header": {},
83+
// "payload": {
84+
// "from": "SYSTEM",
85+
// "to": "dfsp1",
86+
// "recepientDetails": {
87+
// "_id": "5bebfe65617a4e64119c4d4e",
88+
// "name": "dfsp1",
89+
// "type": "NET_DEBIT_CAP_BREACH_MAIL",
90+
// "value": "vg@gm.com",
91+
// "action": "sendEmail",
92+
// "createdDate": "2018-11-14T10:52:21.448Z",
93+
// "__v": 0
94+
// },
95+
// "hubDetails": {
96+
// "_id": "5bebfe65617a4e64119c4d53",
97+
// "name": "Hub",
98+
// "type": "NET_DEBIT_CAP_BREACH_MAIL",
99+
// "value": "vg@gm.com",
100+
// "action": "sendEmail",
101+
// "createdDate": "2018-11-14T10:52:21.475Z",
102+
// "__v": 0
103+
// },
104+
// "messageDetails": {
105+
// "dfsp": "dfsp1",
106+
// "limitType": "NET_DEBIT_CAP",
107+
// "value": 4,
108+
// "position": 2880,
109+
// "triggeredBy": "5bebfec8c2b6177ee36f2403",
110+
// "fromEvent": "5bebfe65617a4e64119c4d54",
111+
// "repetitionsAllowed": 3,
112+
// "action": "sendEmail",
113+
// "notificationEndpointType": "NET_DEBIT_CAP_BREACH_MAIL",
114+
// "notificationInterval": 3,
115+
// "resetPeriod": 60
116+
// }
117+
// }
118+
// },
119+
// "metadata": {
120+
// "event": {
121+
// "id": "281bee59-0500-4882-9e74-e750d82ba522",
122+
// "responseTo": "78ea223d-a5b6-4e97-a00c-07c9a525d8db",
123+
// "type": "notification",
124+
// "action": "event",
125+
// "createdAt": "2018-11-14T10:54:12.811Z",
126+
// "state": {
127+
// "status": "success",
128+
// "code": 0,
129+
// "description": "action successful"
130+
// }
131+
// }
132+
// },
133+
// "pp": ""
134+
// }
135135

136-
sendEmail: async ({ payload }) => {
137-
const path = `${payload.messageDetails.language}/${payload.messageDetails.templateType}`
138-
const templates = await loadTemplates(path, 'mustache')
139-
const dfspEmailBody = Mustache.render(templates.dfspEmail, payload.messageDetails)
140-
const hubEmailBody = Mustache.render(templates.hubEmail, payload.messageDetails)
141-
const dfspNotificationDetails = payload.recepientDetails
142-
const hubNotificationDetails = payload.hubDetails
136+
sendEmail: async ({payload}) => {
137+
const path = `${payload.messageDetails.language}/${payload.messageDetails.templateType}`
138+
const templates = await loadTemplates(path, 'mustache')
139+
const dfspEmailBody = Mustache.render(templates.dfspEmail, payload.messageDetails)
140+
const hubEmailBody = Mustache.render(templates.hubEmail, payload.messageDetails)
141+
const dfspNotificationDetails = payload.recepientDetails
142+
const hubNotificationDetails = payload.hubDetails
143143

144-
const dfspMessage = {
145-
priority: 'high',
146-
from: hubNotificationDetails.value,
147-
to: dfspNotificationDetails.value,
148-
subject: `${payload.messageDetails.limitType} threshold is breached`,
149-
text: dfspEmailBody
150-
}
144+
const dfspMessage = {
145+
priority: 'high',
146+
from: hubNotificationDetails.value,
147+
to: dfspNotificationDetails.value,
148+
subject: payload.messageDetails.messageSubject,
149+
text: dfspEmailBody
150+
}
151151

152-
const hubMessage = {
153-
priority: 'high',
154-
from: hubNotificationDetails.value,
155-
to: hubNotificationDetails.value,
156-
subject: `DFSP ${payload.messageDetails.dfsp} ${payload.messageDetails.limitType} threshold is breached`,
157-
text: hubEmailBody
158-
}
152+
const hubMessage = {
153+
priority: 'high',
154+
from: hubNotificationDetails.value,
155+
to: hubNotificationDetails.value,
156+
subject: payload.messageDetails.messageSubject,
157+
text: hubEmailBody
158+
}
159159

160-
const hubMailResult = await Email.sendMailMessage(hubMessage)
161-
const dfspMailResult = await Email.sendMailMessage(dfspMessage)
162-
return {
163-
dfspMailResult,
164-
hubMailResult
160+
const hubMailResult = await Email.sendMailMessage(hubMessage)
161+
const dfspMailResult = await Email.sendMailMessage(dfspMessage)
162+
return {
163+
dfspMailResult,
164+
hubMailResult
165+
}
165166
}
166-
}
167167
}
168168

169169
const actionBuilder = (action) => {
170-
return dictionary[action]
170+
return dictionary[action]
171171
}
172172

173173
const actionObservable = (message) => {
174-
return Rx.Observable.create(async observer => {
175-
const result = await actionBuilder(message.value.content.payload.messageDetails.action)({ payload: message.value.content.payload })
176-
observer.next(result)
177-
try {
178-
} catch (err) {
179-
Logger.info(`action observer failed with error - ${err}`)
180-
observer.error(err)
181-
}
182-
})
174+
return Rx.Observable.create(async observer => {
175+
const result = await actionBuilder(message.value.content.payload.messageDetails.action)({payload: message.value.content.payload})
176+
observer.next(result)
177+
try {
178+
} catch (err) {
179+
Logger.info(`action observer failed with error - ${err}`)
180+
observer.error(err)
181+
}
182+
})
183183
}
184184

185185
const getActions = () => {
186-
let actions = []
187-
for (let action in dictionary) {
188-
actions.push(action)
189-
}
190-
return actions
186+
let actions = []
187+
for (let action in dictionary) {
188+
actions.push(action)
189+
}
190+
return actions
191191
}
192192

193-
module.exports = { actionObservable, getActions }
193+
module.exports = {actionObservable, getActions}

‎templates/en/adjustment/dfspEmail.mustache‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
12
Dear {{dfsp}},
2-
Your {{limitType}} limit was adjusted.
3+
4+
Your {{limitType}} limit was adjusted to {{value}} {{currency}}.
5+
6+
This message will be repeated {{repetitionsAllowed}} times within the next {{resetPeriod}} minutes at {{notificationInterval}} minute intervals, if limit changes are made.
37

48
This is automatically generated email message.
5-
The message will be repeated {{repetitionsAllowed}} times in {{notificationInterval}} period within {{resetPeriod}} hours, if new transfers breaching limit are created.
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
{{dfsp}} {{limitType}} limit was adjusted.
21

3-
This is automatically generated email message.
4-
The message will be repeated {{repetitionsAllowed}} times in {{notificationInterval}} period within {{resetPeriod}} hours, if new transfers breaching limit are created.
2+
{{dfsp}}'s {{limitType}} limit was adjusted to {{value}} {{currency}}.
3+
4+
This message will be repeated {{repetitionsAllowed}} times within the next {{resetPeriod}} minutes at {{notificationInterval}} minute intervals, if limit changes are made.
5+
6+
This is an automatically generated email message.

0 commit comments

Comments
 (0)