11import express , { Request , Response , Router , NextFunction } from "express" ;
22import { DatabaseController } from "../database-controller" ;
3- import { GetQuery , GPTResponse , InsertData , RadData , Testing } from "../types" ;
3+ import { GetQuery , GPTResponse , TableData , RadData , Testing } from "../types" ;
44import axios from "axios" ;
55import jwt from "jsonwebtoken" ;
66import authenticateJWT from "../auth/jwt-auth" ;
@@ -25,7 +25,10 @@ export default function adminRouter(
2525 authenticateJWT ,
2626 async ( req : Request , res : Response ) => {
2727 try {
28- await insertRows ( requestFromJSON ( req . body ) , dbController ) . then ( ( ) => {
28+ await insertRows (
29+ insertDataRequestFromJSON ( req . body ) ,
30+ dbController ,
31+ ) . then ( ( ) => {
2932 // 201: The request was successful, and a new resource was created
3033 res . send ( 201 ) ;
3134 } ) ;
@@ -46,7 +49,23 @@ export default function adminRouter(
4649 res . send ( responseToJSON ( result ) ) ;
4750 } ) ;
4851 } catch ( error ) {
49- console . error ( `` ) ;
52+ console . error ( `${ error } ` ) ;
53+ }
54+ } ,
55+ ) ;
56+
57+ router . post (
58+ "/getFullPapers" ,
59+ /*authenticateJWT,*/ ( req : Request , res : Response ) => {
60+ try {
61+ // More intricate searches can be employed later similar to the table filter
62+ getFullPaperRows ( req . body . search , dbController ) . then (
63+ ( result : TableData [ ] ) => {
64+ res . send ( JSON . stringify ( result , null , 2 ) ) ;
65+ } ,
66+ ) ;
67+ } catch ( error ) {
68+ console . error ( `${ error } ` ) ;
5069 }
5170 } ,
5271 ) ;
@@ -105,7 +124,7 @@ export default function adminRouter(
105124}
106125
107126async function insertRows (
108- insertData : InsertData [ ] ,
127+ insertData : TableData [ ] ,
109128 dbcontroller : DatabaseController ,
110129) : Promise < void > {
111130 for ( const paper in insertData ) {
@@ -123,7 +142,14 @@ async function parsePapers(
123142 return temp ;
124143}
125144
126- function requestFromJSON ( body : any ) : InsertData [ ] {
145+ async function getFullPaperRows (
146+ search : string ,
147+ dbController : DatabaseController ,
148+ ) : Promise < TableData [ ] > {
149+ return await dbController . getFullData ( search ) ;
150+ }
151+
152+ function insertDataRequestFromJSON ( body : any ) : TableData [ ] {
127153 // Ensure body is an array of objects matching the InsertData structure
128154 if ( ! Array . isArray ( body ) ) {
129155 throw new Error ( "Invalid body format: expected an array." ) ;
@@ -132,7 +158,7 @@ function requestFromJSON(body: any): InsertData[] {
132158 // Return a list of rows to insert
133159 return body . map ( ( entry ) => {
134160 // Return the validated entry as InsertData
135- return { ...entry } as InsertData ;
161+ return { ...entry } as TableData ;
136162 } ) ;
137163}
138164
0 commit comments