ballrush-core 0.4.0 → 0.4.2

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.
@@ -1,4 +1,3 @@
1
- import { GroupStatistics } from "../ports";
2
1
  import { ParticipantGroup, PlayerPosition, LanguageType, RatingSource } from "../types";
3
2
  export declare class Group {
4
3
  private readonly groupId;
@@ -7,8 +6,6 @@ export declare class Group {
7
6
  private timezone;
8
7
  private isMessageLast;
9
8
  private language;
10
- private isPublic;
11
- private statistics;
12
9
  private constructor();
13
10
  static create(params: {
14
11
  groupId: number;
@@ -17,8 +14,6 @@ export declare class Group {
17
14
  timezone?: string;
18
15
  isMessageLast?: boolean;
19
16
  language?: LanguageType;
20
- isPublic?: boolean;
21
- statistics?: GroupStatistics;
22
17
  }): Group;
23
18
  getGroupId(): number;
24
19
  getGroupName(): string;
@@ -26,14 +21,11 @@ export declare class Group {
26
21
  getIsMessageLast(): boolean;
27
22
  getLanguage(): LanguageType;
28
23
  getParticipants(): ParticipantGroup[];
29
- getIsPublic(): boolean;
30
- getStatistics(): GroupStatistics;
31
24
  getAdmins(): ParticipantGroup[];
32
25
  getAdminIds(): number[];
33
26
  setTimezone(tz: string): void;
34
27
  setIsMessageLast(v: boolean): void;
35
28
  setLanguage(language: LanguageType): void;
36
- setIsPublic(value: boolean): void;
37
29
  addAdmin(userId: number): void;
38
30
  removeAdmin(userId: number): void;
39
31
  addNewParticipant(userId: number, isAdmin?: boolean, initialRating?: number): boolean;
@@ -4,20 +4,18 @@ exports.Group = void 0;
4
4
  const types_1 = require("../types");
5
5
  const utils_1 = require("../utils");
6
6
  class Group {
7
- constructor(groupId, groupName, participants, timezone = "UTC+0", isMessageLast = false, language = "en", isPublic = false, statistics = { seasonsCount: 0, eventsCount: 0, matchesCount: 0, participantsCount: 0 }) {
7
+ constructor(groupId, groupName, participants, timezone = "UTC+0", isMessageLast = false, language = "en") {
8
8
  this.groupId = groupId;
9
9
  this.groupName = groupName;
10
10
  this.participants = participants;
11
11
  this.timezone = timezone;
12
12
  this.isMessageLast = isMessageLast;
13
13
  this.language = language;
14
- this.isPublic = isPublic;
15
- this.statistics = statistics;
16
14
  }
17
15
  static create(params) {
18
16
  if (!params.groupName)
19
17
  throw new Error("Group name is required");
20
- return new Group(params.groupId, params.groupName, (params.participants ?? []).map(p => ({ ...p, ratingHistory: [...p.ratingHistory] })), params.timezone ?? "UTC+0", params.isMessageLast ?? false, params.language ?? "en", params.isPublic ?? false, params.statistics ?? { seasonsCount: 0, eventsCount: 0, matchesCount: 0, participantsCount: 0 });
18
+ return new Group(params.groupId, params.groupName, (params.participants ?? []).map(p => ({ ...p, ratingHistory: [...p.ratingHistory] })), params.timezone ?? "UTC+0", params.isMessageLast ?? false, params.language ?? "en");
21
19
  }
22
20
  getGroupId() { return this.groupId; }
23
21
  getGroupName() { return this.groupName; }
@@ -25,8 +23,6 @@ class Group {
25
23
  getIsMessageLast() { return this.isMessageLast; }
26
24
  getLanguage() { return this.language; }
27
25
  getParticipants() { return this.participants; }
28
- getIsPublic() { return this.isPublic; }
29
- getStatistics() { return this.statistics; }
30
26
  getAdmins() {
31
27
  return this.participants.filter(p => p.isAdmin);
32
28
  }
@@ -42,9 +38,6 @@ class Group {
42
38
  setLanguage(language) {
43
39
  this.language = language;
44
40
  }
45
- setIsPublic(value) {
46
- this.isPublic = value;
47
- }
48
41
  addAdmin(userId) {
49
42
  const p = this.participants.find(x => x.userId === userId);
50
43
  if (p) {
@@ -7,15 +7,6 @@ export interface GroupDoc {
7
7
  timezone: string;
8
8
  isMessageLast: boolean;
9
9
  language: LanguageType;
10
- isPublic?: boolean;
11
- createdAt?: Date;
12
- updatedAt?: Date;
13
- statistics?: {
14
- seasonsCount: number;
15
- eventsCount: number;
16
- matchesCount: number;
17
- participantsCount: number;
18
- };
19
10
  }
20
11
  export declare function createRatingPointSchema(): Schema<RatingPoint, import("mongoose").Model<RatingPoint, any, any, any, import("mongoose").Document<unknown, any, RatingPoint> & RatingPoint & {
21
12
  _id: import("mongoose").Types.ObjectId;
@@ -30,15 +30,6 @@ function createGroupSchema() {
30
30
  timezone: { type: String, default: "UTC+0" },
31
31
  isMessageLast: { type: Boolean, default: false },
32
32
  language: { type: String, enum: ['en', 'ru', 'ua'], default: 'en' },
33
- isPublic: { type: Boolean, default: false, index: true },
34
- statistics: {
35
- seasonsCount: { type: Number, default: 0 },
36
- eventsCount: { type: Number, default: 0 },
37
- matchesCount: { type: Number, default: 0 },
38
- participantsCount: { type: Number, default: 0 },
39
- },
40
- }, {
41
- timestamps: true, // Adds createdAt and updatedAt automatically
42
33
  });
43
34
  return GroupSchema;
44
35
  }
@@ -12,51 +12,11 @@ export type GroupWrite = {
12
12
  timezone: string;
13
13
  isMessageLast: boolean;
14
14
  language: LanguageType;
15
- isPublic: boolean;
16
- statistics?: {
17
- seasonsCount: number;
18
- eventsCount: number;
19
- matchesCount: number;
20
- participantsCount: number;
21
- };
22
15
  };
23
- export interface FindPublicGroupsOptions {
24
- page: number;
25
- limit: number;
26
- search?: string;
27
- sort: 'lastActivity' | 'name' | 'members' | 'games';
28
- }
29
- export interface GroupStatistics {
30
- seasonsCount: number;
31
- eventsCount: number;
32
- matchesCount: number;
33
- participantsCount: number;
34
- }
35
- export interface PublicGroupsResult {
36
- groups: Array<{
37
- groupId: number;
38
- groupName: string;
39
- updatedAt: Date;
40
- statistics: GroupStatistics;
41
- }>;
42
- totalCount: number;
43
- }
44
16
  export interface GroupsRepository {
45
17
  create(groupData: Group): Promise<Group>;
46
18
  findById(groupId: number): Promise<Group | null>;
47
19
  update(groupId: number, updates: Group): Promise<Group | null>;
48
20
  findAll(): Promise<Group[]>;
49
21
  delete(groupId: number): Promise<void>;
50
- /**
51
- * Find public groups with pagination, search, and sorting
52
- * @param options Query options for filtering, pagination, and sorting
53
- * @returns Paginated list of public groups with statistics
54
- */
55
- findPublicGroups(options: FindPublicGroupsOptions): Promise<PublicGroupsResult>;
56
- /**
57
- * Update statistics for a specific group
58
- * @param groupId The group ID
59
- * @param updates Partial statistics to update
60
- */
61
- updateStatistics(groupId: number, updates: Partial<GroupStatistics>): Promise<void>;
62
22
  }
@@ -11,8 +11,6 @@ function toDomain(doc) {
11
11
  timezone: doc.timezone,
12
12
  isMessageLast: doc.isMessageLast,
13
13
  language: doc.language,
14
- isPublic: doc.isPublic ?? false,
15
- statistics: doc.statistics ?? { seasonsCount: 0, eventsCount: 0, matchesCount: 0, participantsCount: 0 },
16
14
  });
17
15
  }
18
16
  function toDoc(group) {
@@ -23,7 +21,5 @@ function toDoc(group) {
23
21
  timezone: group.getTimezone(),
24
22
  isMessageLast: group.getIsMessageLast(),
25
23
  language: group.getLanguage(),
26
- isPublic: group.getIsPublic(),
27
- statistics: group.getStatistics(),
28
24
  };
29
25
  }
@@ -1,5 +1,5 @@
1
1
  import type { Model } from "mongoose";
2
- import type { GroupsRepository, FindPublicGroupsOptions, PublicGroupsResult, GroupStatistics } from "../../ports/groups.repository";
2
+ import type { GroupsRepository } 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 {
@@ -10,6 +10,4 @@ export declare class MongoGroupsRepository implements GroupsRepository {
10
10
  update(groupId: number, updates: Group): Promise<Group | null>;
11
11
  findAll(): Promise<Group[]>;
12
12
  delete(groupId: number): Promise<void>;
13
- findPublicGroups(options: FindPublicGroupsOptions): Promise<PublicGroupsResult>;
14
- updateStatistics(groupId: number, updates: Partial<GroupStatistics>): Promise<void>;
15
13
  }
@@ -96,98 +96,5 @@ class MongoGroupsRepository {
96
96
  throw new errors_1.QueryError('delete', 'Group', groupId, error);
97
97
  }
98
98
  }
99
- async findPublicGroups(options) {
100
- try {
101
- const { page, limit, search, sort } = options;
102
- const skip = (page - 1) * limit;
103
- // Build query
104
- const query = { isPublic: true };
105
- // Add search filter if provided
106
- if (search) {
107
- query.groupName = { $regex: search, $options: 'i' }; // Case-insensitive search
108
- }
109
- // Build sort object based on sort parameter
110
- let sortObj = {};
111
- switch (sort) {
112
- case 'lastActivity':
113
- sortObj = { updatedAt: -1 }; // Descending (newest first)
114
- break;
115
- case 'name':
116
- sortObj = { groupName: 1 }; // Ascending (A-Z)
117
- break;
118
- case 'members':
119
- // Sort by participants array length
120
- // Note: This is approximate - for exact sorting, use aggregation pipeline
121
- sortObj = { participants: -1 }; // Descending (most members first)
122
- break;
123
- case 'games':
124
- // Sort by denormalized matchesCount
125
- sortObj = { 'statistics.matchesCount': -1 }; // Descending (most games first)
126
- break;
127
- }
128
- // Execute query
129
- const groups = await this.GroupModel
130
- .find(query)
131
- .select('groupId groupName updatedAt participants statistics')
132
- .sort(sortObj)
133
- .skip(skip)
134
- .limit(limit)
135
- .lean()
136
- .exec();
137
- const totalCount = await this.GroupModel.countDocuments(query);
138
- return {
139
- groups: groups.map(g => ({
140
- groupId: g.groupId,
141
- groupName: g.groupName,
142
- updatedAt: g.updatedAt, // guaranteed to exist with timestamps: true
143
- statistics: {
144
- seasonsCount: g.statistics?.seasonsCount ?? 0,
145
- eventsCount: g.statistics?.eventsCount ?? 0,
146
- matchesCount: g.statistics?.matchesCount ?? 0,
147
- participantsCount: g.participants.length,
148
- },
149
- })),
150
- totalCount,
151
- };
152
- }
153
- catch (error) {
154
- throw new errors_1.QueryError('findPublicGroups', 'Group', 'public', error);
155
- }
156
- }
157
- async updateStatistics(groupId, updates) {
158
- try {
159
- // Validate input
160
- if (!groupId || groupId === 0) {
161
- throw new errors_1.ValidationError('Group', 'groupId', groupId, 'must be a non-zero number');
162
- }
163
- if (!updates || Object.keys(updates).length === 0) {
164
- throw new errors_1.ValidationError('Group', 'updates', updates, 'updates object cannot be empty');
165
- }
166
- // Build update object with proper nesting
167
- const updateObj = {};
168
- if (updates.seasonsCount !== undefined) {
169
- updateObj['statistics.seasonsCount'] = updates.seasonsCount;
170
- }
171
- if (updates.eventsCount !== undefined) {
172
- updateObj['statistics.eventsCount'] = updates.eventsCount;
173
- }
174
- if (updates.matchesCount !== undefined) {
175
- updateObj['statistics.matchesCount'] = updates.matchesCount;
176
- }
177
- if (updates.participantsCount !== undefined) {
178
- updateObj['statistics.participantsCount'] = updates.participantsCount;
179
- }
180
- const result = await this.GroupModel.updateOne({ groupId }, { $set: updateObj });
181
- if (result.matchedCount === 0) {
182
- throw new errors_1.EntityNotFoundError('Group', groupId, 'updateStatistics');
183
- }
184
- }
185
- catch (error) {
186
- if (error instanceof errors_1.ValidationError || error instanceof errors_1.EntityNotFoundError) {
187
- throw error;
188
- }
189
- throw new errors_1.QueryError('updateStatistics', 'Group', groupId, error);
190
- }
191
- }
192
99
  }
193
100
  exports.MongoGroupsRepository = MongoGroupsRepository;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ballrush-core",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",