ballrush-core 0.2.5 → 0.3.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/group.d.ts +7 -3
- package/dist/domain/group.js +12 -7
- package/dist/mongo/schemas/group.schema.d.ts +2 -1
- package/dist/mongo/schemas/group.schema.js +3 -0
- package/dist/mongo/schemas/user.schema.js +1 -1
- package/dist/ports/groups.repository.d.ts +3 -0
- package/dist/repositories/mongo/group.mapper.js +2 -0
- package/dist/types/shared.d.ts +7 -1
- package/dist/types/shared.js +7 -1
- package/dist/utils/rating.d.ts +2 -2
- package/dist/utils/rating.js +2 -2
- package/package.json +1 -1
package/dist/domain/group.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { ParticipantGroup, PlayerPosition } from "../types";
|
|
1
|
+
import { ParticipantGroup, PlayerPosition, LanguageType, RatingSource } from "../types";
|
|
2
2
|
export declare class Group {
|
|
3
3
|
private readonly groupId;
|
|
4
4
|
private readonly groupName;
|
|
5
5
|
private participants;
|
|
6
6
|
private timezone;
|
|
7
7
|
private isMessageLast;
|
|
8
|
+
private language;
|
|
8
9
|
private constructor();
|
|
9
10
|
static create(params: {
|
|
10
11
|
groupId: number;
|
|
@@ -12,20 +13,23 @@ export declare class Group {
|
|
|
12
13
|
participants?: ParticipantGroup[];
|
|
13
14
|
timezone?: string;
|
|
14
15
|
isMessageLast?: boolean;
|
|
16
|
+
language?: LanguageType;
|
|
15
17
|
}): Group;
|
|
16
18
|
getGroupId(): number;
|
|
17
19
|
getGroupName(): string;
|
|
18
20
|
getTimezone(): string;
|
|
19
21
|
getIsMessageLast(): boolean;
|
|
22
|
+
getLanguage(): LanguageType;
|
|
20
23
|
getParticipants(): ParticipantGroup[];
|
|
21
24
|
getAdmins(): ParticipantGroup[];
|
|
22
25
|
getAdminIds(): number[];
|
|
23
26
|
setTimezone(tz: string): void;
|
|
24
27
|
setIsMessageLast(v: boolean): void;
|
|
28
|
+
setLanguage(language: LanguageType): void;
|
|
25
29
|
addAdmin(userId: number): void;
|
|
26
30
|
removeAdmin(userId: number): void;
|
|
27
|
-
|
|
31
|
+
addNewParticipant(userId: number, isAdmin?: boolean, initialRating?: number): boolean;
|
|
28
32
|
removeParticipant(userId: number): void;
|
|
29
33
|
setPosition(userId: number, pos: PlayerPosition): void;
|
|
30
|
-
addRatingPoint(userId: number, value: number,
|
|
34
|
+
addRatingPoint(userId: number, value: number, source: RatingSource): void;
|
|
31
35
|
}
|
package/dist/domain/group.js
CHANGED
|
@@ -4,22 +4,24 @@ 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) {
|
|
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
|
+
this.language = language;
|
|
13
14
|
}
|
|
14
15
|
static create(params) {
|
|
15
16
|
if (!params.groupName)
|
|
16
17
|
throw new Error("Group name is required");
|
|
17
|
-
return new Group(params.groupId, params.groupName, (params.participants ?? []).map(p => ({ ...p, ratingHistory: [...p.ratingHistory] })), params.timezone ?? "UTC+0", params.isMessageLast ?? false);
|
|
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");
|
|
18
19
|
}
|
|
19
20
|
getGroupId() { return this.groupId; }
|
|
20
21
|
getGroupName() { return this.groupName; }
|
|
21
22
|
getTimezone() { return this.timezone; }
|
|
22
23
|
getIsMessageLast() { return this.isMessageLast; }
|
|
24
|
+
getLanguage() { return this.language; }
|
|
23
25
|
getParticipants() { return this.participants; }
|
|
24
26
|
getAdmins() {
|
|
25
27
|
return this.participants.filter(p => p.isAdmin);
|
|
@@ -33,6 +35,9 @@ class Group {
|
|
|
33
35
|
setIsMessageLast(v) {
|
|
34
36
|
this.isMessageLast = v;
|
|
35
37
|
}
|
|
38
|
+
setLanguage(language) {
|
|
39
|
+
this.language = language;
|
|
40
|
+
}
|
|
36
41
|
addAdmin(userId) {
|
|
37
42
|
const p = this.participants.find(x => x.userId === userId);
|
|
38
43
|
if (p) {
|
|
@@ -42,7 +47,7 @@ class Group {
|
|
|
42
47
|
this.participants.push({
|
|
43
48
|
userId,
|
|
44
49
|
position: types_1.PlayerPosition.UN,
|
|
45
|
-
ratingHistory: (0, utils_1.addRating)([], 0),
|
|
50
|
+
ratingHistory: (0, utils_1.addRating)([], 0, new Date(), types_1.RatingSource.SYSTEM),
|
|
46
51
|
isAdmin: true,
|
|
47
52
|
});
|
|
48
53
|
}
|
|
@@ -52,13 +57,13 @@ class Group {
|
|
|
52
57
|
if (p)
|
|
53
58
|
p.isAdmin = false;
|
|
54
59
|
}
|
|
55
|
-
|
|
60
|
+
addNewParticipant(userId, isAdmin = false, initialRating = 0) {
|
|
56
61
|
if (this.participants.some(p => p.userId === userId))
|
|
57
62
|
return false;
|
|
58
63
|
this.participants.push({
|
|
59
64
|
userId,
|
|
60
65
|
position: types_1.PlayerPosition.UN,
|
|
61
|
-
ratingHistory: (0, utils_1.addRating)([], initialRating),
|
|
66
|
+
ratingHistory: (0, utils_1.addRating)([], initialRating, new Date(), types_1.RatingSource.SYSTEM),
|
|
62
67
|
isAdmin,
|
|
63
68
|
});
|
|
64
69
|
return true;
|
|
@@ -71,11 +76,11 @@ class Group {
|
|
|
71
76
|
if (p)
|
|
72
77
|
p.position = pos;
|
|
73
78
|
}
|
|
74
|
-
addRatingPoint(userId, value,
|
|
79
|
+
addRatingPoint(userId, value, source) {
|
|
75
80
|
const p = this.participants.find(x => x.userId === userId);
|
|
76
81
|
if (!p)
|
|
77
82
|
return;
|
|
78
|
-
p.ratingHistory = (0, utils_1.addRating)(p.ratingHistory, value,
|
|
83
|
+
p.ratingHistory = (0, utils_1.addRating)(p.ratingHistory, value, new Date(), source);
|
|
79
84
|
}
|
|
80
85
|
}
|
|
81
86
|
exports.Group = Group;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Schema } from "mongoose";
|
|
2
|
-
import { ParticipantGroup, RatingPoint } from "../../types";
|
|
2
|
+
import { ParticipantGroup, RatingPoint, LanguageType } from "../../types";
|
|
3
3
|
export interface GroupDoc {
|
|
4
4
|
groupId: number;
|
|
5
5
|
groupName: string;
|
|
6
6
|
participants: ParticipantGroup[];
|
|
7
7
|
timezone: string;
|
|
8
8
|
isMessageLast: boolean;
|
|
9
|
+
language: LanguageType;
|
|
9
10
|
}
|
|
10
11
|
export declare function createRatingPointSchema(): Schema<RatingPoint, import("mongoose").Model<RatingPoint, any, any, any, import("mongoose").Document<unknown, any, RatingPoint> & RatingPoint & {
|
|
11
12
|
_id: import("mongoose").Types.ObjectId;
|
|
@@ -4,10 +4,12 @@ exports.createRatingPointSchema = createRatingPointSchema;
|
|
|
4
4
|
exports.createParticipantSchema = createParticipantSchema;
|
|
5
5
|
exports.createGroupSchema = createGroupSchema;
|
|
6
6
|
const mongoose_1 = require("mongoose");
|
|
7
|
+
const types_1 = require("../../types");
|
|
7
8
|
function createRatingPointSchema() {
|
|
8
9
|
return new mongoose_1.Schema({
|
|
9
10
|
value: { type: Number, required: true },
|
|
10
11
|
changedAt: { type: Date, default: Date.now },
|
|
12
|
+
source: { type: String, enum: types_1.RatingSource, default: types_1.RatingSource.SYSTEM },
|
|
11
13
|
});
|
|
12
14
|
}
|
|
13
15
|
function createParticipantSchema() {
|
|
@@ -27,6 +29,7 @@ function createGroupSchema() {
|
|
|
27
29
|
participants: { type: [ParticipantSchema], default: [] },
|
|
28
30
|
timezone: { type: String, default: "UTC+0" },
|
|
29
31
|
isMessageLast: { type: Boolean, default: false },
|
|
32
|
+
language: { type: String, enum: ['en', 'ru', 'ua'], default: 'en' },
|
|
30
33
|
});
|
|
31
34
|
return GroupSchema;
|
|
32
35
|
}
|
|
@@ -7,7 +7,7 @@ function createUserSchema() {
|
|
|
7
7
|
firstName: { type: String, required: true },
|
|
8
8
|
username: { type: String },
|
|
9
9
|
userId: { type: Number, required: true, unique: true, index: true },
|
|
10
|
-
language: { type: String, enum: ["ru", "en"], default: "ru" },
|
|
10
|
+
language: { type: String, enum: ["ru", "en", "ua"], default: "ru" },
|
|
11
11
|
});
|
|
12
12
|
return UserSchema;
|
|
13
13
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Group } from "../domain/group";
|
|
2
|
+
import { LanguageType, RatingSource } from "../types";
|
|
2
3
|
export type GroupWrite = {
|
|
3
4
|
groupId: number;
|
|
4
5
|
groupName: string;
|
|
@@ -8,11 +9,13 @@ export type GroupWrite = {
|
|
|
8
9
|
ratingHistory: Array<{
|
|
9
10
|
value: number;
|
|
10
11
|
changedAt: Date;
|
|
12
|
+
source: RatingSource;
|
|
11
13
|
}>;
|
|
12
14
|
isAdmin: boolean;
|
|
13
15
|
}>;
|
|
14
16
|
timezone: string;
|
|
15
17
|
isMessageLast: boolean;
|
|
18
|
+
language: LanguageType;
|
|
16
19
|
};
|
|
17
20
|
export interface GroupsRepository {
|
|
18
21
|
create(groupData: Group): Promise<Group>;
|
|
@@ -10,6 +10,7 @@ function toDomain(doc) {
|
|
|
10
10
|
participants: doc.participants,
|
|
11
11
|
timezone: doc.timezone,
|
|
12
12
|
isMessageLast: doc.isMessageLast,
|
|
13
|
+
language: doc.language,
|
|
13
14
|
});
|
|
14
15
|
}
|
|
15
16
|
function toDoc(group) {
|
|
@@ -19,5 +20,6 @@ function toDoc(group) {
|
|
|
19
20
|
participants: group.getParticipants(),
|
|
20
21
|
timezone: group.getTimezone(),
|
|
21
22
|
isMessageLast: group.getIsMessageLast(),
|
|
23
|
+
language: group.getLanguage(),
|
|
22
24
|
};
|
|
23
25
|
}
|
package/dist/types/shared.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type EventStatus = "active" | "in_progress" | "completed";
|
|
2
|
-
export type LanguageType = "en" | "ru";
|
|
2
|
+
export type LanguageType = "en" | "ru" | "ua";
|
|
3
3
|
export type DayOfWeek = "Monday" | "Tuesday" | "Wednesday" | "Thursday" | "Friday" | "Saturday" | "Sunday";
|
|
4
4
|
export interface ParticipantBase {
|
|
5
5
|
userId: number;
|
|
@@ -71,6 +71,12 @@ export interface SelectedParticipantsDate {
|
|
|
71
71
|
export interface RatingPoint {
|
|
72
72
|
value: number;
|
|
73
73
|
changedAt: Date;
|
|
74
|
+
source: RatingSource;
|
|
75
|
+
}
|
|
76
|
+
export declare enum RatingSource {
|
|
77
|
+
ADMIN_MANUAL = "ADMIN_MANUAL",
|
|
78
|
+
GAME_RESULT = "GAME_RESULT",
|
|
79
|
+
SYSTEM = "SYSTEM"
|
|
74
80
|
}
|
|
75
81
|
export declare const ACHIEVEMENTS: {
|
|
76
82
|
readonly WinStreak: {
|
package/dist/types/shared.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ACHIEVEMENTS = exports.PlayerPosition = void 0;
|
|
3
|
+
exports.ACHIEVEMENTS = exports.RatingSource = exports.PlayerPosition = void 0;
|
|
4
4
|
var PlayerPosition;
|
|
5
5
|
(function (PlayerPosition) {
|
|
6
6
|
PlayerPosition["FW"] = "FW";
|
|
@@ -9,6 +9,12 @@ var PlayerPosition;
|
|
|
9
9
|
PlayerPosition["GK"] = "GK";
|
|
10
10
|
PlayerPosition["UN"] = "UN";
|
|
11
11
|
})(PlayerPosition || (exports.PlayerPosition = PlayerPosition = {}));
|
|
12
|
+
var RatingSource;
|
|
13
|
+
(function (RatingSource) {
|
|
14
|
+
RatingSource["ADMIN_MANUAL"] = "ADMIN_MANUAL";
|
|
15
|
+
RatingSource["GAME_RESULT"] = "GAME_RESULT";
|
|
16
|
+
RatingSource["SYSTEM"] = "SYSTEM";
|
|
17
|
+
})(RatingSource || (exports.RatingSource = RatingSource = {}));
|
|
12
18
|
exports.ACHIEVEMENTS = {
|
|
13
19
|
WinStreak: {
|
|
14
20
|
emoji: '🔥',
|
package/dist/utils/rating.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RatingPoint } from "../types";
|
|
2
|
-
export declare function addRating(rating: ReadonlyArray<RatingPoint>, newValue: number, date
|
|
1
|
+
import { RatingPoint, RatingSource } from "../types";
|
|
2
|
+
export declare function addRating(rating: ReadonlyArray<RatingPoint>, newValue: number, date: Date | undefined, source: RatingSource): RatingPoint[];
|
|
3
3
|
export declare function latestEntry(rating: ReadonlyArray<RatingPoint>): RatingPoint | null;
|
|
4
4
|
export declare function getCurrentRating(rating?: ReadonlyArray<RatingPoint>): number;
|
package/dist/utils/rating.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.addRating = addRating;
|
|
4
4
|
exports.latestEntry = latestEntry;
|
|
5
5
|
exports.getCurrentRating = getCurrentRating;
|
|
6
|
-
function addRating(rating, newValue, date = new Date()) {
|
|
7
|
-
return [...rating, { value: newValue, changedAt: date }];
|
|
6
|
+
function addRating(rating, newValue, date = new Date(), source) {
|
|
7
|
+
return [...rating, { value: newValue, changedAt: date, source }];
|
|
8
8
|
}
|
|
9
9
|
function latestEntry(rating) {
|
|
10
10
|
if (!rating || rating.length === 0)
|