1- import { Controller , Get , Logger , Param , Post , Request } from '@nestjs/common' ;
2- import { BrokerListClientResponse , GetBrokerStatusClientResponse } from '@api-interfaces' ;
1+ import { Body , Controller , Get , Logger , Param , Post , Put , Request } from '@nestjs/common' ;
2+ import {
3+ AddDbmtUserClientResponse ,
4+ AddDbmtUserRequest ,
5+ BrokerListClientResponse ,
6+ GetBrokerStatusClientResponse ,
7+ StartAllBrokersClientResponse ,
8+ StopAllBrokersClientResponse ,
9+ UpdateDbmtUserClientResponse ,
10+ UpdateDbmtUserRequest ,
11+ } from '@api-interfaces' ;
12+ import { validateRequiredFields } from '@util' ;
313import { BaseCmsResponse } from '@type' ;
414import { BrokerService } from './broker.service' ;
515
@@ -23,6 +33,105 @@ export class BrokerController {
2333
2434 constructor ( private readonly brokerService : BrokerService ) { }
2535
36+ /**
37+ * Start all brokers on a host (CMS task: startbroker).
38+ *
39+ * @route POST /:hostUid/broker/start-all
40+ * @param req - Request object containing user information
41+ * @param hostUid - Host unique identifier from path parameter
42+ * @returns StartAllBrokersClientResponse { success: true } on success
43+ * @example
44+ * // POST /host-uid/broker/start-all
45+ */
46+ @Post ( 'start-all' )
47+ async startAllBrokers (
48+ @Request ( ) req ,
49+ @Param ( 'hostUid' ) hostUid : string
50+ ) : Promise < StartAllBrokersClientResponse > {
51+ const userId = req . user . sub ;
52+ this . logger . log ( `Starting all brokers on host: ${ hostUid } ` ) ;
53+ return await this . brokerService . startAllBrokers ( userId , hostUid ) ;
54+ }
55+
56+ /**
57+ * Stop all brokers on a host (CMS task: stopbroker).
58+ *
59+ * @route POST /:hostUid/broker/stop-all
60+ * @param req - Request object containing user information
61+ * @param hostUid - Host unique identifier from path parameter
62+ * @returns StopAllBrokersClientResponse { success: true } on success
63+ * @example
64+ * // POST /host-uid/broker/stop-all
65+ */
66+ @Post ( 'stop-all' )
67+ async stopAllBrokers (
68+ @Request ( ) req ,
69+ @Param ( 'hostUid' ) hostUid : string
70+ ) : Promise < StopAllBrokersClientResponse > {
71+ const userId = req . user . sub ;
72+ this . logger . log ( `Stopping all brokers on host: ${ hostUid } ` ) ;
73+ return await this . brokerService . stopAllBrokers ( userId , hostUid ) ;
74+ }
75+
76+ /**
77+ * Add a DBMT (CMS) user on the host (CMS task: adddbmtuser).
78+ *
79+ * @route POST /:hostUid/broker/dbmt-user
80+ * @param req - Request object containing user information
81+ * @param hostUid - Host unique identifier from path parameter
82+ * @param body - targetid, password, casauth, dbcreate, statusmonitorauth
83+ * @returns AddDbmtUserClientResponse dblist and userlist
84+ * @example
85+ * // POST /host-uid/broker/dbmt-user
86+ * // Body: { "targetid": "test_user_2", "password": "1234", "casauth": "none", "dbcreate": "none", "statusmonitorauth": "none" }
87+ */
88+ @Post ( 'dbmt-user' )
89+ async addDbmtUser (
90+ @Request ( ) req ,
91+ @Param ( 'hostUid' ) hostUid : string ,
92+ @Body ( ) body : AddDbmtUserRequest
93+ ) : Promise < AddDbmtUserClientResponse > {
94+ const userId = req . user . sub ;
95+ validateRequiredFields (
96+ body ,
97+ [ 'targetid' , 'password' , 'casauth' , 'dbcreate' , 'statusmonitorauth' ] ,
98+ 'broker/dbmt-user' ,
99+ this . logger
100+ ) ;
101+ this . logger . log ( `Adding DBMT user: ${ body . targetid } on host: ${ hostUid } ` ) ;
102+ return await this . brokerService . addDbmtUser ( userId , hostUid , body ) ;
103+ }
104+
105+ /**
106+ * Update a DBMT (CMS) user on the host (CMS task: updatedbmtuser).
107+ *
108+ * @route PUT /:hostUid/broker/dbmt-user
109+ * @param req - Request object containing user information
110+ * @param hostUid - Host unique identifier from path parameter
111+ * @param body - targetid, casauth, dbcreate, statusmonitorauth (dbauth optional)
112+ * @returns UpdateDbmtUserClientResponse dblist and userlist
113+ * @example
114+ * // PUT /host-uid/broker/dbmt-user
115+ * // Body: { "targetid": "test_user_2", "casauth": "none", "dbcreate": "none", "statusmonitorauth": "none" }
116+ * // or with dbauth: { "targetid": "test_user_2", "dbauth": [], "casauth": "none", "dbcreate": "none", "statusmonitorauth": "none" }
117+ */
118+ @Put ( 'dbmt-user' )
119+ async updateDbmtUser (
120+ @Request ( ) req ,
121+ @Param ( 'hostUid' ) hostUid : string ,
122+ @Body ( ) body : UpdateDbmtUserRequest
123+ ) : Promise < UpdateDbmtUserClientResponse > {
124+ const userId = req . user . sub ;
125+ validateRequiredFields (
126+ body ,
127+ [ 'targetid' , 'casauth' , 'dbcreate' , 'statusmonitorauth' ] ,
128+ 'broker/dbmt-user' ,
129+ this . logger
130+ ) ;
131+ this . logger . log ( `Updating DBMT user: ${ body . targetid } on host: ${ hostUid } ` ) ;
132+ return await this . brokerService . updateDbmtUser ( userId , hostUid , body ) ;
133+ }
134+
26135 /**
27136 * Get list of brokers for a specific host.
28137 *
@@ -31,7 +140,7 @@ export class BrokerController {
31140 * @param hostUid - Host unique identifier from path parameter
32141 * @returns List of brokers
33142 * @example
34- * // POST /host-uid/broker/list
143+ * // GET /host-uid/broker/list
35144 */
36145 @Get ( 'list' )
37146 async getBrokers (
@@ -63,7 +172,7 @@ export class BrokerController {
63172 ) : Promise < BaseCmsResponse > {
64173 const userId = req . user . sub ;
65174
66- Logger . log ( `Stopping broker: ${ bname } on host: ${ hostUid } ` , 'BrokerController' ) ;
175+ this . logger . log ( `Stopping broker: ${ bname } on host: ${ hostUid } ` ) ;
67176 const response = await this . brokerService . stopBroker ( userId , hostUid , bname ) ;
68177 return response ;
69178 }
@@ -87,7 +196,7 @@ export class BrokerController {
87196 ) : Promise < BaseCmsResponse > {
88197 const userId = req . user . sub ;
89198
90- Logger . log ( `Starting broker: ${ bname } on host: ${ hostUid } ` , 'BrokerController' ) ;
199+ this . logger . log ( `Starting broker: ${ bname } on host: ${ hostUid } ` ) ;
91200 const response = await this . brokerService . startBroker ( userId , hostUid , bname ) ;
92201 return response ;
93202 }
@@ -111,7 +220,7 @@ export class BrokerController {
111220 ) : Promise < boolean > {
112221 const userId = req . user . sub ;
113222
114- Logger . log ( `Restarting broker: ${ bname } on host: ${ hostUid } ` , 'BrokerController' ) ;
223+ this . logger . log ( `Restarting broker: ${ bname } on host: ${ hostUid } ` ) ;
115224 const response : boolean = await this . brokerService . restartBroker ( userId , hostUid , bname ) ;
116225 return response ;
117226 }
@@ -135,7 +244,7 @@ export class BrokerController {
135244 ) : Promise < GetBrokerStatusClientResponse > {
136245 const userId = req . user . sub ;
137246
138- Logger . log ( `Getting broker status: ${ bname } on host: ${ hostUid } ` , 'BrokerController' ) ;
247+ this . logger . log ( `Getting broker status: ${ bname } on host: ${ hostUid } ` ) ;
139248 const response = await this . brokerService . getBrokerStatus ( userId , hostUid , bname ) ;
140249 return response ;
141250 }
0 commit comments