import { injectable , inject } from 'inversify' ; import { UserCommands , UserCommandService , GetEvents } from '@centsideas/schemas' ; import { ServiceServer } from '@centsideas/utils' ; import { RpcMethod , RpcServer , RPC_SERVER_FACTORY , RpcServerFactory } from '@centsideas/rpc' ; import { UserService } from './user.service' ; import { UserConfig } from './user.config' ; import { UserListener } from './user.listener' ; @ injectable ( ) export class UserServer extends ServiceServer implements UserCommands . Service { private rpcServer : RpcServer = this . rpcServerFactory ( { services : [ UserCommandService ] , handlerClassInstance : this , port : this . config . getNumber ( 'user.rpc.port' ) , } ) ; constructor ( private service , private config , private listener , @ inject ( RPC_SERVER_FACTORY ) private rpcServerFactory ) { super ( ) ; } @ RpcMethod ( UserCommandService ) rename ( { userId , username } ) { return this . service . rename ( userId , username ) ; } @ RpcMethod ( UserCommandService ) requestDeletion ( { userId } ) { return this . service . requestDeletion ( userId ) ; } @ RpcMethod ( UserCommandService ) confirmDeletion ( { token } ) { return this . service . confirmDeletion ( token ) ; } @ RpcMethod ( UserCommandService ) requestEmailChange ( { userId , newEmail } ) { return this . service . requestEmailChange ( userId , newEmail ) ; } @ RpcMethod ( UserCommandService ) confirmEmailChange ( { token } ) { return this . service . confirmEmailChange ( token ) ; } @ RpcMethod ( UserCommandService ) async getEvents ( { after , streamId } ) { const events = await this . service . getEvents ( after , streamId ) ; return { events } ; } @ RpcMethod ( UserCommandService ) async getPrivateEvents ( { after , streamId } ) { const events = await this . service . getPrivateEvents ( after , streamId ) ; return { events } ; } async healthcheck ( ) { return this . rpcServer . isRunning && this . listener . connected ; } async shutdownHandler ( ) { await Promise . all ( [ this . rpcServer . disconnect ( ) , this . listener . disconnect ( ) ] ) ; } }