11const models = require ( '../models' )
2- const model = models . auditlog
2+ const model = models . auditlog
33const Joi = require ( 'joi' )
4-
4+
55
66producerLog . schema = Joi . object ( ) . keys ( {
77 SEQ_ID : Joi . string ( ) . required ( ) ,
@@ -13,25 +13,34 @@ producerLog.schema = Joi.object().keys({
1313//add producer_log = used for data update about producer received
1414function producerLog ( payload ) {
1515 const result = Joi . validate ( payload , producerLog . schema )
16- if ( result . error !== null ) {
16+ if ( result . error !== null ) {
1717 return Promise . resolve ( ) . then ( function ( ) {
1818 throw new Error ( 'Producer log create ' + result . error )
1919 } )
2020 }
21- return model . producer_log . create ( payload )
21+ return model . producer_log . create ( payload )
2222}
2323
2424//update producer_log = used for failure update in case of success, it will not be executed
2525function producerLog_update ( payload ) {
2626 const result = Joi . validate ( payload , producerLog . schema )
27- if ( result . error !== null ) {
27+ if ( result . error !== null ) {
2828 return Promise . resolve ( ) . then ( function ( ) {
2929 throw new Error ( 'Producer log create ' + result . error )
3030 } )
3131 }
3232 //return model.producer_log.update(payload)
33- const { SEQ_ID , PODUCER_PUBLISH_RETRY_COUNT , ...change } = payload
34- return model . producer_log . update ( change , { where : { SEQ_ID : payload . SEQ_ID , PODUCER_PUBLISH_RETRY_COUNT : payload . PODUCER_PUBLISH_RETRY_COUNT } } )
33+ const {
34+ SEQ_ID ,
35+ PODUCER_PUBLISH_RETRY_COUNT ,
36+ ...change
37+ } = payload
38+ return model . producer_log . update ( change , {
39+ where : {
40+ SEQ_ID : payload . SEQ_ID ,
41+ PODUCER_PUBLISH_RETRY_COUNT : payload . PODUCER_PUBLISH_RETRY_COUNT
42+ }
43+ } )
3544}
3645
3746
@@ -40,7 +49,7 @@ pAuditLog.schema = Joi.object().keys({
4049 SEQ_ID : Joi . string ( ) . required ( ) ,
4150 REQUEST_CREATE_TIME : Joi . date ( ) ,
4251 PRODUCER_PAYLOAD : Joi . object ( ) ,
43- PRODUCER_PUBLISH_STATUS : Joi . string ( ) . valid ( 'success' , 'failure' ) ,
52+ PRODUCER_PUBLISH_STATUS : Joi . string ( ) . valid ( 'success' , 'failure' ) ,
4453 PRODUCER_FAILURE_LOG : Joi . object ( ) ,
4554 PRODUCER_PUBLISH_TIME : Joi . date ( ) ,
4655 PODUCER_PUBLISH_RETRY_COUNT : Joi . number ( ) ,
@@ -51,7 +60,7 @@ pAuditLog.schema = Joi.object().keys({
5160//add audit_log about the producer details
5261function pAuditLog ( payload ) {
5362 const result = Joi . validate ( payload , pAuditLog . schema )
54- if ( result . error !== null ) {
63+ if ( result . error !== null ) {
5564 return Promise . resolve ( ) . then ( function ( ) {
5665 throw new Error ( 'Audit' + result . error )
5766 } )
@@ -62,14 +71,21 @@ function pAuditLog(payload) {
6271//updated audit_log about the producer status
6372function pAuditLog_update ( payload ) {
6473 const result = Joi . validate ( payload , pAuditLog . schema )
65- if ( result . error !== null ) {
74+ if ( result . error !== null ) {
6675 return Promise . resolve ( ) . then ( function ( ) {
6776 throw new Error ( 'Audit' + result . error )
6877 } )
6978 }
7079 //return model.audit_log.create(payload)
71- const { SEQ_ID , ...change } = payload
72- return model . audit_log . update ( change , { where : { SEQ_ID : payload . SEQ_ID } } )
80+ const {
81+ SEQ_ID ,
82+ ...change
83+ } = payload
84+ return model . audit_log . update ( change , {
85+ where : {
86+ SEQ_ID : payload . SEQ_ID
87+ }
88+ } )
7389}
7490
7591consumerLog . schema = Joi . object ( ) . keys ( {
@@ -82,32 +98,41 @@ consumerLog.schema = Joi.object().keys({
8298//add consumer_log = Entering received record
8399function consumerLog ( payload ) {
84100 const result = Joi . validate ( payload , consumerLog . schema )
85- if ( result . error !== null ) {
101+ if ( result . error !== null ) {
86102 return Promise . resolve ( ) . then ( function ( ) {
87103 throw new Error ( 'Consumer' + result . error )
88104 } )
89105 }
90106
91- return model . consumer_log . create ( payload )
107+ return model . consumer_log . create ( payload )
92108}
93109
94110//update consumer_log = used for failure log update
95111function consumerLog_update ( payload ) {
96112 const result = Joi . validate ( payload , consumerLog . schema )
97- if ( result . error !== null ) {
113+ if ( result . error !== null ) {
98114 return Promise . resolve ( ) . then ( function ( ) {
99115 throw new Error ( 'Consumer' + result . error )
100116 } )
101117 }
102118 //return model.consumer_log.create(payload)
103- const { SEQ_ID , CONSUMER_UPDATE_RETRY_COUNT , ...change } = payload
104- return model . consumer_log . update ( change , { where : { SEQ_ID : payload . SEQ_ID , CONSUMER_UPDATE_RETRY_COUNT : payload . CONSUMER_UPDATE_RETRY_COUNT } } )
119+ const {
120+ SEQ_ID ,
121+ CONSUMER_UPDATE_RETRY_COUNT ,
122+ ...change
123+ } = payload
124+ return model . consumer_log . update ( change , {
125+ where : {
126+ SEQ_ID : payload . SEQ_ID ,
127+ CONSUMER_UPDATE_RETRY_COUNT : payload . CONSUMER_UPDATE_RETRY_COUNT
128+ }
129+ } )
105130}
106131
107132cAuditLog . schema = Joi . object ( ) . keys ( {
108133 SEQ_ID : Joi . string ( ) . required ( ) ,
109134 CONSUMER_PAYLOAD : Joi . object ( ) ,
110- CONSUMER_DEPLOY_STATUS : Joi . string ( ) . valid ( 'success' , 'failure' ) ,
135+ CONSUMER_DEPLOY_STATUS : Joi . string ( ) . valid ( 'success' , 'failure' ) ,
111136 CONSUMER_FAILURE_LOG : Joi . object ( ) ,
112137 CONSUMER_UPDATE_TIME : Joi . date ( ) ,
113138 CONSUMER_UPDATE_RETRY_COUNT : Joi . number ( ) ,
@@ -117,14 +142,21 @@ cAuditLog.schema = Joi.object().keys({
117142//add audit_log = only update is possible
118143function cAuditLog ( payload ) {
119144 const result = Joi . validate ( payload , cAuditLog . schema )
120- if ( result . error !== null ) {
145+ if ( result . error !== null ) {
121146 return Promise . resolve ( ) . then ( function ( ) {
122147 throw new Error ( 'Audit' + result . error )
123148 } )
124149 }
125150
126- const { SEQ_ID , ...change } = payload
127- return model . audit_log . update ( change , { where : { SEQ_ID : payload . SEQ_ID } } )
151+ const {
152+ SEQ_ID ,
153+ ...change
154+ } = payload
155+ return model . audit_log . update ( change , {
156+ where : {
157+ SEQ_ID : payload . SEQ_ID
158+ }
159+ } )
128160}
129161
130162module . exports = {
@@ -135,4 +167,4 @@ module.exports = {
135167 consumerLog,
136168 consumerLog_update,
137169 cAuditLog
138- }
170+ }
0 commit comments