@@ -20,13 +20,14 @@ import { CreateSetBody, Set, SetSqon, UpdateSetContentBody, UpdateSetTagBody } f
2020import { getStatistics , getStudiesStatistics } from './endpoints/statistics' ;
2121import transcriptomicsRouter from './endpoints/transcriptomics/route' ;
2222import { computeUpset } from './endpoints/upset' ;
23- import { reformatVenn , venn , VennOutputReformatted } from './endpoints/venn/venn' ;
23+ import { reformatVenn , venn , VennOutput } from './endpoints/venn/venn' ;
2424import { esHost , keycloakURL , userApiURL } from './env' ;
2525import { globalErrorHandler , globalErrorLogger } from './errors' ;
2626import { flushAllCache , STATISTICS_CACHE_ID , STATISTICS_PUBLIC_CACHE_ID , twineWithCache } from './middleware/cache' ;
2727import { injectBodyHttpHeaders } from './middleware/injectBodyHttpHeaders' ;
2828import { resolveSetIdMiddleware } from './middleware/resolveSetIdInSqon' ;
2929import { replaceIdsWithSetId , resolveSetsInAllSqonsWithMapper } from './sqon/resolveSetInSqon' ;
30+ import { Sqon } from './sqon/types' ;
3031
3132export default ( keycloak : Keycloak , getProject : ( projectId : string ) => ArrangerProject ) : Express => {
3233 const app = express ( ) ;
@@ -202,20 +203,24 @@ export default (keycloak: Keycloak, getProject: (projectId: string) => ArrangerP
202203 } ) ;
203204
204205 app . post ( '/venn' , keycloak . protect ( ) , async ( req , res , next ) => {
206+ const lengthOk = ( l : Sqon [ ] ) => [ 2 , 3 ] . includes ( l . length ) ;
205207 try {
206- if ( ! [ 2 , 3 ] . includes ( req . body ?. sqons ?. length ) || ! [ 2 , 3 ] . includes ( req . body ?. entityCentricSqons ?. length ) ) {
208+ const rawSqons = req . body ?. sqons ;
209+ const rawEntitySqons = req . body ?. entitySqons ;
210+
211+ if ( ! lengthOk ( rawSqons ) || ! lengthOk ( rawEntitySqons ) ) {
207212 res . status ( StatusCodes . UNPROCESSABLE_ENTITY ) . send ( 'Bad Inputs' ) ;
208213 return ;
209214 }
210215
211- const data : VennOutputReformatted [ ] = [ ] ;
212- for ( const [ rawSqons , rawIndex , noOpCounts ] of [
213- [ req . body . sqons , 'participant' , true ] ,
214- [ req . body . entityCentricSqons , req . body ?. index , false ] ,
216+ const data : VennOutput [ ] [ ] = [ ] ;
217+ for ( const [ inputSqons , rawIndex , noOpCounts ] of [
218+ [ rawSqons , 'participant' , true ] ,
219+ [ rawEntitySqons , req . body ?. index , false ] ,
215220 ] ) {
216221 // Convert sqon(s) with set_id if exists to intelligible sqon for ES query translation.
217222 const { resolvedSqons : sqons , m : mSetItToIds } = await resolveSetsInAllSqonsWithMapper (
218- rawSqons ,
223+ inputSqons ,
219224 null ,
220225 req . headers . authorization ,
221226 ) ;
@@ -224,14 +229,12 @@ export default (keycloak: Keycloak, getProject: (projectId: string) => ArrangerP
224229
225230 const datum1 = await venn ( sqons , index , noOpCounts ) ;
226231 const datum2 = datum1 . map ( x => ( { ...x , sqon : replaceIdsWithSetId ( x . sqon , mSetItToIds ) } ) ) ;
227- data . push ( reformatVenn ( datum2 ) ) ;
232+ data . push ( datum2 ) ;
228233 }
229-
234+ const indexOfParticipantEntity = 0 ;
235+ const indexOfEntity = 1 ;
230236 res . send ( {
231- data : {
232- participantCentric : data [ 0 ] ,
233- entityCentric : data [ 1 ] ,
234- } ,
237+ data : reformatVenn ( data [ indexOfParticipantEntity ] , data [ indexOfEntity ] ) ,
235238 } ) ;
236239 } catch ( e ) {
237240 next ( e ) ;
0 commit comments