-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
amend.gateway.ts
115 lines (104 loc) · 3.17 KB
/
amend.gateway.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import {
SubscribeMessage,
WebSocketGateway,
WebSocketServer
} from '@nestjs/websockets'
import { Socket, Server } from 'socket.io'
import { AuthService, AmendService } from '../services'
import { Inject } from '@nestjs/common'
import { withTryCatch, withAuthentication, withResponse } from '../common'
import { IMessage } from '../../../interfaces'
@WebSocketGateway()
export class AmendGateway {
constructor(
@Inject('AuthService')
private readonly authService: AuthService,
@Inject('AmendService')
private readonly amendService: AmendService
) {}
@WebSocketServer()
io: Server
@SubscribeMessage('amend')
@withTryCatch
async handleAmend(client: Socket, message: IMessage<{ id: string }>) {
const response = await this.amendService.getAmend(message.data.id)
client.emit('amend/' + message.data.id, response)
}
@SubscribeMessage('postAmend')
@withResponse('postAmend')
@withTryCatch
@withAuthentication
async handlePostAmend(
client: Socket,
message: IMessage<{
name: string
description: string
patch: string
version: number
textID: string
}>
) {
return await this.amendService.postAmend(message.data, this.io)
}
@SubscribeMessage('upVoteAmend')
@withResponse('upVoteAmend')
@withTryCatch
@withAuthentication
async handleUpVoteAmend(client: Socket, message: IMessage<{ id: string }>) {
return await this.amendService.upVoteAmend(message.data, this.io)
}
@SubscribeMessage('downVoteAmend')
@withResponse('downVoteAmend')
@withTryCatch
@withAuthentication
async handleDownVoteAmend(client: Socket, message: IMessage<{ id: string }>) {
return await this.amendService.downVoteAmend(message.data, this.io)
}
@SubscribeMessage('unVoteAmend')
@withResponse('unVoteAmend')
@withTryCatch
@withAuthentication
async handleUnVoteAmend(client: Socket, message: IMessage<{ id: string }>) {
return await this.amendService.unVoteAmend(message.data, this.io)
}
@SubscribeMessage('postArgument')
@withResponse('postArgument')
@withTryCatch
@withAuthentication
async handlePostArgument(
client: Socket,
message: IMessage<{ amendID: string; text: string; type: string }>
) {
return await this.amendService.postArgument(message.data, this.io)
}
@SubscribeMessage('upVoteArgument')
@withResponse('upVoteArgument')
@withTryCatch
@withAuthentication
async handleUpVoteArgument(
client: Socket,
message: IMessage<{ amendID: string; argumentID: string }>
) {
return await this.amendService.upVoteArgument(message.data, this.io)
}
@SubscribeMessage('downVoteArgument')
@withResponse('downVoteArgument')
@withTryCatch
@withAuthentication
async handleDownVoteArgument(
client: Socket,
message: IMessage<{ amendID: string; argumentID: string }>
) {
return await this.amendService.downVoteArgument(message.data, this.io)
}
@SubscribeMessage('unVoteArgument')
@withResponse('unVoteArgument')
@withTryCatch
@withAuthentication
async handleUnVoteArgument(
client: Socket,
message: IMessage<{ amendID: string; argumentID: string }>
) {
return await this.amendService.unVoteArgument(message.data, this.io)
}
}