Skip to content

Commit 8fb75b1

Browse files
committed
fixed logs
1 parent 9280fd3 commit 8fb75b1

File tree

5 files changed

+62
-2
lines changed

5 files changed

+62
-2
lines changed

client/components/dataTables/ContractorLogs.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,26 @@ export const columns: ColumnDef<ContractorLog>[] = [
8888
<div className="text-center font-medium">{row.getValue("description")}</div>
8989
),
9090
},
91+
{
92+
accessorKey: "time",
93+
header: ({ column }) => {
94+
return (
95+
<div className="flex justify-center items-center">
96+
<Button
97+
variant="ghost"
98+
className="text-center"
99+
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
100+
>
101+
Time
102+
<CaretSortIcon className="ml-2 h-4 w-4" />
103+
</Button>
104+
</div>
105+
);
106+
},
107+
cell: ({ row }) => (
108+
<div className="text-center font-medium">{row.getValue("time")}</div>
109+
),
110+
},
91111
{
92112
id: "actions",
93113
enableHiding: false,

client/hooks/dataQuery/useGetAllLogs.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ export default function useGetAllLogs() {
2222
return {
2323
type: log.type,
2424
description: log.description,
25+
time: new Date(log.createdAt).toLocaleString(
26+
"en-US",
27+
{
28+
hour: "2-digit",
29+
minute: "2-digit",
30+
}
31+
),
2532
};
2633
});
2734
await setContractorLog(logList);

server/src/controllers/logs.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ const prisma = new PrismaClient();
88

99
const getAdminLogs = errorWrapper(
1010
async (req: Request, res: Response) => {
11-
const logs = await prisma.adminLogs.findMany();
11+
const logs = await prisma.adminLogs.findMany({
12+
orderBy:{
13+
createdAt : 'desc'
14+
}
15+
});
1216
res.status(200).json(logs);
1317
},
1418
{ statusCode: 500, message: "Couldn't get admin logs" }

server/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import cors from "cors";
77
import { createServer } from "http";
88
import { Server } from "socket.io";
99
import { track } from "./controllers/tracking";
10+
import { getIPAddress } from "./services/utils";
11+
12+
13+
getIPAddress();
1014

1115
const PORT = process.env.PORT || 3000;
1216
const app = express();

server/src/services/utils.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as os from 'os';
2+
13
const randomOTPGenerator = () => {
24
const otp = Math.floor(1000 + Math.random() * 9000);
35
return otp;
@@ -8,4 +10,27 @@ const randomPasswordGenerator = () => {
810
return password;
911
};
1012

11-
export { randomOTPGenerator, randomPasswordGenerator };
13+
14+
const getIPAddress = (): string => {
15+
// Get the network interfaces
16+
const networkInterfaces = os.networkInterfaces();
17+
18+
// Extract the IPv4 address from the network interfaces
19+
const ipv4Addresses: string[] = [];
20+
for (const interfaceName in networkInterfaces) {
21+
if (Object.prototype.hasOwnProperty.call(networkInterfaces, interfaceName)) {
22+
const interfaces = networkInterfaces[interfaceName];
23+
for (const iface of interfaces?.filter(Boolean) || []){
24+
if (iface.family === 'IPv4' && !iface.internal) {
25+
ipv4Addresses.push(iface.address);
26+
}
27+
}
28+
}
29+
}
30+
31+
console.log('IPv4 Addresses:', ipv4Addresses[0]);
32+
return ipv4Addresses[0] || '';
33+
};
34+
35+
36+
export { randomOTPGenerator, randomPasswordGenerator, getIPAddress };

0 commit comments

Comments
 (0)