tango-app-api-report 3.3.7 → 3.4.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-report",
3
- "version": "3.3.7",
3
+ "version": "3.4.0-beta.0",
4
4
  "description": "report",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -81,12 +81,25 @@ export async function updateReport( req, res ) {
81
81
  const updateAck = await reportUpdate( {
82
82
  _id: req.params?.id, fileType: req.body?.fileType, email: req.body?.email, clientId: req.body?.clientId,
83
83
  } );
84
+ const postReport = await reportGetSingle( {
85
+ _id: req.params?.id,
86
+ } );
84
87
 
85
- const user = await getUserNameEmailById( req.userId );
86
-
88
+ const user = req.user;
89
+ const oldData={
90
+ ReportName: previousReport?.fileName,
91
+ FileType: previousReport?.fileType,
92
+ ReceiversEmail: previousReport?.email.join( ', ' ),
93
+ };
94
+ const newData={
95
+ ReportName: postReport?.fileName,
96
+ FileType: postReport?.fileType,
97
+ ReceiversEmail: postReport?.email.join( ', ' ),
98
+ };
87
99
  const logObj = {
88
100
  clientId: req.body?.clientId,
89
101
  userName: user?.userName,
102
+ userId: user?._id,
90
103
  email: user?.email,
91
104
  date: new Date(),
92
105
  logType: 'configuration',
@@ -94,14 +107,14 @@ export async function updateReport( req, res ) {
94
107
  changes: [ `The Report ${previousReport.fileName}.${previousReport.fileType}` ],
95
108
  eventType: 'update',
96
109
  showTo: [ 'tango' ],
97
- current: req.body,
110
+ current: postReport,
98
111
  previous: previousReport,
99
-
112
+ oldData: oldData,
113
+ newData: newData,
100
114
  };
101
-
102
115
  await insertOpenSearchData( openSearch.activityLog, logObj );
103
116
  if ( updateAck ) {
104
- res.sendSuccess( { result: 'Updated Successfully' } );
117
+ return res.sendSuccess( { result: 'Updated Successfully' } );
105
118
  }
106
119
  } catch ( error ) {
107
120
  logger.error( { error: error, message: req.params, function: 'updateReport' } );
@@ -112,21 +125,26 @@ export async function updateReport( req, res ) {
112
125
  export async function deleteReport( req, res ) {
113
126
  try {
114
127
  const inputData = req.params;
128
+ const openSearch = JSON.parse( process.env.OPENSEARCH );
115
129
  const previousReport = await reportGetSingle( {
116
130
  _id: inputData?.id,
117
131
  } );
132
+
118
133
  await deleteOneReport( { _id: inputData.id } );
134
+ const postReport = await reportGetSingle( {
135
+ _id: req.params?.id,
136
+ } );
119
137
  const logObj = {
120
- clientId: req.body?.clientId,
121
- userName: user?.userName,
122
- email: user?.email,
138
+ clientId: req?.body?.clientId,
139
+ userName: req?.user?.userName,
140
+ email: req?.user?.email,
123
141
  date: new Date(),
124
142
  logType: 'configuration',
125
143
  logSubType: 'reportConfig',
126
144
  changes: [ `The Report ${previousReport.fileName}.${previousReport.fileType} has been deleted` ],
127
145
  eventType: 'delete',
128
146
  showTo: [ 'tango' ],
129
- current: req.body,
147
+ current: postReport,
130
148
  previous: previousReport,
131
149
 
132
150
  };
@@ -135,7 +153,9 @@ export async function deleteReport( req, res ) {
135
153
  await insertOpenSearchData( openSearch.activityLog, logObj );
136
154
  return res.sendSuccess( { result: 'Report has been deleted successfully' } );
137
155
  } catch ( error ) {
138
- return res.sendError( error, 500 );
156
+ const err = error.message || 'Internal Server Error';
157
+ logger.error( { message: error, data: req.params, function: 'deleteReport' } );
158
+ return res.sendError( err, 500 );
139
159
  }
140
160
  }
141
161
 
@@ -281,7 +301,6 @@ export async function generateReport( req, res ) {
281
301
  logType: 'report',
282
302
  logSubType: 'generateReport',
283
303
  logData: {
284
- // clientName: req.report?.clientName,
285
304
  fileDate: inputData.fileDate.split( '-' ).reverse().join( '-' ),
286
305
  reportName: req.report?.reportConfigs?.reportName,
287
306
  clientId: inputData.clientId,