jp.db.schemas 2.2.10 → 2.2.11
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/package.json +37 -37
- package/readme.md +3 -3
- package/src/index.ts +294 -294
- package/src/models/account-type.enum.ts +8 -8
- package/src/models/activity-log-user-login.interface.ts +10 -10
- package/src/models/activity-log.enum.ts +8 -8
- package/src/models/currency.enum.ts +6 -6
- package/src/models/rating-add-bulk-item.interface.ts +7 -7
- package/src/models/rating-monthly-result.interface.ts +11 -11
- package/src/models/tournament-participant.interface.ts +5 -5
- package/src/models/tournament-status.enum.ts +6 -6
- package/src/models/tournament-template.enum.ts +3 -3
- package/src/models/tournament-winner.interface.ts +7 -7
- package/src/models/users-balance-reason.enum.ts +8 -8
- package/src/repositories/achievement.repository.ts +17 -17
- package/src/repositories/activity-log.repository.ts +209 -209
- package/src/repositories/admin.repository.ts +20 -20
- package/src/repositories/article.repository.ts +24 -24
- package/src/repositories/banners.repository.ts +60 -60
- package/src/repositories/complains.repository.ts +31 -31
- package/src/repositories/daily-bonus.repository.ts +32 -32
- package/src/repositories/friend.repository.ts +24 -24
- package/src/repositories/game-result.repository.ts +19 -19
- package/src/repositories/game-statistic.repository.ts +25 -25
- package/src/repositories/index.ts +61 -61
- package/src/repositories/menu.repository.ts +19 -19
- package/src/repositories/notification.repository.ts +59 -59
- package/src/repositories/premium.repository.ts +16 -16
- package/src/repositories/products.repository.ts +30 -30
- package/src/repositories/purchase.repository.ts +111 -111
- package/src/repositories/rating.repository.ts +90 -90
- package/src/repositories/rooms.repository.ts +14 -14
- package/src/repositories/rule.repository.ts +14 -14
- package/src/repositories/scheduled-tournaments.repository.ts +35 -35
- package/src/repositories/servers.repository.ts +16 -16
- package/src/repositories/setting.repository.ts +24 -24
- package/src/repositories/settings-options.repository.ts +17 -17
- package/src/repositories/simple-rooms.repository.ts +16 -16
- package/src/repositories/tournament-many-tables-rooms.repository.ts +171 -171
- package/src/repositories/tournament-one-table-rooms.repository.ts +142 -142
- package/src/repositories/users-achievements.repository.ts +46 -46
- package/src/repositories/users-balances.repository.ts +65 -65
- package/src/repositories/users.repository.ts +153 -153
- package/src/repositories/welcome.repository.ts +16 -16
- package/src/schemas/achievement.schema.ts +40 -40
- package/src/schemas/activity_log.schema.ts +37 -37
- package/src/schemas/admin.schema.ts +22 -22
- package/src/schemas/article.schema.ts +37 -37
- package/src/schemas/banner.schema.ts +40 -40
- package/src/schemas/channel_message.schema.ts +32 -32
- package/src/schemas/complain.schema.ts +46 -46
- package/src/schemas/daily_bonus.schema.ts +49 -49
- package/src/schemas/feature.schema.ts +28 -28
- package/src/schemas/friend.schema.ts +49 -49
- package/src/schemas/game_result.schema.ts +68 -68
- package/src/schemas/game_statistic.schema.ts +40 -40
- package/src/schemas/menu.schema.ts +37 -37
- package/src/schemas/notification.schema.ts +61 -61
- package/src/schemas/premium.schema.ts +37 -37
- package/src/schemas/product.schema.ts +111 -111
- package/src/schemas/purchase.schema.ts +61 -61
- package/src/schemas/purchase_channel.schema.ts +32 -32
- package/src/schemas/rating.schema.ts +37 -37
- package/src/schemas/rooms.schema.ts +63 -63
- package/src/schemas/rule.schema.ts +37 -37
- package/src/schemas/scheduled_tournament.schema.ts +94 -94
- package/src/schemas/server.schema.ts +22 -22
- package/src/schemas/setting.schema.ts +49 -49
- package/src/schemas/settings_option.schema.ts +41 -41
- package/src/schemas/simple_rooms.schema.ts +49 -49
- package/src/schemas/tournament_many_tables_rooms.schema.ts +87 -87
- package/src/schemas/tournament_one_table_rooms.schema.ts +84 -84
- package/src/schemas/user.fb.schema.ts +33 -33
- package/src/schemas/user.google.schema.ts +24 -24
- package/src/schemas/user.ok.schema.ts +53 -53
- package/src/schemas/user.schema.ts +160 -160
- package/src/schemas/user.tg.schema.ts +30 -30
- package/src/schemas/user.vk.schema.ts +70 -70
- package/src/schemas/user.ya.schema.ts +24 -24
- package/src/schemas/users_achievement.schema.ts +41 -41
- package/src/schemas/users_balance.schema.ts +34 -34
- package/src/schemas/welcome.schema.ts +37 -37
- package/src/utils.ts +3 -3
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import { InjectModel } from '@nestjs/mongoose';
|
|
3
|
-
import { Model } from 'mongoose';
|
|
4
|
-
|
|
5
|
-
import { ScheduledTournament, ScheduledTournamentDocument } from '../';
|
|
6
|
-
|
|
7
|
-
@Injectable()
|
|
8
|
-
export class ScheduledTournamentsRepository {
|
|
9
|
-
constructor(
|
|
10
|
-
@InjectModel(ScheduledTournament.name)
|
|
11
|
-
private scheduledTournamentModel: Model<ScheduledTournamentDocument>,
|
|
12
|
-
) {}
|
|
13
|
-
|
|
14
|
-
async findAndCount(
|
|
15
|
-
limit: number,
|
|
16
|
-
skip: number,
|
|
17
|
-
): Promise<{
|
|
18
|
-
items: Array<ScheduledTournament>;
|
|
19
|
-
total: number;
|
|
20
|
-
}> {
|
|
21
|
-
const items = await this.scheduledTournamentModel
|
|
22
|
-
.find({ category: 'global' })
|
|
23
|
-
.sort({ date: -1 })
|
|
24
|
-
.limit(limit)
|
|
25
|
-
.skip(skip)
|
|
26
|
-
.exec();
|
|
27
|
-
|
|
28
|
-
const total = await this.scheduledTournamentModel
|
|
29
|
-
.find({ category: 'global' })
|
|
30
|
-
.countDocuments()
|
|
31
|
-
.exec();
|
|
32
|
-
|
|
33
|
-
return { items, total };
|
|
34
|
-
}
|
|
35
|
-
}
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { InjectModel } from '@nestjs/mongoose';
|
|
3
|
+
import { Model } from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { ScheduledTournament, ScheduledTournamentDocument } from '../';
|
|
6
|
+
|
|
7
|
+
@Injectable()
|
|
8
|
+
export class ScheduledTournamentsRepository {
|
|
9
|
+
constructor(
|
|
10
|
+
@InjectModel(ScheduledTournament.name)
|
|
11
|
+
private scheduledTournamentModel: Model<ScheduledTournamentDocument>,
|
|
12
|
+
) {}
|
|
13
|
+
|
|
14
|
+
async findAndCount(
|
|
15
|
+
limit: number,
|
|
16
|
+
skip: number,
|
|
17
|
+
): Promise<{
|
|
18
|
+
items: Array<ScheduledTournament>;
|
|
19
|
+
total: number;
|
|
20
|
+
}> {
|
|
21
|
+
const items = await this.scheduledTournamentModel
|
|
22
|
+
.find({ category: 'global' })
|
|
23
|
+
.sort({ date: -1 })
|
|
24
|
+
.limit(limit)
|
|
25
|
+
.skip(skip)
|
|
26
|
+
.exec();
|
|
27
|
+
|
|
28
|
+
const total = await this.scheduledTournamentModel
|
|
29
|
+
.find({ category: 'global' })
|
|
30
|
+
.countDocuments()
|
|
31
|
+
.exec();
|
|
32
|
+
|
|
33
|
+
return { items, total };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import { InjectModel } from '@nestjs/mongoose';
|
|
3
|
-
import { Model } from 'mongoose';
|
|
4
|
-
|
|
5
|
-
import { Server, ServerDocument } from '../';
|
|
6
|
-
|
|
7
|
-
@Injectable()
|
|
8
|
-
export class ServersRepository {
|
|
9
|
-
constructor(
|
|
10
|
-
@InjectModel(Server.name) private serverModel: Model<ServerDocument>,
|
|
11
|
-
) {}
|
|
12
|
-
|
|
13
|
-
async findServerByName(name: string): Promise<Server | null> {
|
|
14
|
-
return this.serverModel.findOne({ name }).exec();
|
|
15
|
-
}
|
|
16
|
-
}
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { InjectModel } from '@nestjs/mongoose';
|
|
3
|
+
import { Model } from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { Server, ServerDocument } from '../';
|
|
6
|
+
|
|
7
|
+
@Injectable()
|
|
8
|
+
export class ServersRepository {
|
|
9
|
+
constructor(
|
|
10
|
+
@InjectModel(Server.name) private serverModel: Model<ServerDocument>,
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
async findServerByName(name: string): Promise<Server | null> {
|
|
14
|
+
return this.serverModel.findOne({ name }).exec();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import { InjectModel } from '@nestjs/mongoose';
|
|
3
|
-
import { Model } from 'mongoose';
|
|
4
|
-
|
|
5
|
-
import { Setting, SettingDocument } from '..';
|
|
6
|
-
import { getChannelRegExpFilter } from '../utils';
|
|
7
|
-
|
|
8
|
-
@Injectable()
|
|
9
|
-
export class SettingRepository {
|
|
10
|
-
constructor(
|
|
11
|
-
@InjectModel(Setting.name) private settingModel: Model<SettingDocument>,
|
|
12
|
-
) {}
|
|
13
|
-
|
|
14
|
-
async findSettings(
|
|
15
|
-
channel: string,
|
|
16
|
-
game: string,
|
|
17
|
-
): Promise<Array<Setting> | null> {
|
|
18
|
-
return this.settingModel
|
|
19
|
-
.find({
|
|
20
|
-
channels: getChannelRegExpFilter(channel),
|
|
21
|
-
})
|
|
22
|
-
.exec();
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { InjectModel } from '@nestjs/mongoose';
|
|
3
|
+
import { Model } from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { Setting, SettingDocument } from '..';
|
|
6
|
+
import { getChannelRegExpFilter } from '../utils';
|
|
7
|
+
|
|
8
|
+
@Injectable()
|
|
9
|
+
export class SettingRepository {
|
|
10
|
+
constructor(
|
|
11
|
+
@InjectModel(Setting.name) private settingModel: Model<SettingDocument>,
|
|
12
|
+
) {}
|
|
13
|
+
|
|
14
|
+
async findSettings(
|
|
15
|
+
channel: string,
|
|
16
|
+
game: string,
|
|
17
|
+
): Promise<Array<Setting> | null> {
|
|
18
|
+
return this.settingModel
|
|
19
|
+
.find({
|
|
20
|
+
channels: getChannelRegExpFilter(channel),
|
|
21
|
+
})
|
|
22
|
+
.exec();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import { InjectModel } from '@nestjs/mongoose';
|
|
3
|
-
import { Model } from 'mongoose';
|
|
4
|
-
|
|
5
|
-
import { SettingsOption, SettingsOptionDocument } from '..';
|
|
6
|
-
|
|
7
|
-
@Injectable()
|
|
8
|
-
export class SettingsOptionsRepository {
|
|
9
|
-
constructor(
|
|
10
|
-
@InjectModel(SettingsOption.name)
|
|
11
|
-
private settingOptionsModel: Model<SettingsOptionDocument>,
|
|
12
|
-
) {}
|
|
13
|
-
|
|
14
|
-
async findSettingsOptions(): Promise<Array<SettingsOption> | null> {
|
|
15
|
-
return this.settingOptionsModel.find().exec();
|
|
16
|
-
}
|
|
17
|
-
}
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { InjectModel } from '@nestjs/mongoose';
|
|
3
|
+
import { Model } from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { SettingsOption, SettingsOptionDocument } from '..';
|
|
6
|
+
|
|
7
|
+
@Injectable()
|
|
8
|
+
export class SettingsOptionsRepository {
|
|
9
|
+
constructor(
|
|
10
|
+
@InjectModel(SettingsOption.name)
|
|
11
|
+
private settingOptionsModel: Model<SettingsOptionDocument>,
|
|
12
|
+
) {}
|
|
13
|
+
|
|
14
|
+
async findSettingsOptions(): Promise<Array<SettingsOption> | null> {
|
|
15
|
+
return this.settingOptionsModel.find().exec();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import { InjectModel } from '@nestjs/mongoose';
|
|
3
|
-
import { Model } from 'mongoose';
|
|
4
|
-
|
|
5
|
-
import { SimpleRoom, SimpleRoomDocument } from '../';
|
|
6
|
-
|
|
7
|
-
@Injectable()
|
|
8
|
-
export class SimpleRoomsRepository {
|
|
9
|
-
constructor(
|
|
10
|
-
@InjectModel(SimpleRoom.name) private roomModel: Model<SimpleRoomDocument>,
|
|
11
|
-
) {}
|
|
12
|
-
|
|
13
|
-
async findRooms(gameType: string): Promise<Array<SimpleRoomDocument>> {
|
|
14
|
-
return this.roomModel.find({ gameType }).exec();
|
|
15
|
-
}
|
|
16
|
-
}
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { InjectModel } from '@nestjs/mongoose';
|
|
3
|
+
import { Model } from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { SimpleRoom, SimpleRoomDocument } from '../';
|
|
6
|
+
|
|
7
|
+
@Injectable()
|
|
8
|
+
export class SimpleRoomsRepository {
|
|
9
|
+
constructor(
|
|
10
|
+
@InjectModel(SimpleRoom.name) private roomModel: Model<SimpleRoomDocument>,
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
async findRooms(gameType: string): Promise<Array<SimpleRoomDocument>> {
|
|
14
|
+
return this.roomModel.find({ gameType }).exec();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,171 +1,171 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import { InjectModel } from '@nestjs/mongoose';
|
|
3
|
-
import { Model } from 'mongoose';
|
|
4
|
-
import dayjs from 'dayjs';
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
TournamentManyTablesRoom,
|
|
8
|
-
TournamentManyTablesRoomDocument,
|
|
9
|
-
TournamentOneTableRoomDocument,
|
|
10
|
-
} from '../';
|
|
11
|
-
import { TournamentStatusEnum } from '../models/tournament-status.enum';
|
|
12
|
-
import { ITournamentWinner } from '../models/tournament-winner.interface';
|
|
13
|
-
import { TournamentTemplateEnum } from '../models/tournament-template.enum';
|
|
14
|
-
import { ITournamentParticipant } from '../models/tournament-participant.interface';
|
|
15
|
-
|
|
16
|
-
@Injectable()
|
|
17
|
-
export class TournamentManyTablesRoomsRepository {
|
|
18
|
-
constructor(
|
|
19
|
-
@InjectModel(TournamentManyTablesRoom.name)
|
|
20
|
-
private tournamentModel: Model<TournamentManyTablesRoomDocument>,
|
|
21
|
-
) {}
|
|
22
|
-
|
|
23
|
-
async findTournamentById(
|
|
24
|
-
tournamentId: string,
|
|
25
|
-
): Promise<TournamentManyTablesRoomDocument | null> {
|
|
26
|
-
return this.tournamentModel.findById(tournamentId).exec();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async findTemplateById(
|
|
30
|
-
templateId: string,
|
|
31
|
-
gameType: string,
|
|
32
|
-
): Promise<TournamentOneTableRoomDocument | null> {
|
|
33
|
-
return this.tournamentModel.findOne({ templateId, gameType }).exec();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async findActualTournaments(
|
|
37
|
-
gameType: string,
|
|
38
|
-
): Promise<Array<TournamentManyTablesRoomDocument>> {
|
|
39
|
-
return this.tournamentModel
|
|
40
|
-
.find({
|
|
41
|
-
$and: [
|
|
42
|
-
{
|
|
43
|
-
isTemplate: false,
|
|
44
|
-
gameType,
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
$or: [
|
|
48
|
-
{ status: TournamentStatusEnum.STATE_WAITING_FOR_START },
|
|
49
|
-
{ finishDate: { $gte: dayjs().subtract(1, 'day').toDate() } },
|
|
50
|
-
],
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
})
|
|
54
|
-
.exec();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async findWaitingTournamentByDate(
|
|
58
|
-
gameType: string,
|
|
59
|
-
startDate: Date,
|
|
60
|
-
endDate: Date,
|
|
61
|
-
): Promise<TournamentOneTableRoomDocument | null> {
|
|
62
|
-
return this.tournamentModel
|
|
63
|
-
.findOne({
|
|
64
|
-
gameType,
|
|
65
|
-
status: TournamentStatusEnum.STATE_WAITING_FOR_START,
|
|
66
|
-
isTemplate: false,
|
|
67
|
-
scheduleDate: { $gte: startDate, $lt: endDate },
|
|
68
|
-
})
|
|
69
|
-
.exec();
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async createTournament(
|
|
73
|
-
tournament: Partial<TournamentManyTablesRoom>,
|
|
74
|
-
): Promise<TournamentManyTablesRoomDocument> {
|
|
75
|
-
return this.tournamentModel.create(tournament);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async scheduleTournamentFromMasterTemplate(
|
|
79
|
-
gameType: string,
|
|
80
|
-
scheduleDate: Date,
|
|
81
|
-
): Promise<TournamentManyTablesRoomDocument> {
|
|
82
|
-
const masterTemplate = await this.findTemplateById(
|
|
83
|
-
TournamentTemplateEnum.MASTER,
|
|
84
|
-
gameType,
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
return this.createTournament({
|
|
88
|
-
title: masterTemplate.title,
|
|
89
|
-
subtitle: masterTemplate.subtitle,
|
|
90
|
-
description: masterTemplate.description,
|
|
91
|
-
tableSize: masterTemplate.tableSize,
|
|
92
|
-
bet: masterTemplate.bet,
|
|
93
|
-
ticketPrice: masterTemplate.ticketPrice,
|
|
94
|
-
roomType: masterTemplate.roomType,
|
|
95
|
-
gameType: masterTemplate.gameType,
|
|
96
|
-
rulesType: masterTemplate.rulesType,
|
|
97
|
-
deckType: masterTemplate.deckType,
|
|
98
|
-
maxParticipants: masterTemplate.maxParticipants,
|
|
99
|
-
participants: masterTemplate.participants,
|
|
100
|
-
status: masterTemplate.status,
|
|
101
|
-
winners: masterTemplate.winners,
|
|
102
|
-
createDate: new Date(),
|
|
103
|
-
isTemplate: false,
|
|
104
|
-
templateId: undefined,
|
|
105
|
-
scheduleDate,
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
async updateTournament(
|
|
110
|
-
tournamentId: string,
|
|
111
|
-
tournament: Partial<TournamentManyTablesRoom>,
|
|
112
|
-
): Promise<TournamentManyTablesRoomDocument> {
|
|
113
|
-
return this.tournamentModel
|
|
114
|
-
.findByIdAndUpdate(tournamentId, {
|
|
115
|
-
$set: {
|
|
116
|
-
...tournament,
|
|
117
|
-
},
|
|
118
|
-
})
|
|
119
|
-
.exec();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
async removeTournament(tournamentId: string): Promise<void> {
|
|
123
|
-
await this.tournamentModel.findByIdAndDelete(tournamentId);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
async startTournament(tournamentId: string): Promise<void> {
|
|
127
|
-
await this.tournamentModel
|
|
128
|
-
.findByIdAndUpdate(tournamentId, {
|
|
129
|
-
$set: {
|
|
130
|
-
startDate: new Date(),
|
|
131
|
-
status: TournamentStatusEnum.STATE_IN_PROGRESS,
|
|
132
|
-
},
|
|
133
|
-
})
|
|
134
|
-
.exec();
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
async cancelTournament(tournamentId: string): Promise<void> {
|
|
138
|
-
await this.tournamentModel
|
|
139
|
-
.findByIdAndUpdate(tournamentId, {
|
|
140
|
-
$set: {
|
|
141
|
-
finishDate: new Date(),
|
|
142
|
-
status: TournamentStatusEnum.STATE_CANCELLED,
|
|
143
|
-
},
|
|
144
|
-
})
|
|
145
|
-
.exec();
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
async finishTournament(
|
|
149
|
-
tournamentId: string,
|
|
150
|
-
winners: Array<ITournamentWinner>,
|
|
151
|
-
): Promise<void> {
|
|
152
|
-
await this.tournamentModel
|
|
153
|
-
.findByIdAndUpdate(tournamentId, {
|
|
154
|
-
$set: {
|
|
155
|
-
finishDate: new Date(),
|
|
156
|
-
status: TournamentStatusEnum.STATE_FINISHED,
|
|
157
|
-
winners,
|
|
158
|
-
},
|
|
159
|
-
})
|
|
160
|
-
.exec();
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
async addPlayerToParticipants(
|
|
164
|
-
tournamentId: string,
|
|
165
|
-
player: ITournamentParticipant,
|
|
166
|
-
): Promise<void> {
|
|
167
|
-
await this.tournamentModel
|
|
168
|
-
.findByIdAndUpdate(tournamentId, { $push: { participants: player } })
|
|
169
|
-
.exec();
|
|
170
|
-
}
|
|
171
|
-
}
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { InjectModel } from '@nestjs/mongoose';
|
|
3
|
+
import { Model } from 'mongoose';
|
|
4
|
+
import dayjs from 'dayjs';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
TournamentManyTablesRoom,
|
|
8
|
+
TournamentManyTablesRoomDocument,
|
|
9
|
+
TournamentOneTableRoomDocument,
|
|
10
|
+
} from '../';
|
|
11
|
+
import { TournamentStatusEnum } from '../models/tournament-status.enum';
|
|
12
|
+
import { ITournamentWinner } from '../models/tournament-winner.interface';
|
|
13
|
+
import { TournamentTemplateEnum } from '../models/tournament-template.enum';
|
|
14
|
+
import { ITournamentParticipant } from '../models/tournament-participant.interface';
|
|
15
|
+
|
|
16
|
+
@Injectable()
|
|
17
|
+
export class TournamentManyTablesRoomsRepository {
|
|
18
|
+
constructor(
|
|
19
|
+
@InjectModel(TournamentManyTablesRoom.name)
|
|
20
|
+
private tournamentModel: Model<TournamentManyTablesRoomDocument>,
|
|
21
|
+
) {}
|
|
22
|
+
|
|
23
|
+
async findTournamentById(
|
|
24
|
+
tournamentId: string,
|
|
25
|
+
): Promise<TournamentManyTablesRoomDocument | null> {
|
|
26
|
+
return this.tournamentModel.findById(tournamentId).exec();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async findTemplateById(
|
|
30
|
+
templateId: string,
|
|
31
|
+
gameType: string,
|
|
32
|
+
): Promise<TournamentOneTableRoomDocument | null> {
|
|
33
|
+
return this.tournamentModel.findOne({ templateId, gameType }).exec();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async findActualTournaments(
|
|
37
|
+
gameType: string,
|
|
38
|
+
): Promise<Array<TournamentManyTablesRoomDocument>> {
|
|
39
|
+
return this.tournamentModel
|
|
40
|
+
.find({
|
|
41
|
+
$and: [
|
|
42
|
+
{
|
|
43
|
+
isTemplate: false,
|
|
44
|
+
gameType,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
$or: [
|
|
48
|
+
{ status: TournamentStatusEnum.STATE_WAITING_FOR_START },
|
|
49
|
+
{ finishDate: { $gte: dayjs().subtract(1, 'day').toDate() } },
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
})
|
|
54
|
+
.exec();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async findWaitingTournamentByDate(
|
|
58
|
+
gameType: string,
|
|
59
|
+
startDate: Date,
|
|
60
|
+
endDate: Date,
|
|
61
|
+
): Promise<TournamentOneTableRoomDocument | null> {
|
|
62
|
+
return this.tournamentModel
|
|
63
|
+
.findOne({
|
|
64
|
+
gameType,
|
|
65
|
+
status: TournamentStatusEnum.STATE_WAITING_FOR_START,
|
|
66
|
+
isTemplate: false,
|
|
67
|
+
scheduleDate: { $gte: startDate, $lt: endDate },
|
|
68
|
+
})
|
|
69
|
+
.exec();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async createTournament(
|
|
73
|
+
tournament: Partial<TournamentManyTablesRoom>,
|
|
74
|
+
): Promise<TournamentManyTablesRoomDocument> {
|
|
75
|
+
return this.tournamentModel.create(tournament);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async scheduleTournamentFromMasterTemplate(
|
|
79
|
+
gameType: string,
|
|
80
|
+
scheduleDate: Date,
|
|
81
|
+
): Promise<TournamentManyTablesRoomDocument> {
|
|
82
|
+
const masterTemplate = await this.findTemplateById(
|
|
83
|
+
TournamentTemplateEnum.MASTER,
|
|
84
|
+
gameType,
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
return this.createTournament({
|
|
88
|
+
title: masterTemplate.title,
|
|
89
|
+
subtitle: masterTemplate.subtitle,
|
|
90
|
+
description: masterTemplate.description,
|
|
91
|
+
tableSize: masterTemplate.tableSize,
|
|
92
|
+
bet: masterTemplate.bet,
|
|
93
|
+
ticketPrice: masterTemplate.ticketPrice,
|
|
94
|
+
roomType: masterTemplate.roomType,
|
|
95
|
+
gameType: masterTemplate.gameType,
|
|
96
|
+
rulesType: masterTemplate.rulesType,
|
|
97
|
+
deckType: masterTemplate.deckType,
|
|
98
|
+
maxParticipants: masterTemplate.maxParticipants,
|
|
99
|
+
participants: masterTemplate.participants,
|
|
100
|
+
status: masterTemplate.status,
|
|
101
|
+
winners: masterTemplate.winners,
|
|
102
|
+
createDate: new Date(),
|
|
103
|
+
isTemplate: false,
|
|
104
|
+
templateId: undefined,
|
|
105
|
+
scheduleDate,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async updateTournament(
|
|
110
|
+
tournamentId: string,
|
|
111
|
+
tournament: Partial<TournamentManyTablesRoom>,
|
|
112
|
+
): Promise<TournamentManyTablesRoomDocument> {
|
|
113
|
+
return this.tournamentModel
|
|
114
|
+
.findByIdAndUpdate(tournamentId, {
|
|
115
|
+
$set: {
|
|
116
|
+
...tournament,
|
|
117
|
+
},
|
|
118
|
+
})
|
|
119
|
+
.exec();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async removeTournament(tournamentId: string): Promise<void> {
|
|
123
|
+
await this.tournamentModel.findByIdAndDelete(tournamentId);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async startTournament(tournamentId: string): Promise<void> {
|
|
127
|
+
await this.tournamentModel
|
|
128
|
+
.findByIdAndUpdate(tournamentId, {
|
|
129
|
+
$set: {
|
|
130
|
+
startDate: new Date(),
|
|
131
|
+
status: TournamentStatusEnum.STATE_IN_PROGRESS,
|
|
132
|
+
},
|
|
133
|
+
})
|
|
134
|
+
.exec();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async cancelTournament(tournamentId: string): Promise<void> {
|
|
138
|
+
await this.tournamentModel
|
|
139
|
+
.findByIdAndUpdate(tournamentId, {
|
|
140
|
+
$set: {
|
|
141
|
+
finishDate: new Date(),
|
|
142
|
+
status: TournamentStatusEnum.STATE_CANCELLED,
|
|
143
|
+
},
|
|
144
|
+
})
|
|
145
|
+
.exec();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async finishTournament(
|
|
149
|
+
tournamentId: string,
|
|
150
|
+
winners: Array<ITournamentWinner>,
|
|
151
|
+
): Promise<void> {
|
|
152
|
+
await this.tournamentModel
|
|
153
|
+
.findByIdAndUpdate(tournamentId, {
|
|
154
|
+
$set: {
|
|
155
|
+
finishDate: new Date(),
|
|
156
|
+
status: TournamentStatusEnum.STATE_FINISHED,
|
|
157
|
+
winners,
|
|
158
|
+
},
|
|
159
|
+
})
|
|
160
|
+
.exec();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async addPlayerToParticipants(
|
|
164
|
+
tournamentId: string,
|
|
165
|
+
player: ITournamentParticipant,
|
|
166
|
+
): Promise<void> {
|
|
167
|
+
await this.tournamentModel
|
|
168
|
+
.findByIdAndUpdate(tournamentId, { $push: { participants: player } })
|
|
169
|
+
.exec();
|
|
170
|
+
}
|
|
171
|
+
}
|