'use strict' ; import { Router , RequestHandler , Request , Response , NextFunction } from 'express' ; import { setupMetaverseAPI , finishMetaverseAPI } from '@Route-Tools/middleware' ; import { accountFromAuthToken } from '@Route-Tools/middleware' ; import { buildAccountInfo } from '@Route-Tools/Util' ; import { Accounts } from '@Entities/Accounts' ; import { PaginationInfo } from '@Entities/EntityFilters/PaginationInfo' ; import { AccountScopeFilter } from '@Entities/EntityFilters/AccountScopeFilter' ; import { AccountFilterInfo } from '@Entities/EntityFilters/AccountFilterInfo' ; import { Logger } from '@Tools/Logging' ; const procGetAccounts = async ( req , resp , next ) => { if ( req . vAuthAccount ) { const pager = new PaginationInfo ( ) ; const scoper = new AccountScopeFilter ( req . vAuthAccount ) ; const infoer = new AccountFilterInfo ( ) ; pager . parametersFromRequest ( req ) ; scoper . parametersFromRequest ( req ) ; infoer . parametersFromRequest ( req ) ; const accts = [ ] ; for await ( const acct of Accounts . enumerateAsync ( scoper , infoer , pager ) ) { accts . push ( await buildAccountInfo ( req , acct ) ) ; } ; req . vRestResp . Data = { accounts : accts } ; pager . addResponseFields ( req ) ; scoper . addResponseFields ( req ) ; infoer . addResponseFields ( req ) ; } else { req . vRestResp . respondFailure ( req . vAccountError ?? 'Not logged in' ) ; } ; next ( ) ; } ; export const name = '/api/v1/accounts' ; export const router = Router ( ) ; router . get ( '/api/v1/accounts' , [ setupMetaverseAPI , accountFromAuthToken , procGetAccounts , finishMetaverseAPI ] ) ;