Bansari Akhani commited on
Commit
b52eb95
·
1 Parent(s): 3a65c87

add update audit log for invoice update, update invoice status after propertyware sync request - succ/failed

Browse files
src/controllers/auditLog.controller.ts CHANGED
@@ -117,7 +117,7 @@ const getAuditLogById = async (req: Request, res: Response) => {
117
 
118
  }
119
 
120
- const createNewAuditLog = async (auditLogData: AuditLogInterface) => {
121
  try {
122
  const newAuditLog = await AuditLog.create({
123
  action_by: auditLogData.action_by,
@@ -130,4 +130,4 @@ const createNewAuditLog = async (auditLogData: AuditLogInterface) => {
130
  }
131
  };
132
 
133
- export { getAuditLogs, getAuditLogById, createNewAuditLog }
 
117
 
118
  }
119
 
120
+ const createAuditLog = async (auditLogData: AuditLogInterface) => {
121
  try {
122
  const newAuditLog = await AuditLog.create({
123
  action_by: auditLogData.action_by,
 
130
  }
131
  };
132
 
133
+ export { getAuditLogs, getAuditLogById, createAuditLog }
src/controllers/invoice/invoice.controller.ts CHANGED
@@ -12,6 +12,7 @@ import PwBuilding from "../../models/pwBuildings";
12
  import PwUnit from "../../models/pwUnits";
13
  import { logger } from '../../utils/logger';
14
  import AuditLog from "../../models/auditLogs";
 
15
 
16
 
17
  export const createInvoice = async (req: Request, res: Response) => {
@@ -331,14 +332,14 @@ export const updateInvoice = async (req: Request, res: Response): Promise<Respon
331
  const invoiceUpdate = await existingInvoice.update(updatedInvoiceData);
332
 
333
  const updatedFields = getUpdatedFields(originalInvoiceData, invoiceUpdate.dataValues);
334
- const auditLogData = {
 
335
  invoice_id: invoice.id,
336
  action_by: 1, // replace with the actual user ID performing the action
337
  action: 'Update Invoice',
338
  details: updatedFields
339
- };
340
 
341
- await AuditLog.create(auditLogData);
342
  // Delete existing InvoiceDetails
343
  await InvoiceDetail.destroy({ where: { invoice_id: id } });
344
 
 
12
  import PwUnit from "../../models/pwUnits";
13
  import { logger } from '../../utils/logger';
14
  import AuditLog from "../../models/auditLogs";
15
+ import { createAuditLog } from "../auditLog.controller";
16
 
17
 
18
  export const createInvoice = async (req: Request, res: Response) => {
 
332
  const invoiceUpdate = await existingInvoice.update(updatedInvoiceData);
333
 
334
  const updatedFields = getUpdatedFields(originalInvoiceData, invoiceUpdate.dataValues);
335
+
336
+ createAuditLog({
337
  invoice_id: invoice.id,
338
  action_by: 1, // replace with the actual user ID performing the action
339
  action: 'Update Invoice',
340
  details: updatedFields
341
+ });
342
 
 
343
  // Delete existing InvoiceDetails
344
  await InvoiceDetail.destroy({ where: { invoice_id: id } });
345
 
src/controllers/propertyware/bills.controller.ts CHANGED
@@ -7,6 +7,7 @@ import { formatDate } from '../../utils/dataUtils';
7
  import AuditLog from '../../models/auditLogs';
8
  import ErrorLog from './../../models/errorLog';
9
  import { AxiosError } from 'axios';
 
10
 
11
  export const syncInvoices = async (req: Request, res: Response) => {
12
  try {
@@ -44,16 +45,18 @@ export const syncInvoices = async (req: Request, res: Response) => {
44
  };
45
  try {
46
  const response = await createBill(bill);
47
- console.log(response.id);
48
 
49
- // add audit log for Update Invoice
50
-
51
  const auditLogData = { invoice_id: invoice.id as number, action_by: 1, action: 'Invoice sync to PW', details: `Bill for invoice ${bill.refNo} synced successfully. PW invoice id : ${response.id}`};
52
- await AuditLog.create(auditLogData);
 
 
 
53
 
54
  logger.info(`Bill for invoice ${bill.refNo} synced successfully`);
55
  } catch (error) {
56
  if (error instanceof Error ){
 
57
 
58
  logger.error(`Error syncing bill for invoice ${bill.refNo}`);
59
 
 
7
  import AuditLog from '../../models/auditLogs';
8
  import ErrorLog from './../../models/errorLog';
9
  import { AxiosError } from 'axios';
10
+ import { createAuditLog } from '../auditLog.controller';
11
 
12
  export const syncInvoices = async (req: Request, res: Response) => {
13
  try {
 
45
  };
46
  try {
47
  const response = await createBill(bill);
 
48
 
49
+ // add audit log for Update Invoice
 
50
  const auditLogData = { invoice_id: invoice.id as number, action_by: 1, action: 'Invoice sync to PW', details: `Bill for invoice ${bill.refNo} synced successfully. PW invoice id : ${response.id}`};
51
+ createAuditLog(auditLogData);
52
+
53
+ // Update Invoide status
54
+ await invoice.update({status:'Sync success'});
55
 
56
  logger.info(`Bill for invoice ${bill.refNo} synced successfully`);
57
  } catch (error) {
58
  if (error instanceof Error ){
59
+ await invoice.update({status:'Sync failed'})
60
 
61
  logger.error(`Error syncing bill for invoice ${bill.refNo}`);
62