jp.db.schemas 2.1.9 → 2.1.11

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.
Files changed (61) hide show
  1. package/dist/index.d.ts +9 -4
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +11 -2
  4. package/dist/index.js.map +1 -1
  5. package/dist/models/rating-add-bulk-item.interface.d.ts +8 -0
  6. package/dist/models/rating-add-bulk-item.interface.d.ts.map +1 -0
  7. package/dist/models/rating-add-bulk-item.interface.js +3 -0
  8. package/dist/models/rating-add-bulk-item.interface.js.map +1 -0
  9. package/dist/models/rating-monthly-result.interface.d.ts +12 -0
  10. package/dist/models/rating-monthly-result.interface.d.ts.map +1 -0
  11. package/dist/models/rating-monthly-result.interface.js +3 -0
  12. package/dist/models/rating-monthly-result.interface.js.map +1 -0
  13. package/dist/repositories/activity-log.repository.d.ts +6 -6
  14. package/dist/repositories/activity-log.repository.d.ts.map +1 -1
  15. package/dist/repositories/activity-log.repository.js +13 -13
  16. package/dist/repositories/activity-log.repository.js.map +1 -1
  17. package/dist/repositories/friend.repository.d.ts +8 -0
  18. package/dist/repositories/friend.repository.d.ts.map +1 -0
  19. package/dist/repositories/friend.repository.js +39 -0
  20. package/dist/repositories/friend.repository.js.map +1 -0
  21. package/dist/repositories/game-statistic.repository.d.ts +8 -0
  22. package/dist/repositories/game-statistic.repository.d.ts.map +1 -0
  23. package/dist/repositories/game-statistic.repository.js +39 -0
  24. package/dist/repositories/game-statistic.repository.js.map +1 -0
  25. package/dist/repositories/index.d.ts +4 -1
  26. package/dist/repositories/index.d.ts.map +1 -1
  27. package/dist/repositories/index.js +7 -1
  28. package/dist/repositories/index.js.map +1 -1
  29. package/dist/repositories/rating.repository.d.ts +11 -0
  30. package/dist/repositories/rating.repository.d.ts.map +1 -0
  31. package/dist/repositories/rating.repository.js +98 -0
  32. package/dist/repositories/rating.repository.js.map +1 -0
  33. package/dist/schemas/activity_log.schema.d.ts +2 -2
  34. package/dist/schemas/activity_log.schema.d.ts.map +1 -1
  35. package/dist/schemas/activity_log.schema.js +1 -1
  36. package/dist/schemas/activity_log.schema.js.map +1 -1
  37. package/dist/schemas/friend.schema.d.ts +87 -0
  38. package/dist/schemas/friend.schema.d.ts.map +1 -0
  39. package/dist/schemas/friend.schema.js +73 -0
  40. package/dist/schemas/friend.schema.js.map +1 -0
  41. package/dist/schemas/game_statistic.schema.d.ts +115 -0
  42. package/dist/schemas/game_statistic.schema.d.ts.map +1 -0
  43. package/dist/schemas/game_statistic.schema.js +61 -0
  44. package/dist/schemas/game_statistic.schema.js.map +1 -0
  45. package/dist/schemas/rating.schema.d.ts +5 -35
  46. package/dist/schemas/rating.schema.d.ts.map +1 -1
  47. package/dist/schemas/rating.schema.js +5 -17
  48. package/dist/schemas/rating.schema.js.map +1 -1
  49. package/package.json +1 -1
  50. package/src/index.ts +18 -0
  51. package/src/models/rating-add-bulk-item.interface.ts +7 -0
  52. package/src/models/rating-monthly-result.interface.ts +11 -0
  53. package/src/repositories/activity-log.repository.ts +13 -13
  54. package/src/repositories/friend.repository.ts +20 -0
  55. package/src/repositories/game-statistic.repository.ts +21 -0
  56. package/src/repositories/index.ts +6 -0
  57. package/src/repositories/rating.repository.ts +84 -0
  58. package/src/schemas/activity_log.schema.ts +1 -1
  59. package/src/schemas/friend.schema.ts +51 -0
  60. package/src/schemas/game_statistic.schema.ts +40 -0
  61. package/src/schemas/rating.schema.ts +3 -12
package/src/index.ts CHANGED
@@ -42,10 +42,13 @@ import { PurchaseChannel, PurchaseChannelSchema } from './schemas/purchase_chann
42
42
  import type { PurchaseChannelDocument } from './schemas/purchase_channel.schema';
43
43
  import { Rating, RatingSchema } from './schemas/rating.schema';
44
44
  import type { RatingDocument } from './schemas/rating.schema';
45
+ import type { IRatingMonthlyResult} from './models/rating-monthly-result.interface';
45
46
  import { Setting, SettingSchema } from './schemas/setting.schema';
46
47
  import type { SettingDocument } from './schemas/setting.schema';
47
48
  import { Premium, PremiumSchema } from './schemas/premium.schema';
48
49
  import type { PremiumDocument } from './schemas/premium.schema';
50
+ import { GameStatistic, GameStatisticSchema } from './schemas/game_statistic.schema';
51
+ import type { GameStatisticDocument } from './schemas/game_statistic.schema';
49
52
  import { Menu, MenuSchema } from './schemas/menu.schema';
50
53
  import type { MenuDocument } from './schemas/menu.schema';
51
54
  import { GameResult, GameResultSchema } from './schemas/game_result.schema';
@@ -62,6 +65,8 @@ import { DailyBonus, DailyBonusSchema } from './schemas/daily_bonus.schema';
62
65
  import type { DailyBonusDocument } from './schemas/daily_bonus.schema';
63
66
  import { Rule, RuleSchema } from './schemas/rule.schema';
64
67
  import type { RuleDocument } from './schemas/rule.schema';
68
+ import { Friend, FriendSchema } from './schemas/friend.schema';
69
+ import type { FriendDocument } from './schemas/friend.schema';
65
70
  import { Welcome, WelcomeSchema } from './schemas/welcome.schema';
66
71
  import type { WelcomeDocument } from './schemas/welcome.schema';
67
72
  import { ActivityLog, ActivityLogSchema } from './schemas/activity_log.schema';
@@ -79,7 +84,10 @@ import {
79
84
  ServersRepository,
80
85
  UsersRepository,
81
86
  MenuRepository,
87
+ GameStatisticRepository,
88
+ FriendRepository,
82
89
  WelcomeRepository,
90
+ RatingRepository,
83
91
  PremiumRepository,
84
92
  RuleRepository,
85
93
  DailyBonusRepository,
@@ -117,11 +125,13 @@ export type {
117
125
  ProductDocument,
118
126
  PurchaseChannelDocument,
119
127
  RatingDocument,
128
+ GameStatisticDocument,
120
129
  SettingDocument,
121
130
  PremiumDocument,
122
131
  MenuDocument,
123
132
  WelcomeDocument,
124
133
  RuleDocument,
134
+ FriendDocument,
125
135
  DailyBonusDocument,
126
136
  GameResultDocument,
127
137
  BalanceHistoryDocument,
@@ -176,8 +186,11 @@ export {
176
186
  PurchaseChannelSchema,
177
187
  Rating,
178
188
  RatingSchema,
189
+ IRatingMonthlyResult,
179
190
  Setting,
180
191
  SettingSchema,
192
+ GameStatistic,
193
+ GameStatisticSchema,
181
194
  Menu,
182
195
  MenuSchema,
183
196
  DailyBonus,
@@ -188,6 +201,8 @@ export {
188
201
  PremiumSchema,
189
202
  Welcome,
190
203
  WelcomeSchema,
204
+ Friend,
205
+ FriendSchema,
191
206
  GameResult,
192
207
  GameResultSchema,
193
208
  BalanceHistory,
@@ -217,6 +232,9 @@ export {
217
232
  DailyBonusRepository,
218
233
  PremiumRepository,
219
234
  RuleRepository,
235
+ RatingRepository,
236
+ GameStatisticRepository,
237
+ FriendRepository,
220
238
  WelcomeRepository,
221
239
  SettingRepository,
222
240
  RoomsRepository,
@@ -0,0 +1,7 @@
1
+ export interface IRatingAddBulkItem {
2
+ userId: string;
3
+ userName: string;
4
+ userAvatarUrl: string
5
+ game: string;
6
+ channels: string;
7
+ }
@@ -0,0 +1,11 @@
1
+ export interface IRatingMonthlyResult {
2
+ id: string;
3
+ userId: string;
4
+ userName: string;
5
+ userAvatarUrl: string
6
+ game: string;
7
+ channels: string;
8
+ count: number;
9
+ date: string;
10
+ rank: number;
11
+ }
@@ -36,7 +36,7 @@ export class ActivityLogRepository {
36
36
  userName: { $first: "$userName" },
37
37
  event: { $first: "$event" },
38
38
  game: { $first: "$game" },
39
- channel: { $first: "$channel" },
39
+ channels: { $first: "$channels" },
40
40
  count: { $sum: 1 },
41
41
  }
42
42
  },
@@ -79,28 +79,28 @@ export class ActivityLogRepository {
79
79
  return await this.activityLogModel.countDocuments({ userId, event: ActivityLogEnum.USER_WON_ONE_TABLE_TOURNAMENT }).exec()
80
80
  }
81
81
 
82
- async addUserLoginEvent(userId: string, userName: string, game: string, channel: string): Promise<ActivityLog> {
83
- return this.addActivityLog({ date: new Date(), event: ActivityLogEnum.USER_LOGIN, userId, userName, game, channel });
82
+ async addUserLoginEvent(userId: string, userName: string, game: string, channels: string): Promise<ActivityLog> {
83
+ return this.addActivityLog({ date: new Date(), event: ActivityLogEnum.USER_LOGIN, userId, userName, game, channels });
84
84
  }
85
85
 
86
- async addUserGotBonuseEvent(userId: string, userName: string, game: string, channel: string, amount: number): Promise<ActivityLog> {
87
- return this.addActivityLog({ date: new Date(), event: ActivityLogEnum.USER_GOT_BONUS, userId, userName, game, channel, amount, });
86
+ async addUserGotBonuseEvent(userId: string, userName: string, game: string, channels: string, amount: number): Promise<ActivityLog> {
87
+ return this.addActivityLog({ date: new Date(), event: ActivityLogEnum.USER_GOT_BONUS, userId, userName, game, channels, amount, });
88
88
  }
89
89
 
90
- async addUserPlayedGameEvent(userId: string, userName: string, game: string, channel: string): Promise<ActivityLog> {
91
- return this.addActivityLog({ date: new Date(), event: ActivityLogEnum.USER_PLAYED_GAME, userId, userName, game, channel, });
90
+ async addUserPlayedGameEvent(userId: string, userName: string, game: string, channels: string): Promise<ActivityLog> {
91
+ return this.addActivityLog({ date: new Date(), event: ActivityLogEnum.USER_PLAYED_GAME, userId, userName, game, channels, });
92
92
  }
93
93
 
94
- async addUserWonGameEvent(userId: string, userName: string, game: string, channel: string): Promise<ActivityLog> {
95
- return this.addActivityLog({ date: new Date(), event: ActivityLogEnum.USER_WON_GAME, userId, userName, game, channel });
94
+ async addUserWonGameEvent(userId: string, userName: string, game: string, channels: string): Promise<ActivityLog> {
95
+ return this.addActivityLog({ date: new Date(), event: ActivityLogEnum.USER_WON_GAME, userId, userName, game, channels });
96
96
  }
97
97
 
98
- async addUserWonProfieEvent(userId: string, userName: string, game: string, channel: string): Promise<ActivityLog> {
99
- return this.addActivityLog({ date: new Date(), event: ActivityLogEnum.USER_WON_PROFI, userId, userName, game, channel });
98
+ async addUserWonProfieEvent(userId: string, userName: string, game: string, channels: string): Promise<ActivityLog> {
99
+ return this.addActivityLog({ date: new Date(), event: ActivityLogEnum.USER_WON_PROFI, userId, userName, game, channels });
100
100
  }
101
101
 
102
- async addUserWonOneTableTournamentEvent(userId: string, userName: string, game: string, channel: string): Promise<ActivityLog> {
103
- return this.addActivityLog({ date: new Date(), event: ActivityLogEnum.USER_WON_ONE_TABLE_TOURNAMENT, userId, userName, game, channel });
102
+ async addUserWonOneTableTournamentEvent(userId: string, userName: string, game: string, channels: string): Promise<ActivityLog> {
103
+ return this.addActivityLog({ date: new Date(), event: ActivityLogEnum.USER_WON_ONE_TABLE_TOURNAMENT, userId, userName, game, channels });
104
104
  }
105
105
 
106
106
  async addActivityLog(activityLog: Partial<ActivityLog>): Promise<ActivityLog> {
@@ -0,0 +1,20 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { InjectModel } from '@nestjs/mongoose';
3
+ import { Model } from 'mongoose';
4
+
5
+ import { Friend, FriendDocument } from '..';
6
+ import { getChannelRegExpFilter } from '../utils';
7
+
8
+ @Injectable()
9
+ export class FriendRepository {
10
+ constructor (@InjectModel(Friend.name) private friendModel: Model<FriendDocument>) {
11
+ }
12
+
13
+ async findFriend (channel: string, game: string): Promise<Array<Friend> | null> {
14
+ return this.friendModel
15
+ .find({
16
+ channels: getChannelRegExpFilter(channel),
17
+ })
18
+ .exec();
19
+ }
20
+ }
@@ -0,0 +1,21 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { InjectModel } from '@nestjs/mongoose';
3
+ import { Model } from 'mongoose';
4
+
5
+ import { GameStatistic, GameStatisticDocument } from '..';
6
+ import { getChannelRegExpFilter } from '../utils';
7
+
8
+ @Injectable()
9
+ export class GameStatisticRepository {
10
+ constructor (@InjectModel(GameStatistic.name) private gameStatisticModel: Model<GameStatisticDocument>) {
11
+ }
12
+
13
+ async findGameStatistic (channel: string, game: string): Promise<Array<GameStatistic> | null> {
14
+ return this.gameStatisticModel
15
+ .find({
16
+ channels: getChannelRegExpFilter(channel),
17
+ })
18
+ .exec();
19
+ }
20
+ }
21
+
@@ -9,6 +9,9 @@ import { ServersRepository } from './servers.repository';
9
9
  import { UsersRepository } from './users.repository';
10
10
  import { MenuRepository } from './menu.repository';
11
11
  import { RuleRepository } from './rule.repository';
12
+ import { RatingRepository } from './rating.repository';
13
+ import { GameStatisticRepository } from './game-statistic.repository';
14
+ import { FriendRepository } from './friend.repository';
12
15
  import { SettingRepository } from './setting.repository';
13
16
  import { PremiumRepository } from './premium.repository';
14
17
  import { WelcomeRepository } from './welcome.repository';
@@ -33,7 +36,10 @@ export {
33
36
  ServersRepository,
34
37
  UsersRepository,
35
38
  MenuRepository,
39
+ RatingRepository,
40
+ GameStatisticRepository,
36
41
  RuleRepository,
42
+ FriendRepository,
37
43
  SettingRepository,
38
44
  PremiumRepository,
39
45
  WelcomeRepository,
@@ -0,0 +1,84 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { InjectModel } from '@nestjs/mongoose';
3
+ import { Model } from 'mongoose';
4
+
5
+ import { Rating, RatingDocument } from '..';
6
+ import { getChannelRegExpFilter } from '../utils';
7
+ import { IRatingMonthlyResult } from '../models/rating-monthly-result.interface';
8
+
9
+ @Injectable()
10
+ export class RatingRepository {
11
+ constructor(@InjectModel(Rating.name) private ratingModel: Model<RatingDocument>) {
12
+ }
13
+
14
+ async findRating(channel: string, game: string): Promise<Array<Rating> | null> {
15
+ return this.ratingModel
16
+ .find({
17
+ channels: getChannelRegExpFilter(channel),
18
+
19
+ })
20
+ .exec();
21
+ }
22
+
23
+ async addBulkPlayerRating(items: Array<Rating>): Promise<void> {
24
+ this.ratingModel.insertMany(items);
25
+ }
26
+
27
+ async getMonthlyRatingList(game: string, startDate: Date, endDate: Date): Promise<Array<IRatingMonthlyResult>> {
28
+ return this.ratingModel.aggregate([
29
+ {
30
+ $match: {
31
+ game,
32
+ date: {
33
+ $gte: startDate,
34
+ $lte: endDate,
35
+ },
36
+ }
37
+ },
38
+ {
39
+ $group:
40
+ {
41
+ _id: {
42
+ userId: "$userId",
43
+ date: {
44
+ $dateToString: {
45
+ format: "%Y-%m",
46
+ date: "$date"
47
+ }
48
+ }
49
+ },
50
+ userId: { $first: "$userId" },
51
+ userName: { $first: "$userName" },
52
+ userAvatarUrl: { $first: "$userAvatarUrl" },
53
+ game: { $first: "$game" },
54
+ channels: { $first: "$channels" },
55
+ count: { $sum: 1 },
56
+ profit: { $sum: "$profit" }
57
+ }
58
+ },
59
+ {
60
+ $sort: { profit: -1 }
61
+ },
62
+ {
63
+ $setWindowFields: {
64
+ sortBy: { profit: -1 },
65
+ output: { rank: { $rank: {} } }
66
+ }
67
+ },
68
+ {
69
+ $project: {
70
+ _id: 0,
71
+ id: { $concat: ["$_id.userId", "_", "$_id.date"] },
72
+ userId: 1,
73
+ userName: 1,
74
+ userAvatarUrl: 1,
75
+ game: 1,
76
+ channels: 1,
77
+ count: 1,
78
+ date: "$_id.date",
79
+ rank: 1,
80
+ }
81
+ }
82
+ ]);
83
+ }
84
+ }
@@ -31,7 +31,7 @@ export class ActivityLog {
31
31
  game: string;
32
32
 
33
33
  @Prop()
34
- channel: string;
34
+ channels: string;
35
35
  }
36
36
 
37
37
  export const ActivityLogSchema = SchemaFactory.createForClass(ActivityLog);
@@ -0,0 +1,51 @@
1
+ import { Prop, Schema, SchemaFactory, Virtual } from '@nestjs/mongoose';
2
+ import { Document, HydratedDocument } from 'mongoose';
3
+
4
+ export type FriendDocument = HydratedDocument<Friend>;
5
+
6
+ @Schema({ collection: 'friends' })
7
+ export class Friend {
8
+ @Virtual({
9
+ get: function (this: Document) {
10
+ return this._id.toString();
11
+ },
12
+ })
13
+ readonly ruleId: string;
14
+
15
+ @Prop()
16
+ id: string;
17
+
18
+ @Prop()
19
+ icon: string;
20
+
21
+ @Prop()
22
+ title: string;
23
+
24
+ @Prop()
25
+ titleEn: string;
26
+
27
+ @Prop()
28
+ userId: string;
29
+
30
+ @Prop()
31
+ avatarUrl: string;
32
+
33
+ @Prop()
34
+ userName: string;
35
+
36
+ @Prop()
37
+ level: number;
38
+
39
+ @Prop()
40
+ url: string;
41
+
42
+ @Prop()
43
+ game: string;
44
+
45
+ @Prop()
46
+ channel: string;
47
+
48
+
49
+ }
50
+
51
+ export const FriendSchema = SchemaFactory.createForClass(Friend);
@@ -0,0 +1,40 @@
1
+ import { Prop, Schema, SchemaFactory, Virtual } from '@nestjs/mongoose';
2
+ import { Document, HydratedDocument } from 'mongoose';
3
+
4
+ export type GameStatisticDocument = HydratedDocument<GameStatistic>;
5
+
6
+ @Schema({ collection: 'game_statistics' })
7
+ export class GameStatistic {
8
+ @Virtual({
9
+ get: function (this: Document) {
10
+ return this._id.toString();
11
+ },
12
+ })
13
+ readonly gameStatisticId: string;
14
+
15
+ @Prop()
16
+ code: string;
17
+
18
+ @Prop()
19
+ title: string;
20
+
21
+ @Prop()
22
+ titleEn: string;
23
+
24
+ @Prop()
25
+ icon: string;
26
+
27
+ @Prop()
28
+ url: string;
29
+
30
+ @Prop()
31
+ position: number;
32
+
33
+ @Prop()
34
+ game: string;
35
+
36
+ @Prop()
37
+ channel: string;
38
+ }
39
+
40
+ export const GameStatisticSchema = SchemaFactory.createForClass(GameStatistic);
@@ -13,10 +13,7 @@ export class Rating {
13
13
  readonly achievementId: string;
14
14
 
15
15
  @Prop()
16
- day: string;
17
-
18
- @Prop()
19
- month: string;
16
+ date: Date;
20
17
 
21
18
  @Prop()
22
19
  userId: string;
@@ -31,16 +28,10 @@ export class Rating {
31
28
  profit: number;
32
29
 
33
30
  @Prop()
34
- lost: number
35
-
36
- @Prop()
37
- gamesPlayed: number;
38
-
39
- @Prop()
40
- gamesWon: number;
31
+ game: string;
41
32
 
42
33
  @Prop()
43
- game: string;
34
+ channels: string;
44
35
  }
45
36
 
46
37
  export const RatingSchema = SchemaFactory.createForClass(Rating);