ballrush-core 0.13.0 → 1.3.0
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 +4 -0
- package/dist/domain/event.js +7 -2
- package/dist/mongo/schemas/event.schema.d.ts +1 -0
- package/dist/mongo/schemas/event.schema.js +1 -0
- package/dist/ports/events.repository.d.ts +1 -0
- package/dist/ports/groups.repository.d.ts +9 -0
- package/dist/repositories/mongo/event.mapper.js +2 -0
- package/dist/repositories/mongo/group.repository.d.ts +2 -1
- package/dist/repositories/mongo/group.repository.js +16 -0
- package/package.json +1 -1
package/dist/domain/event.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare class Event {
|
|
|
14
14
|
private gameMode;
|
|
15
15
|
private reportMessageId?;
|
|
16
16
|
private status;
|
|
17
|
+
private excludeFromStats;
|
|
17
18
|
private constructor();
|
|
18
19
|
static create(params: {
|
|
19
20
|
eventId: number;
|
|
@@ -30,6 +31,7 @@ export declare class Event {
|
|
|
30
31
|
isRatingApplied?: boolean;
|
|
31
32
|
status?: EventStatus;
|
|
32
33
|
gameMode?: GameMode;
|
|
34
|
+
excludeFromStats?: boolean;
|
|
33
35
|
}): Event;
|
|
34
36
|
getEventId(): number;
|
|
35
37
|
getGroupId(): number;
|
|
@@ -44,6 +46,7 @@ export declare class Event {
|
|
|
44
46
|
getCreatedBy(): number;
|
|
45
47
|
getStatus(): EventStatus;
|
|
46
48
|
getIsRatingApplied(): boolean;
|
|
49
|
+
getExcludeFromStats(): boolean;
|
|
47
50
|
getGameMode(): GameMode;
|
|
48
51
|
canChangeGameMode(): boolean;
|
|
49
52
|
setGameMode(mode: GameMode): void;
|
|
@@ -54,6 +57,7 @@ export declare class Event {
|
|
|
54
57
|
replaceTeams(teams: Team[]): void;
|
|
55
58
|
replaceMatches(matches: Match[]): void;
|
|
56
59
|
setRatingApplied(mark: boolean): void;
|
|
60
|
+
setExcludeFromStats(value: boolean): void;
|
|
57
61
|
setStatus(status: EventStatus): void;
|
|
58
62
|
isActive(): boolean;
|
|
59
63
|
isInProgress(): boolean;
|
package/dist/domain/event.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Event = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
class Event {
|
|
6
|
-
constructor(eventId, groupId, messageId, templateId, date, participants, teams, matches, createdBy, isRatingApplied, seasonId, gameMode, reportMessageId, status = "active") {
|
|
6
|
+
constructor(eventId, groupId, messageId, templateId, date, participants, teams, matches, createdBy, isRatingApplied, seasonId, gameMode, reportMessageId, status = "active", excludeFromStats = false) {
|
|
7
7
|
this.eventId = eventId;
|
|
8
8
|
this.groupId = groupId;
|
|
9
9
|
this.messageId = messageId;
|
|
@@ -18,12 +18,13 @@ class Event {
|
|
|
18
18
|
this.gameMode = gameMode;
|
|
19
19
|
this.reportMessageId = reportMessageId;
|
|
20
20
|
this.status = status;
|
|
21
|
+
this.excludeFromStats = excludeFromStats;
|
|
21
22
|
}
|
|
22
23
|
static create(params) {
|
|
23
24
|
if (!params.seasonId) {
|
|
24
25
|
throw new Error("Event must have a season ID");
|
|
25
26
|
}
|
|
26
|
-
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.gameMode ?? types_1.DEFAULT_GAME_MODE, params.reportMessageId, params.status ?? "active");
|
|
27
|
+
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.gameMode ?? types_1.DEFAULT_GAME_MODE, params.reportMessageId, params.status ?? "active", params.excludeFromStats ?? false);
|
|
27
28
|
}
|
|
28
29
|
getEventId() { return this.eventId; }
|
|
29
30
|
getGroupId() { return this.groupId; }
|
|
@@ -38,6 +39,7 @@ class Event {
|
|
|
38
39
|
getCreatedBy() { return this.createdBy; }
|
|
39
40
|
getStatus() { return this.status; }
|
|
40
41
|
getIsRatingApplied() { return this.isRatingApplied; }
|
|
42
|
+
getExcludeFromStats() { return this.excludeFromStats; }
|
|
41
43
|
getGameMode() { return this.gameMode; }
|
|
42
44
|
canChangeGameMode() { return this.matches.length === 0; }
|
|
43
45
|
setGameMode(mode) {
|
|
@@ -67,6 +69,9 @@ class Event {
|
|
|
67
69
|
setRatingApplied(mark) {
|
|
68
70
|
this.isRatingApplied = mark;
|
|
69
71
|
}
|
|
72
|
+
setExcludeFromStats(value) {
|
|
73
|
+
this.excludeFromStats = value;
|
|
74
|
+
}
|
|
70
75
|
setStatus(status) {
|
|
71
76
|
this.status = status;
|
|
72
77
|
}
|
|
@@ -57,6 +57,7 @@ function createEventSchema() {
|
|
|
57
57
|
teams: { type: [TeamSchema], default: [] },
|
|
58
58
|
matches: { type: [MatchSchema], default: [] },
|
|
59
59
|
isRatingApplied: { type: Boolean },
|
|
60
|
+
excludeFromStats: { type: Boolean, default: false },
|
|
60
61
|
reportMessageId: { type: Number },
|
|
61
62
|
gameMode: {
|
|
62
63
|
type: String,
|
|
@@ -14,10 +14,19 @@ export type GroupWrite = {
|
|
|
14
14
|
language: LanguageType;
|
|
15
15
|
isPublic: boolean;
|
|
16
16
|
};
|
|
17
|
+
export type GroupFieldsUpdate = Partial<Pick<GroupWrite, "groupName" | "timezone" | "isMessageLast" | "language" | "isPublic">>;
|
|
17
18
|
export interface GroupsRepository {
|
|
18
19
|
create(groupData: Group): Promise<Group>;
|
|
19
20
|
findById(groupId: number): Promise<Group | null>;
|
|
20
21
|
update(groupId: number, updates: Group): Promise<Group | null>;
|
|
22
|
+
/**
|
|
23
|
+
* Partial $set update for non-participant scalar fields.
|
|
24
|
+
* Use this instead of update() whenever you only need to change metadata
|
|
25
|
+
* (timezone, language, isMessageLast, etc.) — update() rewrites participants
|
|
26
|
+
* from the in-memory cache and can clobber rating data written by other
|
|
27
|
+
* processes between cache load and save.
|
|
28
|
+
*/
|
|
29
|
+
updateFields(groupId: number, fields: GroupFieldsUpdate): Promise<void>;
|
|
21
30
|
findAll(): Promise<Group[]>;
|
|
22
31
|
delete(groupId: number): Promise<void>;
|
|
23
32
|
}
|
|
@@ -20,6 +20,7 @@ function toDomain(doc) {
|
|
|
20
20
|
reportMessageId: doc.reportMessageId,
|
|
21
21
|
status: doc.status,
|
|
22
22
|
gameMode: doc.gameMode ?? types_1.DEFAULT_GAME_MODE,
|
|
23
|
+
excludeFromStats: doc.excludeFromStats ?? false,
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
26
|
function toDoc(event) {
|
|
@@ -38,5 +39,6 @@ function toDoc(event) {
|
|
|
38
39
|
isRatingApplied: event.getIsRatingApplied(),
|
|
39
40
|
reportMessageId: event.getReportMessageId(),
|
|
40
41
|
gameMode: event.getGameMode(),
|
|
42
|
+
excludeFromStats: event.getExcludeFromStats(),
|
|
41
43
|
};
|
|
42
44
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Model } from "mongoose";
|
|
2
|
-
import type { GroupsRepository } from "../../ports/groups.repository";
|
|
2
|
+
import type { GroupsRepository, GroupFieldsUpdate } from "../../ports/groups.repository";
|
|
3
3
|
import type { GroupDoc } from "../../mongo";
|
|
4
4
|
import { Group } from "../../domain/group";
|
|
5
5
|
export declare class MongoGroupsRepository implements GroupsRepository {
|
|
@@ -8,6 +8,7 @@ export declare class MongoGroupsRepository implements GroupsRepository {
|
|
|
8
8
|
create(group: Group): Promise<Group>;
|
|
9
9
|
findById(groupId: number): Promise<Group | null>;
|
|
10
10
|
update(groupId: number, updates: Group): Promise<Group | null>;
|
|
11
|
+
updateFields(groupId: number, fields: GroupFieldsUpdate): Promise<void>;
|
|
11
12
|
findAll(): Promise<Group[]>;
|
|
12
13
|
delete(groupId: number): Promise<void>;
|
|
13
14
|
}
|
|
@@ -68,6 +68,22 @@ class MongoGroupsRepository {
|
|
|
68
68
|
throw new errors_1.QueryError('update', 'Group', groupId, error);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
+
async updateFields(groupId, fields) {
|
|
72
|
+
try {
|
|
73
|
+
if (!groupId || groupId === 0) {
|
|
74
|
+
throw new errors_1.ValidationError('Group', 'groupId', groupId, 'must be a non-zero number');
|
|
75
|
+
}
|
|
76
|
+
if (!fields || Object.keys(fields).length === 0)
|
|
77
|
+
return;
|
|
78
|
+
await this.GroupModel.updateOne({ groupId }, { $set: fields });
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
if (error instanceof errors_1.ValidationError) {
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
throw new errors_1.QueryError('updateFields', 'Group', groupId, error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
71
87
|
async findAll() {
|
|
72
88
|
try {
|
|
73
89
|
const docs = await this.GroupModel.find().lean();
|