jp.db.schemas 2.2.10 → 2.2.12

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 (113) hide show
  1. package/dist/index.d.ts +8 -8
  2. package/dist/index.js +9 -9
  3. package/dist/repositories/index.d.ts +3 -3
  4. package/dist/repositories/index.js +5 -5
  5. package/dist/repositories/many-tables-tournament-rooms.repository.d.ts +21 -0
  6. package/dist/repositories/many-tables-tournament-rooms.repository.d.ts.map +1 -0
  7. package/dist/repositories/{tournament-many-tables-rooms.repository.js → many-tables-tournament-rooms.repository.js} +8 -8
  8. package/dist/repositories/many-tables-tournament-rooms.repository.js.map +1 -0
  9. package/dist/repositories/one-table-tournament-rooms.repository.d.ts +18 -0
  10. package/dist/repositories/{tournament-one-table-rooms.repository.d.ts.map → one-table-tournament-rooms.repository.d.ts.map} +1 -1
  11. package/dist/repositories/{tournament-one-table-rooms.repository.js → one-table-tournament-rooms.repository.js} +8 -8
  12. package/dist/repositories/{tournament-one-table-rooms.repository.js.map → one-table-tournament-rooms.repository.js.map} +1 -1
  13. package/dist/schemas/{tournament_many_tables_rooms.schema.d.ts → many_tables_tournament_rooms.schema.d.ts} +52 -52
  14. package/dist/schemas/{tournament_many_tables_rooms.schema.d.ts.map → many_tables_tournament_rooms.schema.d.ts.map} +1 -1
  15. package/dist/schemas/{tournament_many_tables_rooms.schema.js → many_tables_tournament_rooms.schema.js} +29 -29
  16. package/dist/schemas/{tournament_many_tables_rooms.schema.js.map → many_tables_tournament_rooms.schema.js.map} +1 -1
  17. package/dist/schemas/{tournament_one_table_rooms.schema.d.ts → one_table_tournament_rooms.schema.d.ts} +50 -50
  18. package/dist/schemas/{tournament_one_table_rooms.schema.d.ts.map → one_table_tournament_rooms.schema.d.ts.map} +1 -1
  19. package/dist/schemas/{tournament_one_table_rooms.schema.js → one_table_tournament_rooms.schema.js} +28 -28
  20. package/dist/schemas/{tournament_one_table_rooms.schema.js.map → one_table_tournament_rooms.schema.js.map} +1 -1
  21. package/dist/schemas/premium.schema.js.map +1 -1
  22. package/dist/schemas/product.schema.js.map +1 -1
  23. package/dist/schemas/rule.schema.js.map +1 -1
  24. package/dist/schemas/setting.schema.js.map +1 -1
  25. package/dist/schemas/settings_option.schema.js.map +1 -1
  26. package/dist/schemas/welcome.schema.js.map +1 -1
  27. package/package.json +37 -37
  28. package/readme.md +3 -3
  29. package/src/index.ts +294 -294
  30. package/src/models/account-type.enum.ts +8 -8
  31. package/src/models/activity-log-user-login.interface.ts +10 -10
  32. package/src/models/activity-log.enum.ts +8 -8
  33. package/src/models/currency.enum.ts +6 -6
  34. package/src/models/rating-add-bulk-item.interface.ts +7 -7
  35. package/src/models/rating-monthly-result.interface.ts +11 -11
  36. package/src/models/tournament-participant.interface.ts +5 -5
  37. package/src/models/tournament-status.enum.ts +6 -6
  38. package/src/models/tournament-template.enum.ts +3 -3
  39. package/src/models/tournament-winner.interface.ts +7 -7
  40. package/src/models/users-balance-reason.enum.ts +8 -8
  41. package/src/repositories/achievement.repository.ts +17 -17
  42. package/src/repositories/activity-log.repository.ts +209 -209
  43. package/src/repositories/admin.repository.ts +20 -20
  44. package/src/repositories/article.repository.ts +24 -24
  45. package/src/repositories/banners.repository.ts +60 -60
  46. package/src/repositories/complains.repository.ts +31 -31
  47. package/src/repositories/daily-bonus.repository.ts +32 -32
  48. package/src/repositories/friend.repository.ts +24 -24
  49. package/src/repositories/game-result.repository.ts +19 -19
  50. package/src/repositories/game-statistic.repository.ts +25 -25
  51. package/src/repositories/index.ts +61 -61
  52. package/src/repositories/{tournament-many-tables-rooms.repository.ts → many-tables-tournament-rooms.repository.ts} +167 -171
  53. package/src/repositories/menu.repository.ts +19 -19
  54. package/src/repositories/notification.repository.ts +59 -59
  55. package/src/repositories/{tournament-one-table-rooms.repository.ts → one-table-tournament-rooms.repository.ts} +142 -142
  56. package/src/repositories/premium.repository.ts +16 -16
  57. package/src/repositories/products.repository.ts +30 -30
  58. package/src/repositories/purchase.repository.ts +111 -111
  59. package/src/repositories/rating.repository.ts +90 -90
  60. package/src/repositories/rooms.repository.ts +14 -14
  61. package/src/repositories/rule.repository.ts +14 -14
  62. package/src/repositories/scheduled-tournaments.repository.ts +35 -35
  63. package/src/repositories/servers.repository.ts +16 -16
  64. package/src/repositories/setting.repository.ts +24 -24
  65. package/src/repositories/settings-options.repository.ts +17 -17
  66. package/src/repositories/simple-rooms.repository.ts +16 -16
  67. package/src/repositories/users-achievements.repository.ts +46 -46
  68. package/src/repositories/users-balances.repository.ts +65 -65
  69. package/src/repositories/users.repository.ts +153 -153
  70. package/src/repositories/welcome.repository.ts +16 -16
  71. package/src/schemas/achievement.schema.ts +40 -40
  72. package/src/schemas/activity_log.schema.ts +37 -37
  73. package/src/schemas/admin.schema.ts +22 -22
  74. package/src/schemas/article.schema.ts +37 -37
  75. package/src/schemas/banner.schema.ts +40 -40
  76. package/src/schemas/channel_message.schema.ts +32 -32
  77. package/src/schemas/complain.schema.ts +46 -46
  78. package/src/schemas/daily_bonus.schema.ts +49 -49
  79. package/src/schemas/feature.schema.ts +28 -28
  80. package/src/schemas/friend.schema.ts +49 -49
  81. package/src/schemas/game_result.schema.ts +68 -68
  82. package/src/schemas/game_statistic.schema.ts +40 -40
  83. package/src/schemas/{tournament_many_tables_rooms.schema.ts → many_tables_tournament_rooms.schema.ts} +87 -87
  84. package/src/schemas/menu.schema.ts +37 -37
  85. package/src/schemas/notification.schema.ts +61 -61
  86. package/src/schemas/{tournament_one_table_rooms.schema.ts → one_table_tournament_rooms.schema.ts} +84 -84
  87. package/src/schemas/premium.schema.ts +37 -37
  88. package/src/schemas/product.schema.ts +111 -111
  89. package/src/schemas/purchase.schema.ts +61 -61
  90. package/src/schemas/purchase_channel.schema.ts +32 -32
  91. package/src/schemas/rating.schema.ts +37 -37
  92. package/src/schemas/rooms.schema.ts +63 -63
  93. package/src/schemas/rule.schema.ts +37 -37
  94. package/src/schemas/scheduled_tournament.schema.ts +94 -94
  95. package/src/schemas/server.schema.ts +22 -22
  96. package/src/schemas/setting.schema.ts +49 -49
  97. package/src/schemas/settings_option.schema.ts +41 -41
  98. package/src/schemas/simple_rooms.schema.ts +49 -49
  99. package/src/schemas/user.fb.schema.ts +33 -33
  100. package/src/schemas/user.google.schema.ts +24 -24
  101. package/src/schemas/user.ok.schema.ts +53 -53
  102. package/src/schemas/user.schema.ts +160 -160
  103. package/src/schemas/user.tg.schema.ts +30 -30
  104. package/src/schemas/user.vk.schema.ts +70 -70
  105. package/src/schemas/user.ya.schema.ts +24 -24
  106. package/src/schemas/users_achievement.schema.ts +41 -41
  107. package/src/schemas/users_balance.schema.ts +34 -34
  108. package/src/schemas/welcome.schema.ts +37 -37
  109. package/src/utils.ts +3 -3
  110. package/dist/repositories/tournament-many-tables-rooms.repository.d.ts +0 -21
  111. package/dist/repositories/tournament-many-tables-rooms.repository.d.ts.map +0 -1
  112. package/dist/repositories/tournament-many-tables-rooms.repository.js.map +0 -1
  113. package/dist/repositories/tournament-one-table-rooms.repository.d.ts +0 -18
@@ -1,142 +1,142 @@
1
- import { Injectable } from '@nestjs/common';
2
- import { InjectModel } from '@nestjs/mongoose';
3
- import { Model } from 'mongoose';
4
- import dayjs from 'dayjs';
5
-
6
- import { TournamentOneTableRoom, TournamentOneTableRoomDocument } from '../';
7
- import { ITournamentParticipant } from '../models/tournament-participant.interface';
8
- import { TournamentStatusEnum } from '../models/tournament-status.enum';
9
- import { ITournamentWinner } from '../models/tournament-winner.interface';
10
- import { TournamentTemplateEnum } from '../models/tournament-template.enum';
11
-
12
- @Injectable()
13
- export class TournamentOneTableRoomsRepository {
14
- constructor(
15
- @InjectModel(TournamentOneTableRoom.name)
16
- private tournamentModel: Model<TournamentOneTableRoomDocument>,
17
- ) {}
18
-
19
- async findTournamentById(
20
- tournamentId: string,
21
- ): Promise<TournamentOneTableRoomDocument | null> {
22
- return this.tournamentModel.findById(tournamentId).exec();
23
- }
24
-
25
- async findTemplateById(
26
- templateId: string,
27
- gameType: string,
28
- ): Promise<TournamentOneTableRoomDocument | null> {
29
- return this.tournamentModel
30
- .findOne({ isTemplate: true, templateId, gameType })
31
- .exec();
32
- }
33
-
34
- async findActualTournaments(
35
- gameType: string,
36
- ): Promise<Array<TournamentOneTableRoomDocument>> {
37
- return this.tournamentModel
38
- .find({
39
- $and: [
40
- {
41
- isTemplate: false,
42
- gameType,
43
- },
44
- {
45
- $or: [
46
- { status: TournamentStatusEnum.STATE_WAITING_FOR_START },
47
- { finishDate: { $gte: dayjs().subtract(1, 'hour').toDate() } },
48
- ],
49
- },
50
- ],
51
- })
52
- .exec();
53
- }
54
-
55
- async findWaitingTournament(
56
- gameType: string,
57
- ): Promise<TournamentOneTableRoomDocument | null> {
58
- return this.tournamentModel
59
- .findOne({
60
- gameType,
61
- status: TournamentStatusEnum.STATE_WAITING_FOR_START,
62
- isTemplate: false,
63
- })
64
- .exec();
65
- }
66
-
67
- async createTournament(
68
- tournament: Partial<TournamentOneTableRoom>,
69
- ): Promise<TournamentOneTableRoomDocument> {
70
- return this.tournamentModel.create(tournament);
71
- }
72
-
73
- async createTournamentFromMasterTemplate(
74
- gameType: string,
75
- ): Promise<TournamentOneTableRoomDocument> {
76
- const masterTemplate = await this.findTemplateById(
77
- TournamentTemplateEnum.MASTER,
78
- gameType,
79
- );
80
-
81
- return this.createTournament({
82
- title: masterTemplate.title,
83
- subtitle: masterTemplate.subtitle,
84
- description: masterTemplate.description,
85
- tableSize: masterTemplate.tableSize,
86
- bet: masterTemplate.bet,
87
- ticketPrice: masterTemplate.ticketPrice,
88
- roomType: masterTemplate.roomType,
89
- gameType: masterTemplate.gameType,
90
- rulesType: masterTemplate.rulesType,
91
- deckType: masterTemplate.deckType,
92
- maxParticipants: masterTemplate.maxParticipants,
93
- participants: masterTemplate.participants,
94
- status: masterTemplate.status,
95
- winners: masterTemplate.winners,
96
- createDate: new Date(),
97
- isTemplate: false,
98
- templateId: undefined,
99
- });
100
- }
101
-
102
- async startTournament(
103
- tournamentId: string,
104
- participants: Array<ITournamentParticipant>,
105
- ): Promise<void> {
106
- await this.tournamentModel
107
- .findByIdAndUpdate(tournamentId, {
108
- $set: {
109
- startDate: new Date(),
110
- status: TournamentStatusEnum.STATE_IN_PROGRESS,
111
- participants,
112
- },
113
- })
114
- .exec();
115
- }
116
-
117
- async cancelTournament(tournamentId: string): Promise<void> {
118
- await this.tournamentModel
119
- .findByIdAndUpdate(tournamentId, {
120
- $set: {
121
- finishDate: new Date(),
122
- status: TournamentStatusEnum.STATE_CANCELLED,
123
- },
124
- })
125
- .exec();
126
- }
127
-
128
- async finishTournament(
129
- tournamentId: string,
130
- winners: Array<ITournamentWinner>,
131
- ): Promise<void> {
132
- await this.tournamentModel
133
- .findByIdAndUpdate(tournamentId, {
134
- $set: {
135
- finishDate: new Date(),
136
- status: TournamentStatusEnum.STATE_FINISHED,
137
- winners,
138
- },
139
- })
140
- .exec();
141
- }
142
- }
1
+ import { Injectable } from '@nestjs/common';
2
+ import { InjectModel } from '@nestjs/mongoose';
3
+ import { Model } from 'mongoose';
4
+ import dayjs from 'dayjs';
5
+
6
+ import { OneTableTournamentRoom, OneTableTournamentRoomDocument } from '..';
7
+ import { ITournamentParticipant } from '../models/tournament-participant.interface';
8
+ import { TournamentStatusEnum } from '../models/tournament-status.enum';
9
+ import { ITournamentWinner } from '../models/tournament-winner.interface';
10
+ import { TournamentTemplateEnum } from '../models/tournament-template.enum';
11
+
12
+ @Injectable()
13
+ export class OneTableTournamentRoomsRepository {
14
+ constructor(
15
+ @InjectModel(OneTableTournamentRoom.name)
16
+ private tournamentModel: Model<OneTableTournamentRoomDocument>,
17
+ ) {}
18
+
19
+ async findTournamentById(
20
+ tournamentId: string,
21
+ ): Promise<OneTableTournamentRoomDocument | null> {
22
+ return this.tournamentModel.findById(tournamentId).exec();
23
+ }
24
+
25
+ async findTemplateById(
26
+ templateId: string,
27
+ gameType: string,
28
+ ): Promise<OneTableTournamentRoomDocument | null> {
29
+ return this.tournamentModel
30
+ .findOne({ isTemplate: true, templateId, gameType })
31
+ .exec();
32
+ }
33
+
34
+ async findActualTournaments(
35
+ gameType: string,
36
+ ): Promise<Array<OneTableTournamentRoomDocument>> {
37
+ return this.tournamentModel
38
+ .find({
39
+ $and: [
40
+ {
41
+ isTemplate: false,
42
+ gameType,
43
+ },
44
+ {
45
+ $or: [
46
+ { status: TournamentStatusEnum.STATE_WAITING_FOR_START },
47
+ { finishDate: { $gte: dayjs().subtract(1, 'hour').toDate() } },
48
+ ],
49
+ },
50
+ ],
51
+ })
52
+ .exec();
53
+ }
54
+
55
+ async findWaitingTournament(
56
+ gameType: string,
57
+ ): Promise<OneTableTournamentRoomDocument | null> {
58
+ return this.tournamentModel
59
+ .findOne({
60
+ gameType,
61
+ status: TournamentStatusEnum.STATE_WAITING_FOR_START,
62
+ isTemplate: false,
63
+ })
64
+ .exec();
65
+ }
66
+
67
+ async createTournament(
68
+ tournament: Partial<OneTableTournamentRoom>,
69
+ ): Promise<OneTableTournamentRoomDocument> {
70
+ return this.tournamentModel.create(tournament);
71
+ }
72
+
73
+ async createTournamentFromMasterTemplate(
74
+ gameType: string,
75
+ ): Promise<OneTableTournamentRoomDocument> {
76
+ const masterTemplate = await this.findTemplateById(
77
+ TournamentTemplateEnum.MASTER,
78
+ gameType,
79
+ );
80
+
81
+ return this.createTournament({
82
+ title: masterTemplate.title,
83
+ subtitle: masterTemplate.subtitle,
84
+ description: masterTemplate.description,
85
+ tableSize: masterTemplate.tableSize,
86
+ bet: masterTemplate.bet,
87
+ ticketPrice: masterTemplate.ticketPrice,
88
+ roomType: masterTemplate.roomType,
89
+ gameType: masterTemplate.gameType,
90
+ rulesType: masterTemplate.rulesType,
91
+ deckType: masterTemplate.deckType,
92
+ maxParticipants: masterTemplate.maxParticipants,
93
+ participants: masterTemplate.participants,
94
+ status: masterTemplate.status,
95
+ winners: masterTemplate.winners,
96
+ createDate: new Date(),
97
+ isTemplate: false,
98
+ templateId: undefined,
99
+ });
100
+ }
101
+
102
+ async startTournament(
103
+ tournamentId: string,
104
+ participants: Array<ITournamentParticipant>,
105
+ ): Promise<void> {
106
+ await this.tournamentModel
107
+ .findByIdAndUpdate(tournamentId, {
108
+ $set: {
109
+ startDate: new Date(),
110
+ status: TournamentStatusEnum.STATE_IN_PROGRESS,
111
+ participants,
112
+ },
113
+ })
114
+ .exec();
115
+ }
116
+
117
+ async cancelTournament(tournamentId: string): Promise<void> {
118
+ await this.tournamentModel
119
+ .findByIdAndUpdate(tournamentId, {
120
+ $set: {
121
+ finishDate: new Date(),
122
+ status: TournamentStatusEnum.STATE_CANCELLED,
123
+ },
124
+ })
125
+ .exec();
126
+ }
127
+
128
+ async finishTournament(
129
+ tournamentId: string,
130
+ winners: Array<ITournamentWinner>,
131
+ ): Promise<void> {
132
+ await this.tournamentModel
133
+ .findByIdAndUpdate(tournamentId, {
134
+ $set: {
135
+ finishDate: new Date(),
136
+ status: TournamentStatusEnum.STATE_FINISHED,
137
+ winners,
138
+ },
139
+ })
140
+ .exec();
141
+ }
142
+ }
@@ -1,16 +1,16 @@
1
- import { Injectable } from '@nestjs/common';
2
- import { InjectModel } from '@nestjs/mongoose';
3
- import { Model } from 'mongoose';
4
-
5
- import { Premium, PremiumDocument } from '..';
6
-
7
- @Injectable()
8
- export class PremiumRepository {
9
- constructor(
10
- @InjectModel(Premium.name) private premiumModel: Model<PremiumDocument>,
11
- ) {}
12
-
13
- async findPremium(gameType: string): Promise<Premium | null> {
14
- return this.premiumModel.findOne({ gameType }).exec();
15
- }
16
- }
1
+ import { Injectable } from '@nestjs/common';
2
+ import { InjectModel } from '@nestjs/mongoose';
3
+ import { Model } from 'mongoose';
4
+
5
+ import { Premium, PremiumDocument } from '..';
6
+
7
+ @Injectable()
8
+ export class PremiumRepository {
9
+ constructor(
10
+ @InjectModel(Premium.name) private premiumModel: Model<PremiumDocument>,
11
+ ) {}
12
+
13
+ async findPremium(gameType: string): Promise<Premium | null> {
14
+ return this.premiumModel.findOne({ gameType }).exec();
15
+ }
16
+ }
@@ -1,30 +1,30 @@
1
- import { Injectable } from '@nestjs/common';
2
- import { InjectModel } from '@nestjs/mongoose';
3
- import { Model } from 'mongoose';
4
-
5
- import { Product, ProductDocument } from '../';
6
- import { getChannelRegExpFilter } from '../utils';
7
-
8
- @Injectable()
9
- export class ProductsRepository {
10
- constructor(
11
- @InjectModel(Product.name) private productModel: Model<ProductDocument>,
12
- ) {}
13
-
14
- async findByProductId(productId: string): Promise<Product | null> {
15
- return this.productModel.findOne({ productId }).exec();
16
- }
17
-
18
- async findProducts(
19
- parentId: string | null,
20
- channel: string,
21
- ): Promise<Array<Product> | null> {
22
- return this.productModel
23
- .find({
24
- parentId,
25
- active: true,
26
- channels: getChannelRegExpFilter(channel),
27
- })
28
- .exec();
29
- }
30
- }
1
+ import { Injectable } from '@nestjs/common';
2
+ import { InjectModel } from '@nestjs/mongoose';
3
+ import { Model } from 'mongoose';
4
+
5
+ import { Product, ProductDocument } from '../';
6
+ import { getChannelRegExpFilter } from '../utils';
7
+
8
+ @Injectable()
9
+ export class ProductsRepository {
10
+ constructor(
11
+ @InjectModel(Product.name) private productModel: Model<ProductDocument>,
12
+ ) {}
13
+
14
+ async findByProductId(productId: string): Promise<Product | null> {
15
+ return this.productModel.findOne({ productId }).exec();
16
+ }
17
+
18
+ async findProducts(
19
+ parentId: string | null,
20
+ channel: string,
21
+ ): Promise<Array<Product> | null> {
22
+ return this.productModel
23
+ .find({
24
+ parentId,
25
+ active: true,
26
+ channels: getChannelRegExpFilter(channel),
27
+ })
28
+ .exec();
29
+ }
30
+ }
@@ -1,111 +1,111 @@
1
- import { Injectable } from '@nestjs/common';
2
- import { InjectModel } from '@nestjs/mongoose';
3
- import { Model } from 'mongoose';
4
-
5
- import { Purchase, PurchaseDocument } from '..';
6
- import { CurrencyEnum } from '../models/currency.enum';
7
-
8
- @Injectable()
9
- export class PurchaseRepository {
10
- constructor(
11
- @InjectModel(Purchase.name) private purchaseModel: Model<PurchaseDocument>,
12
- ) {}
13
-
14
- async findPurchasesByUserId(userId: string): Promise<Array<Purchase>> {
15
- return this.purchaseModel.find({ userId }).exec();
16
- }
17
-
18
- async findPurchaseByVKOrderId(vkOrderId: number): Promise<Purchase | null> {
19
- return this.purchaseModel.findOne({ vkOrderId }).exec();
20
- }
21
-
22
- async findPurchaseByYaOrderId(yaOrderId: string): Promise<Purchase | null> {
23
- return this.purchaseModel.findOne({ yaOrderId }).exec();
24
- }
25
-
26
- async addVKPurchase(
27
- userId: string,
28
- userName: string,
29
- productId: string,
30
- productCode: string,
31
- productName: string,
32
- price: number,
33
- vkOrderId: number,
34
- token: string,
35
- game: string,
36
- ): Promise<Purchase> {
37
- return this.addPurchase({
38
- userId,
39
- userName,
40
- productId,
41
- productCode,
42
- productName,
43
- price,
44
- currency: CurrencyEnum.VK_VOTES,
45
- vkOrderId,
46
- token,
47
- game,
48
- });
49
- }
50
-
51
- async addYAPUrchase(
52
- userId: string,
53
- userName: string,
54
- productId: string,
55
- productCode: string,
56
- productName: string,
57
- price: number,
58
- yaOrderId: string,
59
- token: string,
60
- game: string,
61
- ): Promise<Purchase> {
62
- return this.addPurchase({
63
- userId,
64
- userName,
65
- productId,
66
- productCode,
67
- productName,
68
- price,
69
- currency: CurrencyEnum.YAN,
70
- yaOrderId,
71
- token,
72
- game,
73
- });
74
- }
75
-
76
- async addManyTablesTournamentTicketPurchase(
77
- userId: string,
78
- userName: string,
79
- tournamentId: string,
80
- price: number,
81
- game: string,
82
- ): Promise<Purchase> {
83
- return this.addPurchase({
84
- userId,
85
- userName,
86
- productId: '6a192b118e596305dc9d0484',
87
- productCode: 'tournament_ticket__evening',
88
- productName: 'Ticket on evenint tournament',
89
- tournamentId,
90
- price,
91
- currency: CurrencyEnum.JP,
92
- game,
93
- });
94
- }
95
-
96
- async addPurchase(purchase: Partial<Purchase>): Promise<Purchase> {
97
- return this.purchaseModel.create(purchase);
98
- }
99
-
100
- async removeByVKOkderId(vkOrderId: number): Promise<Purchase | null> {
101
- return this.purchaseModel
102
- .findOneAndUpdate(
103
- { vkOrderId },
104
- {
105
- removed: true,
106
- },
107
- { new: true },
108
- )
109
- .exec();
110
- }
111
- }
1
+ import { Injectable } from '@nestjs/common';
2
+ import { InjectModel } from '@nestjs/mongoose';
3
+ import { Model } from 'mongoose';
4
+
5
+ import { Purchase, PurchaseDocument } from '..';
6
+ import { CurrencyEnum } from '../models/currency.enum';
7
+
8
+ @Injectable()
9
+ export class PurchaseRepository {
10
+ constructor(
11
+ @InjectModel(Purchase.name) private purchaseModel: Model<PurchaseDocument>,
12
+ ) {}
13
+
14
+ async findPurchasesByUserId(userId: string): Promise<Array<Purchase>> {
15
+ return this.purchaseModel.find({ userId }).exec();
16
+ }
17
+
18
+ async findPurchaseByVKOrderId(vkOrderId: number): Promise<Purchase | null> {
19
+ return this.purchaseModel.findOne({ vkOrderId }).exec();
20
+ }
21
+
22
+ async findPurchaseByYaOrderId(yaOrderId: string): Promise<Purchase | null> {
23
+ return this.purchaseModel.findOne({ yaOrderId }).exec();
24
+ }
25
+
26
+ async addVKPurchase(
27
+ userId: string,
28
+ userName: string,
29
+ productId: string,
30
+ productCode: string,
31
+ productName: string,
32
+ price: number,
33
+ vkOrderId: number,
34
+ token: string,
35
+ game: string,
36
+ ): Promise<Purchase> {
37
+ return this.addPurchase({
38
+ userId,
39
+ userName,
40
+ productId,
41
+ productCode,
42
+ productName,
43
+ price,
44
+ currency: CurrencyEnum.VK_VOTES,
45
+ vkOrderId,
46
+ token,
47
+ game,
48
+ });
49
+ }
50
+
51
+ async addYAPUrchase(
52
+ userId: string,
53
+ userName: string,
54
+ productId: string,
55
+ productCode: string,
56
+ productName: string,
57
+ price: number,
58
+ yaOrderId: string,
59
+ token: string,
60
+ game: string,
61
+ ): Promise<Purchase> {
62
+ return this.addPurchase({
63
+ userId,
64
+ userName,
65
+ productId,
66
+ productCode,
67
+ productName,
68
+ price,
69
+ currency: CurrencyEnum.YAN,
70
+ yaOrderId,
71
+ token,
72
+ game,
73
+ });
74
+ }
75
+
76
+ async addManyTablesTournamentTicketPurchase(
77
+ userId: string,
78
+ userName: string,
79
+ tournamentId: string,
80
+ price: number,
81
+ game: string,
82
+ ): Promise<Purchase> {
83
+ return this.addPurchase({
84
+ userId,
85
+ userName,
86
+ productId: '6a192b118e596305dc9d0484',
87
+ productCode: 'tournament_ticket__evening',
88
+ productName: 'Ticket on evenint tournament',
89
+ tournamentId,
90
+ price,
91
+ currency: CurrencyEnum.JP,
92
+ game,
93
+ });
94
+ }
95
+
96
+ async addPurchase(purchase: Partial<Purchase>): Promise<Purchase> {
97
+ return this.purchaseModel.create(purchase);
98
+ }
99
+
100
+ async removeByVKOkderId(vkOrderId: number): Promise<Purchase | null> {
101
+ return this.purchaseModel
102
+ .findOneAndUpdate(
103
+ { vkOrderId },
104
+ {
105
+ removed: true,
106
+ },
107
+ { new: true },
108
+ )
109
+ .exec();
110
+ }
111
+ }