'use strict' ; import { Router , RequestHandler , Request , Response , NextFunction } from 'express' ; import { setupMetaverseAPI , finishMetaverseAPI } from '@Route-Tools/middleware' ; import { accountFromAuthToken } from '@Route-Tools/middleware' ; import { Requests , RequestType } from '@Entities/Requests' ; import { PaginationInfo } from '@Entities/EntityFilters/PaginationInfo' ; import { RequestScopeFilter } from '@Entities/EntityFilters/RequestScopeFilter' ; import { Logger } from '@Tools/Logging' ; const procGetRequests = async ( req , resp , next ) => { if ( req . vAuthAccount ) { const pager = new PaginationInfo ( ) ; const scoper = new RequestScopeFilter ( req . vAuthAccount ) ; pager . parametersFromRequest ( req ) ; scoper . parametersFromRequest ( req ) ; const reqs = [ ] ; for await ( const aReq of Requests . enumerateAsync ( scoper , pager ) ) { const thisReq = { 'id' : aReq . id , 'type' : aReq . requestType , 'requesting_account_id' : aReq . requestingAccountId , 'target_account_id' : aReq . targetAccountId , 'when_created' : aReq . whenCreated ?. toISOString ( ) , 'when_created_s' : aReq . whenCreated ?. getTime ( ) . toString ( ) , 'expiration_time' : aReq . expirationTime ?. toISOString ( ) , 'expiration_time_s' : aReq . expirationTime ?. getTime ( ) . toString ( ) } ; switch ( aReq . requestType ) { case RequestType . HANDSHAKE : thisReq . handshake = { 'requester_id' : aReq . requesterNodeId , 'target_id' : aReq . targetNodeId , 'requester_accepted' : aReq . requesterAccepted , 'target_accepted' : aReq . targetAccepted } ; } ; reqs . push ( thisReq ) ; } ; req . vRestResp . Data = { requests : reqs } ; scoper . addResponseFields ( req ) ; pager . addResponseFields ( req ) ; } else { req . vRestResp . respondFailure ( req . vAccountError ?? 'Not logged in' ) ; } ; next ( ) ; } ; export const name = '/api/v1/requests' ; export const router = Router ( ) ; router . get ( '/api/v1/requests' , [ setupMetaverseAPI , accountFromAuthToken , procGetRequests , finishMetaverseAPI ] ) ;