11import express , { Request , Response , Router , NextFunction } from "express" ;
22import { DatabaseController } from "../database-controller" ;
3- import { GetQuery , GPTResponse , TableData , RadData , Testing } from "../types" ;
3+ import { GetQuery , GPTResponse , TableData , Testing , UpdateData , InsertData } from "../types" ;
44import axios from "axios" ;
55import jwt from "jsonwebtoken" ;
66import authenticateJWT from "../auth/jwt-auth" ;
@@ -61,6 +61,18 @@ export default function adminRouter(
6161 } ,
6262 ) ;
6363
64+ router . post (
65+ "/updatePaper" ,
66+ getAuthMiddleware ( ) ,
67+ async ( req : Request , res : Response ) => {
68+ try {
69+ await dbController . updatePaper ( req . body as UpdateData )
70+ } catch ( error ) {
71+ console . error ( `${ error } ` ) ;
72+ }
73+ }
74+ ) ;
75+
6476 router . post (
6577 "/parseRequest" ,
6678 getAuthMiddleware ( ) ,
@@ -159,7 +171,7 @@ export default function adminRouter(
159171}
160172
161173async function insertRows (
162- insertData : TableData [ ] ,
174+ insertData : InsertData [ ] ,
163175 dbcontroller : DatabaseController ,
164176) : Promise < void > {
165177 for ( const paper in insertData ) {
@@ -186,7 +198,7 @@ async function getFullPaperRows(
186198 return await dbController . getFullData ( search ) ;
187199}
188200
189- function insertDataRequestFromJSON ( body : any ) : TableData [ ] {
201+ function insertDataRequestFromJSON ( body : any ) : InsertData [ ] {
190202 // Ensure body is an array of objects matching the InsertData structure
191203 if ( ! Array . isArray ( body ) ) {
192204 throw new Error ( "Invalid body format: expected an array." ) ;
@@ -195,7 +207,7 @@ function insertDataRequestFromJSON(body: any): TableData[] {
195207 // Return a list of rows to insert
196208 return body . map ( ( entry ) => {
197209 // Return the validated entry as InsertData
198- return { ...entry } as TableData ;
210+ return { ...entry } as InsertData ;
199211 } ) ;
200212}
201213
0 commit comments