Spaces:
Runtime error
Runtime error
Commit ·
331064e
1
Parent(s): ea7d5b8
fix filter by date logic
Browse files
src/controllers/auditLog.controller.ts
CHANGED
|
@@ -7,14 +7,25 @@ const buildAuditLogWhereClause = (filter: Record<string, any>): any => {
|
|
| 7 |
const whereClause: any = {};
|
| 8 |
if (filter) {
|
| 9 |
if (filter.date) {
|
| 10 |
-
const date = new Date(filter.date);
|
| 11 |
if (!isNaN(date.getTime())) {
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
}
|
| 14 |
}
|
|
|
|
| 15 |
if (filter.action_by) {
|
| 16 |
whereClause.action_by = { [Op.eq]: filter.action_by };
|
| 17 |
}
|
|
|
|
| 18 |
if (filter.invoice_id) {
|
| 19 |
whereClause.invoice_id = { [Op.eq]: filter.invoice_id };
|
| 20 |
}
|
|
|
|
| 7 |
const whereClause: any = {};
|
| 8 |
if (filter) {
|
| 9 |
if (filter.date) {
|
| 10 |
+
const date = new Date(filter.date);
|
| 11 |
if (!isNaN(date.getTime())) {
|
| 12 |
+
const startOfDay = new Date(date);
|
| 13 |
+
startOfDay.setHours(0, 0, 0, 0);
|
| 14 |
+
|
| 15 |
+
const endOfDay = new Date(date);
|
| 16 |
+
endOfDay.setHours(23, 59, 59, 999);
|
| 17 |
+
|
| 18 |
+
whereClause.created_at = {
|
| 19 |
+
[Op.gte]: startOfDay,
|
| 20 |
+
[Op.lte]: endOfDay
|
| 21 |
+
};
|
| 22 |
}
|
| 23 |
}
|
| 24 |
+
|
| 25 |
if (filter.action_by) {
|
| 26 |
whereClause.action_by = { [Op.eq]: filter.action_by };
|
| 27 |
}
|
| 28 |
+
|
| 29 |
if (filter.invoice_id) {
|
| 30 |
whereClause.invoice_id = { [Op.eq]: filter.invoice_id };
|
| 31 |
}
|
src/controllers/user.controller.ts
CHANGED
|
@@ -75,12 +75,21 @@ const buildUserWhereClause = (filter: Record<string, any>): any => {
|
|
| 75 |
whereClause.name = { [Op.like]: `%${filter.name}%` };
|
| 76 |
}
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
}
|
| 83 |
-
}
|
| 84 |
|
| 85 |
if (filter.role_id) {
|
| 86 |
whereClause.role_id = { [Op.eq]: filter.role_id };
|
|
|
|
| 75 |
whereClause.name = { [Op.like]: `%${filter.name}%` };
|
| 76 |
}
|
| 77 |
|
| 78 |
+
if (filter.date) {
|
| 79 |
+
const date = new Date(filter.date);
|
| 80 |
+
if (!isNaN(date.getTime())) {
|
| 81 |
+
const startOfDay = new Date(date);
|
| 82 |
+
startOfDay.setHours(0, 0, 0, 0);
|
| 83 |
+
|
| 84 |
+
const endOfDay = new Date(date);
|
| 85 |
+
endOfDay.setHours(23, 59, 59, 999);
|
| 86 |
+
|
| 87 |
+
whereClause.created_at = {
|
| 88 |
+
[Op.gte]: startOfDay,
|
| 89 |
+
[Op.lte]: endOfDay
|
| 90 |
+
};
|
| 91 |
+
}
|
| 92 |
}
|
|
|
|
| 93 |
|
| 94 |
if (filter.role_id) {
|
| 95 |
whereClause.role_id = { [Op.eq]: filter.role_id };
|