narinder1231 commited on
Commit
5256dce
·
1 Parent(s): eb89a56

include user as actionBy in list audit log api

Browse files
src/controllers/auditLog.controller.ts CHANGED
@@ -3,6 +3,7 @@ import { Op, FindOptions } from 'sequelize';
3
  import AuditLog from '../models/auditLogs';
4
  import { logger } from '../utils/logger';
5
  import { AuditLogInterface } from '../shared/interfaces/auditLog.interface';
 
6
 
7
  const buildAuditLogWhereClause = (filter: Record<string, any>): any => {
8
  const whereClause: any = {};
@@ -76,7 +77,12 @@ const getAuditLogs = async (req: Request, res: Response) => {
76
  }
77
 
78
  const [auditLogs, totalAuditLogs] = await Promise.all([
79
- AuditLog.findAll(options),
 
 
 
 
 
80
  AuditLog.count({ where: whereClause }),
81
  ]);
82
 
 
3
  import AuditLog from '../models/auditLogs';
4
  import { logger } from '../utils/logger';
5
  import { AuditLogInterface } from '../shared/interfaces/auditLog.interface';
6
+ import User from '../models/users';
7
 
8
  const buildAuditLogWhereClause = (filter: Record<string, any>): any => {
9
  const whereClause: any = {};
 
77
  }
78
 
79
  const [auditLogs, totalAuditLogs] = await Promise.all([
80
+ AuditLog.findAll({...options, include: [
81
+ { model: User,
82
+ as: 'actionBy',
83
+ attributes: { exclude: ['password']}
84
+ },
85
+ ]}),
86
  AuditLog.count({ where: whereClause }),
87
  ]);
88
 
src/models/auditLogs.ts CHANGED
@@ -72,7 +72,7 @@ AuditLog.init(
72
  );
73
 
74
  AuditLog.belongsTo(User, {
75
- foreignKey: 'action_by',
76
  })
77
 
78
  AuditLog.belongsTo(Invoice, {
 
72
  );
73
 
74
  AuditLog.belongsTo(User, {
75
+ foreignKey: 'action_by', as: 'actionBy',
76
  })
77
 
78
  AuditLog.belongsTo(Invoice, {