jp.ms.common.modules 1.0.55 → 1.0.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exception/global-exception-filter.js +5 -7
- package/dist/exception/global-exception-filter.js.map +1 -1
- package/dist/modules/main/main.controller.d.ts +1 -1
- package/dist/modules/main/main.controller.js +1 -1
- package/dist/modules/main/main.controller.js.map +1 -1
- package/dist/modules/main/main.service.d.ts +1 -1
- package/dist/modules/main/main.service.js +10 -3
- package/dist/modules/main/main.service.js.map +1 -1
- package/dist/modules/many-tables-tournament/many-tables-tournament.service.js +15 -21
- package/dist/modules/many-tables-tournament/many-tables-tournament.service.js.map +1 -1
- package/dist/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.service.d.ts +2 -0
- package/dist/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.service.js +11 -1
- package/dist/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.service.js.map +1 -1
- package/dist/modules/one-table-tournament/one-table-tournament.controller.d.ts +1 -1
- package/dist/modules/one-table-tournament/one-table-tournament.controller.js +1 -1
- package/dist/modules/one-table-tournament/one-table-tournament.module.js +6 -1
- package/dist/modules/one-table-tournament/one-table-tournament.module.js.map +1 -1
- package/dist/modules/one-table-tournament/one-table-tournament.service.d.ts +4 -2
- package/dist/modules/one-table-tournament/one-table-tournament.service.js +20 -8
- package/dist/modules/one-table-tournament/one-table-tournament.service.js.map +1 -1
- package/dist/modules/simple-rooms/simple-rooms.controller.d.ts +1 -1
- package/dist/modules/simple-rooms/simple-rooms.controller.js +2 -2
- package/dist/modules/simple-rooms/simple-rooms.controller.js.map +1 -1
- package/dist/modules/simple-rooms/simple-rooms.module.js +2 -1
- package/dist/modules/simple-rooms/simple-rooms.module.js.map +1 -1
- package/dist/modules/simple-rooms/simple-rooms.service.d.ts +4 -2
- package/dist/modules/simple-rooms/simple-rooms.service.js +20 -8
- package/dist/modules/simple-rooms/simple-rooms.service.js.map +1 -1
- package/dist/modules/simple-rooms-manager/simple-rooms-manager.service.js +1 -1
- package/dist/modules/simple-rooms-manager/simple-rooms-manager.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/exception/global-exception-filter.ts +4 -10
- package/src/modules/main/main.controller.ts +1 -1
- package/src/modules/main/main.service.ts +20 -3
- package/src/modules/many-tables-tournament/many-tables-tournament.service.ts +24 -39
- package/src/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.service.ts +22 -1
- package/src/modules/one-table-tournament/one-table-tournament.controller.ts +1 -1
- package/src/modules/one-table-tournament/one-table-tournament.module.ts +9 -1
- package/src/modules/one-table-tournament/one-table-tournament.service.ts +30 -8
- package/src/modules/simple-rooms/simple-rooms.controller.ts +6 -2
- package/src/modules/simple-rooms/simple-rooms.module.ts +5 -1
- package/src/modules/simple-rooms/simple-rooms.service.ts +32 -6
- package/src/modules/simple-rooms-manager/simple-rooms-manager.service.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jp.ms.common.modules",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.56",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"jp.common.models": "1.1.61",
|
|
17
17
|
"jp.common.utils": "1.0.9",
|
|
18
18
|
"jp.db.schemas": "2.2.25",
|
|
19
|
-
"jp.ms.common.engine": "3.0.
|
|
19
|
+
"jp.ms.common.engine": "3.0.35",
|
|
20
20
|
"mongoose": "9.1.5",
|
|
21
21
|
"nestjs-i18n": "10.5.1",
|
|
22
22
|
"node-schedule": "2.1.1",
|
|
@@ -23,16 +23,10 @@ export class GlobalExceptionFilter implements ExceptionFilter {
|
|
|
23
23
|
const ctx = host.switchToHttp();
|
|
24
24
|
const response = ctx.getResponse<Response>();
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
response,
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
case HttpException.name: {
|
|
34
|
-
return this.processHttpException(exception as HttpException, response);
|
|
35
|
-
}
|
|
26
|
+
if (exception instanceof HttpExceptionWithSnackbar) {
|
|
27
|
+
return this.processHttpExceptionWithSnackbar(exception, response);
|
|
28
|
+
} else if (exception instanceof HttpException) {
|
|
29
|
+
return this.processHttpException(exception, response);
|
|
36
30
|
}
|
|
37
31
|
|
|
38
32
|
response.status(HttpStatus.INTERNAL_SERVER_ERROR).json({
|
|
@@ -43,7 +43,7 @@ export class MainController {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
@Get('find_free_table')
|
|
46
|
-
findFreeTable(@Headers() headers: IAppHeaders): FindFreeTableDto {
|
|
46
|
+
findFreeTable(@Headers() headers: IAppHeaders): Promise<FindFreeTableDto> {
|
|
47
47
|
return this.mainService.findFreeTable(
|
|
48
48
|
headers.client_auth_token,
|
|
49
49
|
headers.client_language,
|
|
@@ -29,6 +29,7 @@ import { ManyTablesTournamentRoomsManagerService } from '../many-tables-tourname
|
|
|
29
29
|
import { EventsBusMainTablesSubscribeService } from '../event-bus/events-bus.main-tables.subscribe.service';
|
|
30
30
|
import {
|
|
31
31
|
ErrorCodeEnum,
|
|
32
|
+
NotEnoughMoneyForPurchaseException,
|
|
32
33
|
NotFoundFreeRoomForFastGameException,
|
|
33
34
|
} from '../../exception';
|
|
34
35
|
|
|
@@ -140,11 +141,16 @@ export class MainService {
|
|
|
140
141
|
return PlayerCheckStateDto.fromEntities(redirectUrl, player?.id ?? '');
|
|
141
142
|
}
|
|
142
143
|
|
|
143
|
-
findFreeTable(
|
|
144
|
+
async findFreeTable(
|
|
145
|
+
clientAuthToken: string,
|
|
146
|
+
lang: string,
|
|
147
|
+
): Promise<FindFreeTableDto> {
|
|
144
148
|
const player = this.playersManager.getPlayerById(clientAuthToken);
|
|
145
|
-
const
|
|
149
|
+
const table = this.simpleRoomsManager.getFreeFastGameRoom();
|
|
150
|
+
const tableId = table?.getId();
|
|
151
|
+
const user = await this.usersRepository.findById(player?.id ?? '');
|
|
146
152
|
|
|
147
|
-
if (!player || !tableId) {
|
|
153
|
+
if (!player || !table || !tableId || !user) {
|
|
148
154
|
throw new NotFoundFreeRoomForFastGameException(
|
|
149
155
|
new ErrorSnackbarComponent(
|
|
150
156
|
ErrorCodeEnum.NOT_FOUND_FREE_ROOM_FOR_FAST_GAME,
|
|
@@ -153,6 +159,17 @@ export class MainService {
|
|
|
153
159
|
);
|
|
154
160
|
}
|
|
155
161
|
|
|
162
|
+
if (user.balance < table.room.getTicketPrice()) {
|
|
163
|
+
throw new NotEnoughMoneyForPurchaseException(
|
|
164
|
+
new ErrorSnackbarComponent(
|
|
165
|
+
ErrorCodeEnum.NOT_ENOUGH_MONEY_FOR_PURCHASE,
|
|
166
|
+
this.options.i18n.t('common.server.message.code.4004', {
|
|
167
|
+
lang,
|
|
168
|
+
}),
|
|
169
|
+
),
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
156
173
|
return FindFreeTableDto.fromEntities(
|
|
157
174
|
AppScreenRouter.getSimpleRoomTablePath(tableId),
|
|
158
175
|
player.id,
|
|
@@ -9,10 +9,7 @@ import {
|
|
|
9
9
|
AppScreenRouter,
|
|
10
10
|
ErrorSnackbarComponent,
|
|
11
11
|
} from 'jp.common.models';
|
|
12
|
-
import {
|
|
13
|
-
ManyTablesTournamentMaster,
|
|
14
|
-
TournamentMaster,
|
|
15
|
-
} from 'jp.ms.common.engine';
|
|
12
|
+
import { TournamentMaster } from 'jp.ms.common.engine';
|
|
16
13
|
import { PurchaseRepository, UsersRepository } from 'jp.db.schemas';
|
|
17
14
|
|
|
18
15
|
import { BaseAppScreenDto } from '../../dto';
|
|
@@ -152,52 +149,40 @@ export class ManyTablesTournamentService {
|
|
|
152
149
|
player?.id ?? '',
|
|
153
150
|
);
|
|
154
151
|
|
|
155
|
-
if (player
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
player.tableId ?? '',
|
|
163
|
-
),
|
|
164
|
-
player.id,
|
|
165
|
-
);
|
|
166
|
-
} else if (tournament.isParticipant(player.id) && ticket?.amount) {
|
|
167
|
-
player.stack = ticket.amount;
|
|
168
|
-
|
|
169
|
-
tournament
|
|
170
|
-
.getRoomMaster<ManyTablesTournamentMaster>()
|
|
171
|
-
.onTournamentProcessAlonePlayer(tournament.getRoomMaster(), player);
|
|
172
|
-
|
|
173
|
-
return JoinTournamentDto.fromEntities(
|
|
174
|
-
AppScreenRouter.getManyTablesTournamentTablePath(
|
|
175
|
-
player.tableId ?? '',
|
|
176
|
-
),
|
|
177
|
-
player.id,
|
|
178
|
-
);
|
|
179
|
-
} else {
|
|
180
|
-
return JoinTournamentDto.fromEntities(
|
|
181
|
-
AppScreenRouter.getManyTablesTournamentTableListPath(tournamentId),
|
|
182
|
-
player.id,
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
} else if (tournament.getRoomMaster<TournamentMaster>().isWaiting()) {
|
|
152
|
+
if (!player || !tournament) {
|
|
153
|
+
throw new InternalServerErrorException();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (tournament.getRoomMaster<TournamentMaster>().isInProgress()) {
|
|
157
|
+
if (tournament.isParticipant(player.id) && ticket?.amount) {
|
|
158
|
+
player.stack = ticket.amount;
|
|
186
159
|
tournament.handleJoinTournament(player);
|
|
187
160
|
|
|
188
161
|
return JoinTournamentDto.fromEntities(
|
|
189
|
-
AppScreenRouter.
|
|
162
|
+
AppScreenRouter.getManyTablesTournamentTablePath(
|
|
163
|
+
player.tableId ?? '',
|
|
164
|
+
),
|
|
190
165
|
player.id,
|
|
191
166
|
);
|
|
192
167
|
} else {
|
|
193
168
|
return JoinTournamentDto.fromEntities(
|
|
194
|
-
AppScreenRouter.
|
|
169
|
+
AppScreenRouter.getManyTablesTournamentTableListPath(tournamentId),
|
|
195
170
|
player.id,
|
|
196
171
|
);
|
|
197
172
|
}
|
|
198
|
-
}
|
|
173
|
+
} else if (tournament.getRoomMaster<TournamentMaster>().isWaiting()) {
|
|
174
|
+
tournament.handleJoinTournament(player);
|
|
199
175
|
|
|
200
|
-
|
|
176
|
+
return JoinTournamentDto.fromEntities(
|
|
177
|
+
AppScreenRouter.getManyTablesTournamentStatusPath(tournament.getId()),
|
|
178
|
+
player.id,
|
|
179
|
+
);
|
|
180
|
+
} else {
|
|
181
|
+
return JoinTournamentDto.fromEntities(
|
|
182
|
+
AppScreenRouter.getManyTablesTournamentStatusPath(tournament.getId()),
|
|
183
|
+
player.id,
|
|
184
|
+
);
|
|
185
|
+
}
|
|
201
186
|
}
|
|
202
187
|
|
|
203
188
|
async leaveTournament(
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
GameTournamentFinishedEvent,
|
|
19
19
|
GameTournamentPlayerJoinedTheTournamentEvent,
|
|
20
20
|
GameTournamentPlayerLeavedTheTournamentEvent,
|
|
21
|
+
GameTournamentPlayerLostTournamentEvent,
|
|
21
22
|
GameTournamentStartedEvent,
|
|
22
23
|
GameTournamentWaitedEvent,
|
|
23
24
|
LocalService,
|
|
@@ -322,6 +323,12 @@ export class ManyTablesTournamentRoomsManagerService extends TournamentRoomsMana
|
|
|
322
323
|
this.handleRoomStatusUpdated(event as GamePlayerKickedOutTheTableEvent);
|
|
323
324
|
break;
|
|
324
325
|
}
|
|
326
|
+
case GameTournamentPlayerLostTournamentEvent.name: {
|
|
327
|
+
void this.handleGameTournamentPlayerLostTournamentEvent(
|
|
328
|
+
event as GameTournamentPlayerLostTournamentEvent,
|
|
329
|
+
);
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
325
332
|
case GameTournamentPlayerJoinedTheTournamentEvent.name:
|
|
326
333
|
case GameTournamentPlayerLeavedTheTournamentEvent.name:
|
|
327
334
|
case GameTournamentWaitedEvent.name: {
|
|
@@ -366,6 +373,20 @@ export class ManyTablesTournamentRoomsManagerService extends TournamentRoomsMana
|
|
|
366
373
|
private handleGamePlayerKickedOutTheTable = async (
|
|
367
374
|
event: GamePlayerKickedOutTheTableEvent,
|
|
368
375
|
) => {
|
|
376
|
+
await this.cancelTicket(event);
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
private handleGameTournamentPlayerLostTournamentEvent = async (
|
|
380
|
+
event: GameTournamentPlayerLostTournamentEvent,
|
|
381
|
+
) => {
|
|
382
|
+
await this.cancelTicket(event);
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
private async cancelTicket(
|
|
386
|
+
event:
|
|
387
|
+
| GamePlayerKickedOutTheTableEvent
|
|
388
|
+
| GameTournamentPlayerLostTournamentEvent,
|
|
389
|
+
) {
|
|
369
390
|
const tournament = this.getRoomById(event.roomId);
|
|
370
391
|
if (tournament?.isParticipant(event.playerId)) {
|
|
371
392
|
const ticket =
|
|
@@ -382,7 +403,7 @@ export class ManyTablesTournamentRoomsManagerService extends TournamentRoomsMana
|
|
|
382
403
|
|
|
383
404
|
tournament.handleLeaveTournament(event.player);
|
|
384
405
|
}
|
|
385
|
-
}
|
|
406
|
+
}
|
|
386
407
|
|
|
387
408
|
private handleRoomStatusUpdated = (
|
|
388
409
|
event:
|
|
@@ -86,7 +86,7 @@ export class OneTableTournamentController {
|
|
|
86
86
|
joinTournament(
|
|
87
87
|
@Param('tournamentId') tournamentId: string,
|
|
88
88
|
@Headers() headers: IAppHeaders,
|
|
89
|
-
): IBaseAppScreen {
|
|
89
|
+
): Promise<IBaseAppScreen> {
|
|
90
90
|
return this.tournamentService.joinTournament(tournamentId, headers);
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -4,6 +4,9 @@ import {
|
|
|
4
4
|
OneTableTournamentRoom,
|
|
5
5
|
OneTableTournamentRoomSchema,
|
|
6
6
|
OneTableTournamentRoomsRepository,
|
|
7
|
+
User,
|
|
8
|
+
UserSchema,
|
|
9
|
+
UsersRepository,
|
|
7
10
|
} from 'jp.db.schemas';
|
|
8
11
|
import {
|
|
9
12
|
GamePlayer,
|
|
@@ -27,9 +30,14 @@ import { OneTableTournamentModuleOptions } from './one-table-tournament.interfac
|
|
|
27
30
|
schema: OneTableTournamentRoomSchema,
|
|
28
31
|
},
|
|
29
32
|
]),
|
|
33
|
+
MongooseModule.forFeature([{ name: User.name, schema: UserSchema }]),
|
|
30
34
|
],
|
|
31
35
|
controllers: [OneTableTournamentController],
|
|
32
|
-
providers: [
|
|
36
|
+
providers: [
|
|
37
|
+
OneTableTournamentService,
|
|
38
|
+
OneTableTournamentRoomsRepository,
|
|
39
|
+
UsersRepository,
|
|
40
|
+
],
|
|
33
41
|
})
|
|
34
42
|
export class OneTableTournamentModule {
|
|
35
43
|
constructor(
|
|
@@ -8,11 +8,17 @@ import {
|
|
|
8
8
|
IBaseAppScreen,
|
|
9
9
|
IBaseMoveData,
|
|
10
10
|
IAppTableState,
|
|
11
|
+
ErrorSnackbarComponent,
|
|
11
12
|
} from 'jp.common.models';
|
|
13
|
+
import { UsersRepository } from 'jp.db.schemas';
|
|
12
14
|
|
|
13
15
|
import { BaseAppScreenDto } from '../../dto';
|
|
14
16
|
import { OneTableTournamentRoomsManagerService } from '../one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.service';
|
|
15
17
|
import { PlayersManagerService } from '../players-manager/players-manager.service';
|
|
18
|
+
import {
|
|
19
|
+
NotEnoughMoneyForPurchaseException,
|
|
20
|
+
ErrorCodeEnum,
|
|
21
|
+
} from '../../exception';
|
|
16
22
|
|
|
17
23
|
import { OneTableTournamentFactoryOptions } from './one-table-tournament.interfaces';
|
|
18
24
|
import { ONE_TABLE_TOURNAMENT_OPTIONS } from './one-table-tournament.constants';
|
|
@@ -23,6 +29,7 @@ export class OneTableTournamentService {
|
|
|
23
29
|
constructor(
|
|
24
30
|
private readonly oneTableRoomsManagerService: OneTableTournamentRoomsManagerService,
|
|
25
31
|
private readonly playersManager: PlayersManagerService,
|
|
32
|
+
private readonly usersRepository: UsersRepository,
|
|
26
33
|
@Inject(ONE_TABLE_TOURNAMENT_OPTIONS)
|
|
27
34
|
private readonly options: OneTableTournamentFactoryOptions,
|
|
28
35
|
) {}
|
|
@@ -112,22 +119,37 @@ export class OneTableTournamentService {
|
|
|
112
119
|
throw new InternalServerErrorException();
|
|
113
120
|
}
|
|
114
121
|
|
|
115
|
-
joinTournament(
|
|
122
|
+
async joinTournament(
|
|
123
|
+
tournamentId: string,
|
|
124
|
+
headers: IAppHeaders,
|
|
125
|
+
): Promise<IBaseAppScreen> {
|
|
116
126
|
const player = this.playersManager.getPlayerById(headers.client_auth_token);
|
|
117
127
|
const tournament =
|
|
118
128
|
this.oneTableRoomsManagerService.getRoomByTableId(tournamentId);
|
|
129
|
+
const user = await this.usersRepository.findById(player?.id ?? '');
|
|
119
130
|
|
|
120
|
-
if (player
|
|
121
|
-
|
|
131
|
+
if (!player || !tournament || !user) {
|
|
132
|
+
throw new InternalServerErrorException();
|
|
133
|
+
}
|
|
122
134
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
135
|
+
if (user.balance < tournament.getTicketPrice()) {
|
|
136
|
+
throw new NotEnoughMoneyForPurchaseException(
|
|
137
|
+
new ErrorSnackbarComponent(
|
|
138
|
+
ErrorCodeEnum.NOT_ENOUGH_MONEY_FOR_PURCHASE,
|
|
139
|
+
this.options.i18n.t('common.server.message.code.4004', {
|
|
140
|
+
lang: headers.client_language,
|
|
141
|
+
}),
|
|
142
|
+
),
|
|
127
143
|
);
|
|
128
144
|
}
|
|
129
145
|
|
|
130
|
-
|
|
146
|
+
tournament.handleJoinTournament(player);
|
|
147
|
+
|
|
148
|
+
return this.getStatusScreen(
|
|
149
|
+
tournamentId,
|
|
150
|
+
headers.client_language,
|
|
151
|
+
headers.client_auth_token,
|
|
152
|
+
);
|
|
131
153
|
}
|
|
132
154
|
|
|
133
155
|
leaveTournament(tournamentId: string, clientAuthToken: string): void {
|
|
@@ -28,8 +28,12 @@ export class SimpleRoomsController {
|
|
|
28
28
|
enterTheTable(
|
|
29
29
|
@Param('tableId') tableId: string,
|
|
30
30
|
@Headers() headers: IAppHeaders,
|
|
31
|
-
): IAppTableState {
|
|
32
|
-
return this.roomsService.enterTheTable(
|
|
31
|
+
): Promise<IAppTableState> {
|
|
32
|
+
return this.roomsService.enterTheTable(
|
|
33
|
+
tableId,
|
|
34
|
+
headers.client_auth_token,
|
|
35
|
+
headers.client_language,
|
|
36
|
+
);
|
|
33
37
|
}
|
|
34
38
|
|
|
35
39
|
@Post('table/exit/:tableId')
|
|
@@ -4,6 +4,9 @@ import {
|
|
|
4
4
|
SimpleRoom,
|
|
5
5
|
SimpleRoomSchema,
|
|
6
6
|
SimpleRoomsRepository,
|
|
7
|
+
User,
|
|
8
|
+
UserSchema,
|
|
9
|
+
UsersRepository,
|
|
7
10
|
} from 'jp.db.schemas';
|
|
8
11
|
|
|
9
12
|
import { SimpleRoomsController } from './simple-rooms.controller';
|
|
@@ -16,9 +19,10 @@ import { SimpleRoomsModuleOptions } from './simple-rooms.interfaces';
|
|
|
16
19
|
MongooseModule.forFeature([
|
|
17
20
|
{ name: SimpleRoom.name, schema: SimpleRoomSchema },
|
|
18
21
|
]),
|
|
22
|
+
MongooseModule.forFeature([{ name: User.name, schema: UserSchema }]),
|
|
19
23
|
],
|
|
20
24
|
controllers: [SimpleRoomsController],
|
|
21
|
-
providers: [SimpleRoomsService, SimpleRoomsRepository],
|
|
25
|
+
providers: [SimpleRoomsService, SimpleRoomsRepository, UsersRepository],
|
|
22
26
|
})
|
|
23
27
|
export class SimpleRoomsModule {
|
|
24
28
|
constructor() {}
|
|
@@ -3,10 +3,19 @@ import {
|
|
|
3
3
|
Injectable,
|
|
4
4
|
InternalServerErrorException,
|
|
5
5
|
} from '@nestjs/common';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
IBaseMoveData,
|
|
8
|
+
IAppTableState,
|
|
9
|
+
ErrorSnackbarComponent,
|
|
10
|
+
} from 'jp.common.models';
|
|
11
|
+
import { UsersRepository } from 'jp.db.schemas';
|
|
7
12
|
|
|
8
13
|
import { SimpleRoomsManagerService } from '../simple-rooms-manager';
|
|
9
14
|
import { PlayersManagerService } from '../players-manager';
|
|
15
|
+
import {
|
|
16
|
+
NotEnoughMoneyForPurchaseException,
|
|
17
|
+
ErrorCodeEnum,
|
|
18
|
+
} from '../../exception';
|
|
10
19
|
|
|
11
20
|
import { SIMPLE_ROOMS_OPTIONS } from './simple-rooms.constants';
|
|
12
21
|
import { SimpleRoomsFactoryOptions } from './simple-rooms.interfaces';
|
|
@@ -16,6 +25,7 @@ export class SimpleRoomsService {
|
|
|
16
25
|
constructor(
|
|
17
26
|
private readonly simpleRoomsManager: SimpleRoomsManagerService,
|
|
18
27
|
private readonly playersManager: PlayersManagerService,
|
|
28
|
+
private readonly usersRepository: UsersRepository,
|
|
19
29
|
@Inject(SIMPLE_ROOMS_OPTIONS)
|
|
20
30
|
private readonly options: SimpleRoomsFactoryOptions,
|
|
21
31
|
) {}
|
|
@@ -34,18 +44,34 @@ export class SimpleRoomsService {
|
|
|
34
44
|
throw new InternalServerErrorException();
|
|
35
45
|
}
|
|
36
46
|
|
|
37
|
-
enterTheTable(
|
|
47
|
+
async enterTheTable(
|
|
48
|
+
tableId: string,
|
|
49
|
+
clientAuthToken: string,
|
|
50
|
+
clientLanguage: string,
|
|
51
|
+
): Promise<IAppTableState> {
|
|
38
52
|
const player = this.playersManager.getPlayerById(clientAuthToken);
|
|
39
53
|
const room = this.simpleRoomsManager.getRoomByTableId(tableId);
|
|
40
54
|
const master = room?.getMasterById(tableId);
|
|
55
|
+
const user = await this.usersRepository.findById(player?.id ?? '');
|
|
41
56
|
|
|
42
|
-
if (player
|
|
43
|
-
|
|
57
|
+
if (!player || !room || !master || !user) {
|
|
58
|
+
throw new InternalServerErrorException();
|
|
59
|
+
}
|
|
44
60
|
|
|
45
|
-
|
|
61
|
+
if (user.balance < room.getTicketPrice()) {
|
|
62
|
+
throw new NotEnoughMoneyForPurchaseException(
|
|
63
|
+
new ErrorSnackbarComponent(
|
|
64
|
+
ErrorCodeEnum.NOT_ENOUGH_MONEY_FOR_PURCHASE,
|
|
65
|
+
this.options.i18n.t('common.server.message.code.4002', {
|
|
66
|
+
lang: clientLanguage,
|
|
67
|
+
}),
|
|
68
|
+
),
|
|
69
|
+
);
|
|
46
70
|
}
|
|
47
71
|
|
|
48
|
-
|
|
72
|
+
room.handleEnterTheTable(player, tableId);
|
|
73
|
+
|
|
74
|
+
return master.createGameStateDto(player);
|
|
49
75
|
}
|
|
50
76
|
|
|
51
77
|
exitTheTable(tableId: string, clientAuthToken: string): IAppTableState {
|
|
@@ -149,7 +149,7 @@ export class SimpleRoomsManagerService extends RoomsManagerService {
|
|
|
149
149
|
tableSize: room.tableSize,
|
|
150
150
|
tableType: room.tableType,
|
|
151
151
|
bet: room.bet,
|
|
152
|
-
ticketPrice: room.ticketPrice
|
|
152
|
+
ticketPrice: room.ticketPrice,
|
|
153
153
|
title: room.title,
|
|
154
154
|
subtitle: room.subtitle,
|
|
155
155
|
description: room.description,
|