'use strict' ; import { Router , RequestHandler , Request , Response , NextFunction } from 'express' ; import { setupMetaverseAPI , finishMetaverseAPI } from '@Route-Tools/middleware' ; import { accountFromAuthToken , param1FromParams } from '@Route-Tools/middleware' ; import { Accounts } from '@Entities/Accounts' ; import { PaginationInfo } from '@Entities/EntityFilters/PaginationInfo' ; import { VKeyedCollection } from '@Tools/vTypes' ; import { IsNullOrEmpty , IsNotNullOrEmpty } from '@Tools/Misc' ; const procGetUserConnections = async ( req , resp , next ) => { if ( req . vAuthAccount ) { const pager = new PaginationInfo ( ) ; pager . parametersFromRequest ( req ) ; let connections = await Accounts . getField ( req . vAuthToken , req . vAuthAccount , 'connections' , req . vAuthAccount ) ; connections = IsNullOrEmpty ( connections ) ? [ ] : connections ; req . vRestResp . Data = { 'connections' : connections } ; pager . addResponseFields ( req ) ; } else { req . vRestResp . respondFailure ( req . vAccountError ?? 'Not logged in' ) ; } ; next ( ) ; } ; const procPostUserConnections = async ( req , resp , next ) => { req . vRestResp . respondFailure ( 'cannot add connections this way' ) ; next ( ) ; } ; const procDeleteUserConnections = async ( req , resp , next ) => { if ( req . vAuthAccount ) { await Accounts . removeConnection ( req . vAuthAccount , req . vParam1 ) ; } else { req . vRestResp . respondFailure ( req . vAccountError ?? 'Not logged in' ) ; } ; next ( ) ; } ; export const name = '/api/v1/user/connections' ; export const router = Router ( ) ; router . get ( '/api/v1/user/connections' , [ setupMetaverseAPI , accountFromAuthToken , procGetUserConnections , finishMetaverseAPI ] ) ; router . post ( '/api/v1/user/connections' , [ setupMetaverseAPI , accountFromAuthToken , procPostUserConnections , finishMetaverseAPI ] ) ; router . delete ( '/api/v1/user/connections/:param1' , [ setupMetaverseAPI , accountFromAuthToken , param1FromParams , procDeleteUserConnections , finishMetaverseAPI ] ) ;