jp.db.schemas 1.0.18 → 1.0.20
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/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/dist/repositories/admin.repository.d.ts +9 -0
- package/dist/repositories/admin.repository.d.ts.map +1 -0
- package/dist/repositories/admin.repository.js +41 -0
- package/dist/repositories/admin.repository.js.map +1 -0
- package/dist/repositories/article.repository.d.ts +10 -0
- package/dist/repositories/article.repository.d.ts.map +1 -0
- package/dist/repositories/article.repository.js +50 -0
- package/dist/repositories/article.repository.js.map +1 -0
- package/dist/repositories/banners.repository.d.ts +15 -0
- package/dist/repositories/banners.repository.d.ts.map +1 -0
- package/dist/repositories/banners.repository.js +60 -0
- package/dist/repositories/banners.repository.js.map +1 -0
- package/dist/repositories/complains.repository.d.ts +11 -0
- package/dist/repositories/complains.repository.d.ts.map +1 -0
- package/dist/repositories/complains.repository.js +44 -0
- package/dist/repositories/complains.repository.js.map +1 -0
- package/dist/repositories/index.d.ts +12 -0
- package/dist/repositories/index.d.ts.map +1 -0
- package/dist/repositories/index.js +24 -0
- package/dist/repositories/index.js.map +1 -0
- package/dist/repositories/menu.repository.d.ts +8 -0
- package/dist/repositories/menu.repository.d.ts.map +1 -0
- package/dist/repositories/menu.repository.js +39 -0
- package/dist/repositories/menu.repository.js.map +1 -0
- package/dist/repositories/notification.repository.d.ts +15 -0
- package/dist/repositories/notification.repository.d.ts.map +1 -0
- package/dist/repositories/notification.repository.js +60 -0
- package/dist/repositories/notification.repository.js.map +1 -0
- package/dist/repositories/products.repository.d.ts +9 -0
- package/dist/repositories/products.repository.d.ts.map +1 -0
- package/dist/repositories/products.repository.js +46 -0
- package/dist/repositories/products.repository.js.map +1 -0
- package/dist/repositories/scheduled-tournaments.repository.d.ts +11 -0
- package/dist/repositories/scheduled-tournaments.repository.d.ts.map +1 -0
- package/dist/repositories/scheduled-tournaments.repository.js +44 -0
- package/dist/repositories/scheduled-tournaments.repository.js.map +1 -0
- package/dist/repositories/servers.repository.d.ts +8 -0
- package/dist/repositories/servers.repository.d.ts.map +1 -0
- package/dist/repositories/servers.repository.js +36 -0
- package/dist/repositories/servers.repository.js.map +1 -0
- package/dist/repositories/users.repository.d.ts +15 -0
- package/dist/repositories/users.repository.d.ts.map +1 -0
- package/dist/repositories/users.repository.js +70 -0
- package/dist/repositories/users.repository.js.map +1 -0
- package/dist/schemas/menu.schema.d.ts +23 -0
- package/dist/schemas/menu.schema.d.ts.map +1 -0
- package/dist/schemas/menu.schema.js +61 -0
- package/dist/schemas/menu.schema.js.map +1 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +7 -0
- package/dist/utils.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +31 -0
- package/src/repositories/admin.repository.ts +23 -0
- package/src/repositories/article.repository.ts +33 -0
- package/src/repositories/banners.repository.ts +54 -0
- package/src/repositories/complains.repository.ts +30 -0
- package/src/repositories/index.ts +23 -0
- package/src/repositories/menu.repository.ts +21 -0
- package/src/repositories/notification.repository.ts +54 -0
- package/src/repositories/products.repository.ts +29 -0
- package/src/repositories/scheduled-tournaments.repository.ts +30 -0
- package/src/repositories/servers.repository.ts +18 -0
- package/src/repositories/users.repository.ts +69 -0
- package/src/schemas/menu.schema.ts +40 -0
- package/src/utils.ts +3 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { InjectModel } from '@nestjs/mongoose';
|
|
3
|
+
import { Model } from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { Notification, NotificationDocument } from '../';
|
|
6
|
+
|
|
7
|
+
@Injectable()
|
|
8
|
+
export class NotificationRepository {
|
|
9
|
+
constructor (@InjectModel(Notification.name) private notificationModel: Model<NotificationDocument>) {
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async findById (id: string): Promise<Notification | null> {
|
|
13
|
+
return this.notificationModel
|
|
14
|
+
.findById(id)
|
|
15
|
+
.exec();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async findAndCount (limit: number, skip: number): Promise<{
|
|
19
|
+
items: Array<Notification>,
|
|
20
|
+
total: number
|
|
21
|
+
}> {
|
|
22
|
+
const items = await this.notificationModel
|
|
23
|
+
.find()
|
|
24
|
+
.sort({ createDate: -1 })
|
|
25
|
+
.limit(limit)
|
|
26
|
+
.skip(skip)
|
|
27
|
+
.exec();
|
|
28
|
+
|
|
29
|
+
const total = await this.notificationModel
|
|
30
|
+
.find()
|
|
31
|
+
.countDocuments()
|
|
32
|
+
.exec();
|
|
33
|
+
|
|
34
|
+
return { items, total };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public async crateNotification (notification: Notification): Promise<Notification> {
|
|
38
|
+
return this.notificationModel.create(notification);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async updateNotification (notificationId: string, notification: Partial<Notification>): Promise<void> {
|
|
42
|
+
await this.notificationModel.findByIdAndUpdate(
|
|
43
|
+
notificationId,
|
|
44
|
+
{
|
|
45
|
+
$set: {
|
|
46
|
+
...notification,
|
|
47
|
+
},
|
|
48
|
+
}).exec();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public async removeNotification (notificationId: string): Promise<void> {
|
|
52
|
+
await this.notificationModel.findByIdAndDelete(notificationId);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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 (@InjectModel(Product.name) private productModel: Model<ProductDocument>) {
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async findByProductId (productId: string): Promise<Product | null> {
|
|
14
|
+
return this.productModel
|
|
15
|
+
.findOne({ productId })
|
|
16
|
+
.exec();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async findProducts (parentId: string | null, channel: string): Promise<Array<Product> | null> {
|
|
20
|
+
return this.productModel
|
|
21
|
+
.find({
|
|
22
|
+
parentId,
|
|
23
|
+
active: true,
|
|
24
|
+
channels: getChannelRegExpFilter(channel),
|
|
25
|
+
})
|
|
26
|
+
.exec();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { InjectModel } from '@nestjs/mongoose';
|
|
3
|
+
import { Model } from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { ScheduledTournament, ScheduledTournamentDocument } from '../';
|
|
6
|
+
|
|
7
|
+
@Injectable()
|
|
8
|
+
export class ScheduledTournamentsRepository {
|
|
9
|
+
constructor (@InjectModel(ScheduledTournament.name) private scheduledTournamentModel: Model<ScheduledTournamentDocument>) {
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async findAndCount (limit: number, skip: number): Promise<{
|
|
13
|
+
items: Array<ScheduledTournament>,
|
|
14
|
+
total: number
|
|
15
|
+
}> {
|
|
16
|
+
const items = await this.scheduledTournamentModel
|
|
17
|
+
.find({ category: 'global'})
|
|
18
|
+
.sort({ date: -1 })
|
|
19
|
+
.limit(limit)
|
|
20
|
+
.skip(skip)
|
|
21
|
+
.exec();
|
|
22
|
+
|
|
23
|
+
const total = await this.scheduledTournamentModel
|
|
24
|
+
.find({ category: 'global'})
|
|
25
|
+
.countDocuments()
|
|
26
|
+
.exec();
|
|
27
|
+
|
|
28
|
+
return { items, total };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { InjectModel } from '@nestjs/mongoose';
|
|
3
|
+
import { Model } from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { Server, ServerDocument } from '../';
|
|
6
|
+
|
|
7
|
+
@Injectable()
|
|
8
|
+
export class ServersRepository {
|
|
9
|
+
constructor (@InjectModel(Server.name) private serverModel: Model<ServerDocument>) {
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async findServerByName (name: string): Promise<Server | null> {
|
|
13
|
+
return this.serverModel
|
|
14
|
+
.findOne({name})
|
|
15
|
+
.exec();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { InjectModel } from '@nestjs/mongoose';
|
|
3
|
+
import { Model } from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { User, UserDocument } from '../';
|
|
6
|
+
|
|
7
|
+
function getFullNameFilter (userName: string) {
|
|
8
|
+
const regexpName = {
|
|
9
|
+
'$regex': userName,
|
|
10
|
+
'$options': 'i',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
return userName ? { $or: [{ fullName: regexpName }, { fullNameAlias: regexpName }] } : {};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Injectable()
|
|
17
|
+
export class UsersRepository {
|
|
18
|
+
constructor (@InjectModel(User.name) private userModel: Model<UserDocument>) {
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async findById (id: string): Promise<User | null> {
|
|
22
|
+
return this.userModel
|
|
23
|
+
.findById(id)
|
|
24
|
+
.exec();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async findByVKId (vkId: number): Promise<User | null> {
|
|
28
|
+
return this.userModel
|
|
29
|
+
.findOne({ 'vkUser.id': vkId })
|
|
30
|
+
.exec();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async findAndCount (userName: string, limit: number, skip: number): Promise<{
|
|
34
|
+
items: Array<User>,
|
|
35
|
+
total: number
|
|
36
|
+
}> {
|
|
37
|
+
const items = await this.userModel
|
|
38
|
+
.find(getFullNameFilter(userName))
|
|
39
|
+
.limit(limit)
|
|
40
|
+
.skip(skip)
|
|
41
|
+
.exec();
|
|
42
|
+
|
|
43
|
+
const total = await this.userModel
|
|
44
|
+
.find(getFullNameFilter(userName))
|
|
45
|
+
.countDocuments()
|
|
46
|
+
.exec();
|
|
47
|
+
|
|
48
|
+
return { items, total };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async createUser (user: User): Promise<User> {
|
|
52
|
+
return this.userModel.create(user);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async updateUser (userId: string, user: Partial<User>, balanceAdding?: number): Promise<UserDocument | null> {
|
|
56
|
+
delete user.balance;
|
|
57
|
+
|
|
58
|
+
return this.userModel.findByIdAndUpdate(
|
|
59
|
+
userId,
|
|
60
|
+
{
|
|
61
|
+
$set: {
|
|
62
|
+
...user,
|
|
63
|
+
},
|
|
64
|
+
$inc: { balance: balanceAdding ?? 0 }
|
|
65
|
+
},
|
|
66
|
+
{ new: true },
|
|
67
|
+
).exec();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Prop, Schema, SchemaFactory, Virtual } from '@nestjs/mongoose';
|
|
2
|
+
import { Document, HydratedDocument } from 'mongoose';
|
|
3
|
+
|
|
4
|
+
export type MenuDocument = HydratedDocument<Menu>;
|
|
5
|
+
|
|
6
|
+
@Schema()
|
|
7
|
+
export class Menu {
|
|
8
|
+
@Virtual({
|
|
9
|
+
get: function (this: Document) {
|
|
10
|
+
return this.id;
|
|
11
|
+
},
|
|
12
|
+
})
|
|
13
|
+
readonly menuId: 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 MenuSchema = SchemaFactory.createForClass(Menu);
|
package/src/utils.ts
ADDED