ballrush-core 0.6.0 → 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.
@@ -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?: boolean;
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;
@@ -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 ?? true, // По умолчанию публичный (системный)
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,
@@ -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 }); // Для поиска по году и статусу
@@ -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({ isPublic: true }).sort({ year: -1, startDate: -1 }).lean();
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
- { isPublic: true },
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
- { isPublic: true },
200
+ { seasonType: 'system' },
203
201
  { groupId: groupId }
204
202
  ];
205
203
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ballrush-core",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",