File tree Expand file tree Collapse file tree 5 files changed +62
-2
lines changed
Expand file tree Collapse file tree 5 files changed +62
-2
lines changed Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff line change @@ -8,7 +8,11 @@ const prisma = new PrismaClient();
88
99const 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" }
Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ import cors from "cors";
77import { createServer } from "http" ;
88import { Server } from "socket.io" ;
99import { track } from "./controllers/tracking" ;
10+ import { getIPAddress } from "./services/utils" ;
11+
12+
13+ getIPAddress ( ) ;
1014
1115const PORT = process . env . PORT || 3000 ;
1216const app = express ( ) ;
Original file line number Diff line number Diff line change 1+ import * as os from 'os' ;
2+
13const 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 } ;
You can’t perform that action at this time.
0 commit comments