ballrush-core 0.5.4 → 0.6.1
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/domain/event.d.ts +3 -4
- package/dist/domain/event.js +6 -11
- package/dist/domain/season.d.ts +8 -2
- package/dist/domain/season.js +13 -3
- package/dist/mongo/schemas/event.schema.d.ts +1 -1
- package/dist/mongo/schemas/event.schema.js +1 -1
- package/dist/mongo/schemas/season.schema.d.ts +2 -1
- package/dist/mongo/schemas/season.schema.js +8 -0
- package/dist/ports/events.repository.d.ts +1 -1
- package/dist/repositories/mongo/event.mapper.js +2 -2
- package/dist/repositories/mongo/season.mapper.js +2 -0
- package/dist/repositories/mongo/season.repository.js +3 -5
- package/package.json +1 -1
package/dist/domain/event.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export declare class Event {
|
|
|
10
10
|
private matches;
|
|
11
11
|
private readonly createdBy;
|
|
12
12
|
private isRatingApplied;
|
|
13
|
-
private
|
|
13
|
+
private seasonId;
|
|
14
14
|
private reportMessageId?;
|
|
15
15
|
private status;
|
|
16
16
|
private constructor();
|
|
@@ -20,7 +20,7 @@ export declare class Event {
|
|
|
20
20
|
templateId: number;
|
|
21
21
|
date: Date;
|
|
22
22
|
createdBy: number;
|
|
23
|
-
|
|
23
|
+
seasonId: string;
|
|
24
24
|
participants?: ParticipantEvent[];
|
|
25
25
|
teams?: Team[];
|
|
26
26
|
matches?: Match[];
|
|
@@ -35,14 +35,13 @@ export declare class Event {
|
|
|
35
35
|
getMessageId(): number;
|
|
36
36
|
getReportMessageId(): number | undefined;
|
|
37
37
|
getDate(): Date;
|
|
38
|
-
|
|
38
|
+
getSeasonId(): string;
|
|
39
39
|
getParticipants(): ParticipantEvent[];
|
|
40
40
|
getTeams(): Team[];
|
|
41
41
|
getMatches(): Match[];
|
|
42
42
|
getCreatedBy(): number;
|
|
43
43
|
getStatus(): EventStatus;
|
|
44
44
|
getIsRatingApplied(): boolean;
|
|
45
|
-
renameSeason(newName: string): void;
|
|
46
45
|
reschedule(newDate: Date): void;
|
|
47
46
|
attachMessage(messageId: number): void;
|
|
48
47
|
attachReportMessage(reportMessageId: number): void;
|
package/dist/domain/event.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Event = void 0;
|
|
4
4
|
class Event {
|
|
5
|
-
constructor(eventId, groupId, messageId, templateId, date, participants, teams, matches, createdBy, isRatingApplied,
|
|
5
|
+
constructor(eventId, groupId, messageId, templateId, date, participants, teams, matches, createdBy, isRatingApplied, seasonId, reportMessageId, status = "active") {
|
|
6
6
|
this.eventId = eventId;
|
|
7
7
|
this.groupId = groupId;
|
|
8
8
|
this.messageId = messageId;
|
|
@@ -13,15 +13,15 @@ class Event {
|
|
|
13
13
|
this.matches = matches;
|
|
14
14
|
this.createdBy = createdBy;
|
|
15
15
|
this.isRatingApplied = isRatingApplied;
|
|
16
|
-
this.
|
|
16
|
+
this.seasonId = seasonId;
|
|
17
17
|
this.reportMessageId = reportMessageId;
|
|
18
18
|
this.status = status;
|
|
19
19
|
}
|
|
20
20
|
static create(params) {
|
|
21
|
-
if (!params.
|
|
22
|
-
throw new Error("Event must have a season
|
|
21
|
+
if (!params.seasonId) {
|
|
22
|
+
throw new Error("Event must have a season ID");
|
|
23
23
|
}
|
|
24
|
-
return new Event(params.eventId, params.groupId, params.messageId ?? 0, params.templateId, params.date, params.participants ?? [], params.teams ?? [], params.matches ?? [], params.createdBy, params.isRatingApplied ?? false, params.
|
|
24
|
+
return new Event(params.eventId, params.groupId, params.messageId ?? 0, params.templateId, params.date, params.participants ?? [], params.teams ?? [], params.matches ?? [], params.createdBy, params.isRatingApplied ?? false, params.seasonId, params.reportMessageId, params.status ?? "active");
|
|
25
25
|
}
|
|
26
26
|
getEventId() { return this.eventId; }
|
|
27
27
|
getGroupId() { return this.groupId; }
|
|
@@ -29,18 +29,13 @@ class Event {
|
|
|
29
29
|
getMessageId() { return this.messageId; }
|
|
30
30
|
getReportMessageId() { return this.reportMessageId; }
|
|
31
31
|
getDate() { return this.date; }
|
|
32
|
-
|
|
32
|
+
getSeasonId() { return this.seasonId; }
|
|
33
33
|
getParticipants() { return this.participants; }
|
|
34
34
|
getTeams() { return this.teams; }
|
|
35
35
|
getMatches() { return this.matches; }
|
|
36
36
|
getCreatedBy() { return this.createdBy; }
|
|
37
37
|
getStatus() { return this.status; }
|
|
38
38
|
getIsRatingApplied() { return this.isRatingApplied; }
|
|
39
|
-
renameSeason(newName) {
|
|
40
|
-
if (!newName)
|
|
41
|
-
throw new Error("Season name cannot be empty");
|
|
42
|
-
this.seasonName = newName;
|
|
43
|
-
}
|
|
44
39
|
reschedule(newDate) {
|
|
45
40
|
this.date = newDate;
|
|
46
41
|
}
|
package/dist/domain/season.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type SeasonStatus = 'upcoming' | 'in_progress' | 'ended';
|
|
2
|
+
export type SeasonType = 'system' | 'group';
|
|
2
3
|
export declare class Season {
|
|
3
4
|
private seasonId;
|
|
4
5
|
private name;
|
|
@@ -7,12 +8,13 @@ export declare class Season {
|
|
|
7
8
|
private endDate;
|
|
8
9
|
private status;
|
|
9
10
|
private isPublic;
|
|
11
|
+
private seasonType;
|
|
10
12
|
private description?;
|
|
11
13
|
private groupId?;
|
|
12
14
|
private createdBy?;
|
|
13
15
|
private createdAt?;
|
|
14
16
|
private updatedAt?;
|
|
15
|
-
constructor(seasonId: string, name: string, year: number, startDate: Date, endDate: Date, status: SeasonStatus, isPublic: boolean, description?: string | undefined, groupId?: number | undefined, createdBy?: number | undefined, createdAt?: Date | undefined, updatedAt?: Date | undefined);
|
|
17
|
+
constructor(seasonId: string, name: string, year: number, startDate: Date, endDate: Date, status: SeasonStatus, isPublic: boolean, seasonType: SeasonType, description?: string | undefined, groupId?: number | undefined, createdBy?: number | undefined, createdAt?: Date | undefined, updatedAt?: Date | undefined);
|
|
16
18
|
static create(p: {
|
|
17
19
|
seasonId: string;
|
|
18
20
|
name: string;
|
|
@@ -20,7 +22,8 @@ export declare class Season {
|
|
|
20
22
|
startDate: Date;
|
|
21
23
|
endDate: Date;
|
|
22
24
|
status?: SeasonStatus;
|
|
23
|
-
isPublic
|
|
25
|
+
isPublic: boolean;
|
|
26
|
+
seasonType: SeasonType;
|
|
24
27
|
description?: string;
|
|
25
28
|
groupId?: number;
|
|
26
29
|
createdBy?: number;
|
|
@@ -50,6 +53,7 @@ export declare class Season {
|
|
|
50
53
|
getEndDate(): Date;
|
|
51
54
|
getStatus(): SeasonStatus;
|
|
52
55
|
getIsPublic(): boolean;
|
|
56
|
+
getSeasonType(): SeasonType;
|
|
53
57
|
getDescription(): string | undefined;
|
|
54
58
|
getGroupId(): number | undefined;
|
|
55
59
|
getCreatedBy(): number | undefined;
|
|
@@ -61,6 +65,7 @@ export declare class Season {
|
|
|
61
65
|
setEndDate(endDate: Date): void;
|
|
62
66
|
setStatus(status: SeasonStatus): void;
|
|
63
67
|
setIsPublic(isPublic: boolean): void;
|
|
68
|
+
setSeasonType(seasonType: SeasonType): void;
|
|
64
69
|
setDescription(description?: string): void;
|
|
65
70
|
setGroupId(groupId?: number): void;
|
|
66
71
|
setCreatedBy(createdBy?: number): void;
|
|
@@ -72,6 +77,7 @@ export declare class Season {
|
|
|
72
77
|
endDate: Date;
|
|
73
78
|
status: SeasonStatus;
|
|
74
79
|
isPublic: boolean;
|
|
80
|
+
seasonType: SeasonType;
|
|
75
81
|
description: string | undefined;
|
|
76
82
|
groupId: number | undefined;
|
|
77
83
|
createdBy: number | undefined;
|
package/dist/domain/season.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Season = void 0;
|
|
4
4
|
class Season {
|
|
5
|
-
constructor(seasonId, name, year, startDate, endDate, status, isPublic, description, groupId, createdBy, createdAt, updatedAt) {
|
|
5
|
+
constructor(seasonId, name, year, startDate, endDate, status, isPublic, seasonType, description, groupId, createdBy, createdAt, updatedAt) {
|
|
6
6
|
this.seasonId = seasonId;
|
|
7
7
|
this.name = name;
|
|
8
8
|
this.year = year;
|
|
@@ -10,6 +10,7 @@ class Season {
|
|
|
10
10
|
this.endDate = endDate;
|
|
11
11
|
this.status = status;
|
|
12
12
|
this.isPublic = isPublic;
|
|
13
|
+
this.seasonType = seasonType;
|
|
13
14
|
this.description = description;
|
|
14
15
|
this.groupId = groupId;
|
|
15
16
|
this.createdBy = createdBy;
|
|
@@ -29,10 +30,13 @@ class Season {
|
|
|
29
30
|
throw new Error("endDate is required");
|
|
30
31
|
if (p.startDate >= p.endDate)
|
|
31
32
|
throw new Error("startDate must be before endDate");
|
|
33
|
+
if (p.isPublic === undefined)
|
|
34
|
+
throw new Error("isPublic is required");
|
|
35
|
+
if (!p.seasonType)
|
|
36
|
+
throw new Error("seasonType is required");
|
|
32
37
|
// Если статус не указан, вычисляем автоматически
|
|
33
38
|
const status = p.status ?? Season.calculateStatusFromDates(p.startDate, p.endDate);
|
|
34
|
-
return new Season(p.seasonId, p.name, p.year, p.startDate, p.endDate, status, p.isPublic
|
|
35
|
-
p.description, p.groupId, p.createdBy, p.createdAt ?? new Date(), p.updatedAt ?? new Date());
|
|
39
|
+
return new Season(p.seasonId, p.name, p.year, p.startDate, p.endDate, status, p.isPublic, p.seasonType, p.description, p.groupId, p.createdBy, p.createdAt ?? new Date(), p.updatedAt ?? new Date());
|
|
36
40
|
}
|
|
37
41
|
/**
|
|
38
42
|
* Вычисляет статус сезона на основе дат
|
|
@@ -71,6 +75,7 @@ class Season {
|
|
|
71
75
|
getEndDate() { return this.endDate; }
|
|
72
76
|
getStatus() { return this.status; }
|
|
73
77
|
getIsPublic() { return this.isPublic; }
|
|
78
|
+
getSeasonType() { return this.seasonType; }
|
|
74
79
|
getDescription() { return this.description; }
|
|
75
80
|
getGroupId() { return this.groupId; }
|
|
76
81
|
getCreatedBy() { return this.createdBy; }
|
|
@@ -109,6 +114,10 @@ class Season {
|
|
|
109
114
|
this.isPublic = isPublic;
|
|
110
115
|
this.updatedAt = new Date();
|
|
111
116
|
}
|
|
117
|
+
setSeasonType(seasonType) {
|
|
118
|
+
this.seasonType = seasonType;
|
|
119
|
+
this.updatedAt = new Date();
|
|
120
|
+
}
|
|
112
121
|
setDescription(description) {
|
|
113
122
|
this.description = description;
|
|
114
123
|
this.updatedAt = new Date();
|
|
@@ -130,6 +139,7 @@ class Season {
|
|
|
130
139
|
endDate: this.endDate,
|
|
131
140
|
status: this.status,
|
|
132
141
|
isPublic: this.isPublic,
|
|
142
|
+
seasonType: this.seasonType,
|
|
133
143
|
description: this.description,
|
|
134
144
|
groupId: this.groupId,
|
|
135
145
|
createdBy: this.createdBy,
|
|
@@ -39,7 +39,7 @@ function createEventSchema() {
|
|
|
39
39
|
messageId: { type: Number, required: true },
|
|
40
40
|
templateId: { type: Number, required: true },
|
|
41
41
|
date: { type: Date, required: true },
|
|
42
|
-
|
|
42
|
+
seasonId: { type: String, required: true },
|
|
43
43
|
createdBy: { type: Number, required: true },
|
|
44
44
|
participants: { type: [ParticipantSchema], default: [] },
|
|
45
45
|
teams: { type: [TeamSchema], default: [] },
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema } from "mongoose";
|
|
2
|
-
import { SeasonStatus } from "../../domain/season";
|
|
2
|
+
import { SeasonStatus, SeasonType } from "../../domain/season";
|
|
3
3
|
export interface SeasonDoc {
|
|
4
4
|
seasonId: string;
|
|
5
5
|
name: string;
|
|
@@ -8,6 +8,7 @@ export interface SeasonDoc {
|
|
|
8
8
|
endDate: Date;
|
|
9
9
|
status: SeasonStatus;
|
|
10
10
|
isPublic: boolean;
|
|
11
|
+
seasonType: SeasonType;
|
|
11
12
|
description?: string;
|
|
12
13
|
groupId?: number;
|
|
13
14
|
createdBy?: number;
|
|
@@ -43,6 +43,13 @@ function createSeasonSchema() {
|
|
|
43
43
|
default: true,
|
|
44
44
|
index: true
|
|
45
45
|
},
|
|
46
|
+
seasonType: {
|
|
47
|
+
type: String,
|
|
48
|
+
enum: ['system', 'group'],
|
|
49
|
+
required: true,
|
|
50
|
+
default: 'system',
|
|
51
|
+
index: true
|
|
52
|
+
},
|
|
46
53
|
description: {
|
|
47
54
|
type: String,
|
|
48
55
|
required: false
|
|
@@ -68,6 +75,7 @@ function createSeasonSchema() {
|
|
|
68
75
|
timestamps: true, // Автоматически обновляет createdAt и updatedAt
|
|
69
76
|
});
|
|
70
77
|
// Compound indexes для оптимизации запросов
|
|
78
|
+
schema.index({ seasonType: 1, status: 1 }); // Для поиска системных/групповых сезонов
|
|
71
79
|
schema.index({ isPublic: 1, status: 1 }); // Для поиска публичных активных сезонов
|
|
72
80
|
schema.index({ groupId: 1, status: 1 }); // Для поиска сезонов группы
|
|
73
81
|
schema.index({ year: 1, status: 1 }); // Для поиска по году и статусу
|
|
@@ -15,7 +15,7 @@ function toDomain(doc) {
|
|
|
15
15
|
matches: doc.matches,
|
|
16
16
|
createdBy: doc.createdBy,
|
|
17
17
|
isRatingApplied: doc.isRatingApplied,
|
|
18
|
-
|
|
18
|
+
seasonId: doc.seasonId,
|
|
19
19
|
reportMessageId: doc.reportMessageId,
|
|
20
20
|
status: doc.status,
|
|
21
21
|
});
|
|
@@ -32,7 +32,7 @@ function toDoc(event) {
|
|
|
32
32
|
teams: event.getTeams(),
|
|
33
33
|
matches: event.getMatches(),
|
|
34
34
|
status: event.getStatus(),
|
|
35
|
-
|
|
35
|
+
seasonId: event.getSeasonId(),
|
|
36
36
|
isRatingApplied: event.getIsRatingApplied(),
|
|
37
37
|
reportMessageId: event.getReportMessageId(),
|
|
38
38
|
};
|
|
@@ -12,6 +12,7 @@ function toDomain(doc) {
|
|
|
12
12
|
endDate: new Date(doc.endDate),
|
|
13
13
|
status: doc.status,
|
|
14
14
|
isPublic: doc.isPublic,
|
|
15
|
+
seasonType: doc.seasonType,
|
|
15
16
|
description: doc.description,
|
|
16
17
|
groupId: doc.groupId,
|
|
17
18
|
createdBy: doc.createdBy,
|
|
@@ -28,6 +29,7 @@ function toDoc(entity) {
|
|
|
28
29
|
endDate: entity.getEndDate(),
|
|
29
30
|
status: entity.getStatus(),
|
|
30
31
|
isPublic: entity.getIsPublic(),
|
|
32
|
+
seasonType: entity.getSeasonType(),
|
|
31
33
|
description: entity.getDescription(),
|
|
32
34
|
groupId: entity.getGroupId(),
|
|
33
35
|
createdBy: entity.getCreatedBy(),
|
|
@@ -23,7 +23,7 @@ class MongoSeasonsRepository {
|
|
|
23
23
|
}
|
|
24
24
|
async getPublicSeasons() {
|
|
25
25
|
try {
|
|
26
|
-
const docs = await this.Model.find({
|
|
26
|
+
const docs = await this.Model.find({ seasonType: 'system' }).sort({ year: -1, startDate: -1 }).lean();
|
|
27
27
|
return docs.map(d => (0, season_mapper_1.toDomain)(d));
|
|
28
28
|
}
|
|
29
29
|
catch (error) {
|
|
@@ -35,10 +35,8 @@ class MongoSeasonsRepository {
|
|
|
35
35
|
if (!groupId || groupId === 0) {
|
|
36
36
|
throw new errors_1.ValidationError('Season', 'groupId', groupId, 'must be a non-zero number');
|
|
37
37
|
}
|
|
38
|
-
// Возвращаем публичные сезоны + сезоны конкретной группы
|
|
39
38
|
const docs = await this.Model.find({
|
|
40
39
|
$or: [
|
|
41
|
-
{ isPublic: true },
|
|
42
40
|
{ groupId: groupId }
|
|
43
41
|
]
|
|
44
42
|
}).sort({ year: -1, startDate: -1 }).lean();
|
|
@@ -178,7 +176,7 @@ class MongoSeasonsRepository {
|
|
|
178
176
|
throw new errors_1.ValidationError('Season', 'groupId', groupId, 'must be a non-zero number');
|
|
179
177
|
}
|
|
180
178
|
filter.$or = [
|
|
181
|
-
{
|
|
179
|
+
{ seasonType: 'system' },
|
|
182
180
|
{ groupId: groupId }
|
|
183
181
|
];
|
|
184
182
|
}
|
|
@@ -199,7 +197,7 @@ class MongoSeasonsRepository {
|
|
|
199
197
|
throw new errors_1.ValidationError('Season', 'groupId', groupId, 'must be a non-zero number');
|
|
200
198
|
}
|
|
201
199
|
filter.$or = [
|
|
202
|
-
{
|
|
200
|
+
{ seasonType: 'system' },
|
|
203
201
|
{ groupId: groupId }
|
|
204
202
|
];
|
|
205
203
|
}
|