ballrush-core 0.3.0 → 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.
@@ -1,4 +1,4 @@
1
- import { ParticipantGroup, PlayerPosition, LanguageType } 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;
@@ -28,8 +28,8 @@ export declare class Group {
28
28
  setLanguage(language: LanguageType): void;
29
29
  addAdmin(userId: number): void;
30
30
  removeAdmin(userId: number): void;
31
- addParticipant(userId: number, isAdmin?: boolean, initialRating?: number): boolean;
31
+ addNewParticipant(userId: number, isAdmin?: boolean, initialRating?: number): boolean;
32
32
  removeParticipant(userId: number): void;
33
33
  setPosition(userId: number, pos: PlayerPosition): void;
34
- addRatingPoint(userId: number, value: number, at?: Date): void;
34
+ addRatingPoint(userId: number, value: number, source: RatingSource): void;
35
35
  }
@@ -47,7 +47,7 @@ class Group {
47
47
  this.participants.push({
48
48
  userId,
49
49
  position: types_1.PlayerPosition.UN,
50
- ratingHistory: (0, utils_1.addRating)([], 0),
50
+ ratingHistory: (0, utils_1.addRating)([], 0, new Date(), types_1.RatingSource.SYSTEM),
51
51
  isAdmin: true,
52
52
  });
53
53
  }
@@ -57,13 +57,13 @@ class Group {
57
57
  if (p)
58
58
  p.isAdmin = false;
59
59
  }
60
- addParticipant(userId, isAdmin = false, initialRating = 0) {
60
+ addNewParticipant(userId, isAdmin = false, initialRating = 0) {
61
61
  if (this.participants.some(p => p.userId === userId))
62
62
  return false;
63
63
  this.participants.push({
64
64
  userId,
65
65
  position: types_1.PlayerPosition.UN,
66
- ratingHistory: (0, utils_1.addRating)([], initialRating),
66
+ ratingHistory: (0, utils_1.addRating)([], initialRating, new Date(), types_1.RatingSource.SYSTEM),
67
67
  isAdmin,
68
68
  });
69
69
  return true;
@@ -76,11 +76,11 @@ class Group {
76
76
  if (p)
77
77
  p.position = pos;
78
78
  }
79
- addRatingPoint(userId, value, at = new Date()) {
79
+ addRatingPoint(userId, value, source) {
80
80
  const p = this.participants.find(x => x.userId === userId);
81
81
  if (!p)
82
82
  return;
83
- p.ratingHistory = (0, utils_1.addRating)(p.ratingHistory, value, at);
83
+ p.ratingHistory = (0, utils_1.addRating)(p.ratingHistory, value, new Date(), source);
84
84
  }
85
85
  }
86
86
  exports.Group = Group;
@@ -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() {
@@ -1,5 +1,5 @@
1
1
  import { Group } from "../domain/group";
2
- import { LanguageType } from "../types";
2
+ import { LanguageType, RatingSource } from "../types";
3
3
  export type GroupWrite = {
4
4
  groupId: number;
5
5
  groupName: string;
@@ -9,6 +9,7 @@ export type GroupWrite = {
9
9
  ratingHistory: Array<{
10
10
  value: number;
11
11
  changedAt: Date;
12
+ source: RatingSource;
12
13
  }>;
13
14
  isAdmin: boolean;
14
15
  }>;
@@ -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: {
@@ -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: '🔥',
@@ -1,4 +1,4 @@
1
- import { RatingPoint } from "../types";
2
- export declare function addRating(rating: ReadonlyArray<RatingPoint>, newValue: number, date?: Date): RatingPoint[];
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;
@@ -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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ballrush-core",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",