@@ -25,6 +25,7 @@ import { ToggleQuestionLikeSwagger } from './swagger/toggle-question.swagger';
2525import { BaseDto } from '@common/base.dto' ;
2626import { SessionTokenValidationGuard } from '@common/guards/session-token-validation.guard' ;
2727import { TransformInterceptor } from '@common/interceptors/transform.interceptor' ;
28+ import { requestSocket } from '@common/request-socket' ;
2829import {
2930 UpdateQuestionBodyDto ,
3031 UpdateQuestionClosedDto ,
@@ -38,16 +39,13 @@ import {
3839 UpdateQuestionClosedSwagger ,
3940 UpdateQuestionPinnedSwagger ,
4041} from '@questions/swagger/update-question.swagger' ;
41- import { SocketGateway } from '@socket/socket.gateway ' ;
42+ import { SOCKET_EVENTS } from '@socket/socket.constant ' ;
4243
4344@ApiTags ( 'Questions' )
4445@UseInterceptors ( TransformInterceptor )
4546@Controller ( 'questions' )
4647export class QuestionsController {
47- constructor (
48- private readonly questionsService : QuestionsService ,
49- private readonly socketGateway : SocketGateway ,
50- ) { }
48+ constructor ( private readonly questionsService : QuestionsService ) { }
5149
5250 @Get ( )
5351 @GetQuestionSwagger ( )
@@ -66,7 +64,8 @@ export class QuestionsController {
6664 const { sessionId, token } = createQuestionDto ;
6765 const resultForOwner = { question : createdQuestion } ;
6866 const resultForOther = { question : { ...createdQuestion , isOwner : false } } ;
69- this . socketGateway . broadcastNewQuestion ( sessionId , token , resultForOther ) ;
67+ const event = SOCKET_EVENTS . QUESTION_CREATED ;
68+ await requestSocket ( { sessionId, token, event, content : resultForOther } ) ;
7069 return resultForOwner ;
7170 }
7271
@@ -86,7 +85,8 @@ export class QuestionsController {
8685 ) ;
8786 const { sessionId, token } = updateQuestionBodyDto ;
8887 const result = { question : updatedQuestion } ;
89- this . socketGateway . broadcastQuestionUpdate ( sessionId , token , result ) ;
88+ const event = SOCKET_EVENTS . QUESTION_UPDATED ;
89+ await requestSocket ( { sessionId, token, event, content : result } ) ;
9090 return result ;
9191 }
9292
@@ -97,7 +97,8 @@ export class QuestionsController {
9797 const { sessionId, token } = data ;
9898 await this . questionsService . deleteQuestion ( questionId , req . question , data ) ;
9999 const resultForOther = { questionId } ;
100- this . socketGateway . broadcastQuestionDelete ( sessionId , token , resultForOther ) ;
100+ const event = SOCKET_EVENTS . QUESTION_DELETED ;
101+ await requestSocket ( { sessionId, token, event, content : resultForOther } ) ;
101102 return { } ;
102103 }
103104
@@ -112,7 +113,8 @@ export class QuestionsController {
112113 const updatedQuestion = await this . questionsService . updateQuestionPinned ( questionId , updateQuestionPinnedDto ) ;
113114 const { sessionId, token } = updateQuestionPinnedDto ;
114115 const result = { question : updatedQuestion } ;
115- this . socketGateway . broadcastQuestionUpdate ( sessionId , token , result ) ;
116+ const event = SOCKET_EVENTS . QUESTION_UPDATED ;
117+ await requestSocket ( { sessionId, token, event, content : result } ) ;
116118 return result ;
117119 }
118120
@@ -127,7 +129,8 @@ export class QuestionsController {
127129 const updatedQuestion = await this . questionsService . updateQuestionClosed ( questionId , updateQuestionClosedDto ) ;
128130 const { sessionId, token } = updateQuestionClosedDto ;
129131 const result = { question : updatedQuestion } ;
130- this . socketGateway . broadcastQuestionUpdate ( sessionId , token , result ) ;
132+ const event = SOCKET_EVENTS . QUESTION_UPDATED ;
133+ await requestSocket ( { sessionId, token, event, content : result } ) ;
131134 return result ;
132135 }
133136
@@ -143,7 +146,8 @@ export class QuestionsController {
143146 const { sessionId, token } = toggleQuestionLikeDto ;
144147 const resultForOwner = { liked, likesCount } ;
145148 const resultForOther = { questionId, liked : false , likesCount } ;
146- this . socketGateway . broadcastQuestionLike ( sessionId , token , resultForOther ) ;
149+ const event = SOCKET_EVENTS . QUESTION_LIKED ;
150+ await requestSocket ( { sessionId, token, event, content : resultForOther } ) ;
147151 return resultForOwner ;
148152 }
149153}
0 commit comments