'use strict' ; import Config from '@Base/config' ; import { Router , RequestHandler , Request , Response , NextFunction } from 'express' ; import { setupMetaverseAPI , finishMetaverseAPI , param1FromParams , placeFromParams } from '@Route-Tools/middleware' ; import { accountFromAuthToken } from '@Route-Tools/middleware' ; import { procGetPlacesPlaceId , procDeletePlacesPlaceId } from '../places/placeId' ; import { procPostPlaces } from '../places' ; import { buildPlaceInfo } from '@Route-Tools/Util' ; import { Places } from '@Entities/Places' ; import { Maturity } from '@Entities/Sets/Maturity' ; import { PaginationInfo } from '@Entities/EntityFilters/PaginationInfo' ; import { PlaceFilterInfo } from '@Entities/EntityFilters/PlaceFilterInfo' ; import { Domains } from '@Entities/Domains' ; const procGetPlaces = async ( req , resp , next ) => { if ( req . vAuthAccount ) { const pager = new PaginationInfo ( ) ; const placer = new PlaceFilterInfo ( ) ; pager . parametersFromRequest ( req ) ; placer . parametersFromRequest ( req ) ; const allPlaces = [ ] ; for await ( const place of Places . enumerateAsync ( placer , pager ) ) { if ( place . domainId ) { const aDomain = await Domains . getDomainWithId ( place . domainId ) ; if ( aDomain && aDomain . sponsorAccountId === req . vAuthAccount . id ) { allPlaces . push ( await buildPlaceInfo ( place ) ) ; } ; } ; } ; req . vRestResp . Data = { 'places' : allPlaces , 'maturity-categories' : Maturity . MaturityCategories } ; pager . addResponseFields ( req ) ; } else { req . vRestResp . respondFailure ( req . vAccountError ?? 'Not logged in' ) ; } ; next ( ) ; } ; export const name = '/api/v1/user/places' ; export const router = Router ( ) ; router . get ( '/api/v1/user/places' , [ setupMetaverseAPI , accountFromAuthToken , procGetPlaces , finishMetaverseAPI ] ) ; router . post ( '/api/v1/user/places' , [ setupMetaverseAPI , accountFromAuthToken , procPostPlaces , finishMetaverseAPI ] ) ; router . get ( '/api/v1/user/places/:placeId' , [ setupMetaverseAPI , accountFromAuthToken , placeFromParams , procGetPlacesPlaceId , finishMetaverseAPI ] ) ; router . delete ( '/api/v1/user/places/:placeId' , [ setupMetaverseAPI , accountFromAuthToken , placeFromParams , procDeletePlacesPlaceId , finishMetaverseAPI ] ) ;