@purpleschool/gptbot 0.6.15 → 0.6.16
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/build/commands/index.js +1 -0
- package/build/commands/user/find-users-by-criteria.command.js +36 -6
- package/build/commands/user-to-product/index.js +17 -0
- package/build/commands/user-to-product/update-user-to-product.command.js +19 -0
- package/build/commands/user-to-subscription/index.js +1 -0
- package/build/commands/user-to-subscription/update-user-to-subscription.command.js +27 -0
- package/build/models/filters.schema.js +16 -0
- package/build/models/index.js +1 -0
- package/commands/index.ts +1 -0
- package/commands/user/find-users-by-criteria.command.ts +45 -7
- package/commands/user-to-product/index.ts +1 -0
- package/commands/user-to-product/update-user-to-product.command.ts +22 -0
- package/commands/user-to-subscription/index.ts +1 -0
- package/commands/user-to-subscription/update-user-to-subscription.command.ts +30 -0
- package/models/filters.schema.ts +17 -0
- package/models/index.ts +1 -0
- package/package.json +1 -1
package/build/commands/index.js
CHANGED
|
@@ -9,24 +9,54 @@ const models_1 = require("../../models");
|
|
|
9
9
|
const constants_1 = require("../../constants");
|
|
10
10
|
var FindUsersByCriteriaCommand;
|
|
11
11
|
(function (FindUsersByCriteriaCommand) {
|
|
12
|
-
FindUsersByCriteriaCommand.RequestSchema = zod_1.default
|
|
13
|
-
.
|
|
12
|
+
FindUsersByCriteriaCommand.RequestSchema = zod_1.default.preprocess((input) => {
|
|
13
|
+
if (input && typeof input === 'object' && !Array.isArray(input)) {
|
|
14
|
+
const obj = Object.assign({}, input);
|
|
15
|
+
const onlyNormalize = ['createdAt', 'updatedAt', 'tokenBonusBalance'];
|
|
16
|
+
const relevantBracketed = Object.keys(obj).some((key) => {
|
|
17
|
+
const match = key.match(/^(\w+)\[(\w+)\]$/);
|
|
18
|
+
return match && onlyNormalize.includes(match[1]);
|
|
19
|
+
});
|
|
20
|
+
if (!relevantBracketed) {
|
|
21
|
+
return obj;
|
|
22
|
+
}
|
|
23
|
+
const result = Object.assign({}, obj);
|
|
24
|
+
for (const key of Object.keys(obj)) {
|
|
25
|
+
const match = key.match(/^(\w+)\[(\w+)\]$/);
|
|
26
|
+
if (match && onlyNormalize.includes(match[1])) {
|
|
27
|
+
const [, outer, inner] = match;
|
|
28
|
+
result[outer] = result[outer] || {};
|
|
29
|
+
result[outer][inner] = obj[key];
|
|
30
|
+
delete result[key];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
return input;
|
|
36
|
+
}, zod_1.default.object({
|
|
14
37
|
uuid: zod_1.default.string().uuid().optional(),
|
|
15
38
|
email: zod_1.default.string().email().optional(),
|
|
16
39
|
status: zod_1.default.nativeEnum(constants_1.USER_STATUS).optional(),
|
|
17
40
|
role: zod_1.default.nativeEnum(constants_1.ROLE).optional(),
|
|
18
|
-
|
|
19
|
-
|
|
41
|
+
telegramId: zod_1.default.coerce.number().optional(),
|
|
42
|
+
createdAt: models_1.DateFilter.optional(),
|
|
43
|
+
updatedAt: models_1.DateFilter.optional(),
|
|
44
|
+
tokenBonusBalance: models_1.NumberFilter.optional(),
|
|
20
45
|
sortBy: zod_1.default.nativeEnum(constants_1.USER_SORT_BY).optional(),
|
|
21
46
|
sortOrder: zod_1.default.nativeEnum(constants_1.SORT_ORDER).default(constants_1.SORT_ORDER.DESC).optional(),
|
|
22
|
-
|
|
23
|
-
.
|
|
47
|
+
limit: zod_1.default.coerce.number().min(1),
|
|
48
|
+
offset: zod_1.default.coerce.number().min(0).default(0),
|
|
49
|
+
}));
|
|
24
50
|
FindUsersByCriteriaCommand.ResponseSchema = zod_1.default.object({
|
|
25
51
|
data: zod_1.default.array(models_1.UserSchema.omit({
|
|
26
52
|
verifyTokenHash: true,
|
|
27
53
|
password: true,
|
|
28
54
|
passwordHash: true,
|
|
29
55
|
restoreTokenHash: true,
|
|
56
|
+
}).extend({
|
|
57
|
+
telegramId: zod_1.default.number().nullable(),
|
|
30
58
|
})),
|
|
59
|
+
page: zod_1.default.number(),
|
|
60
|
+
totalPages: zod_1.default.number(),
|
|
31
61
|
});
|
|
32
62
|
})(FindUsersByCriteriaCommand || (exports.FindUsersByCriteriaCommand = FindUsersByCriteriaCommand = {}));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./update-user-to-product.command"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UpdateUserToProductCommand = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const models_1 = require("../../models");
|
|
6
|
+
var UpdateUserToProductCommand;
|
|
7
|
+
(function (UpdateUserToProductCommand) {
|
|
8
|
+
UpdateUserToProductCommand.RequestParamSchema = models_1.UserToProductSchema.pick({
|
|
9
|
+
uuid: true,
|
|
10
|
+
});
|
|
11
|
+
UpdateUserToProductCommand.RequestSchema = models_1.UserToProductSchema.pick({
|
|
12
|
+
initTokenBalance: true,
|
|
13
|
+
tokenBalance: true,
|
|
14
|
+
status: true,
|
|
15
|
+
}).partial();
|
|
16
|
+
UpdateUserToProductCommand.ResponseSchema = zod_1.z.object({
|
|
17
|
+
data: UpdateUserToProductCommand.RequestParamSchema,
|
|
18
|
+
});
|
|
19
|
+
})(UpdateUserToProductCommand || (exports.UpdateUserToProductCommand = UpdateUserToProductCommand = {}));
|
|
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./get-user-to-subscriptions.command"), exports);
|
|
18
|
+
__exportStar(require("./update-user-to-subscription.command"), exports);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UpdateUserToSubscriptionCommand = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const models_1 = require("../../models");
|
|
6
|
+
var UpdateUserToSubscriptionCommand;
|
|
7
|
+
(function (UpdateUserToSubscriptionCommand) {
|
|
8
|
+
UpdateUserToSubscriptionCommand.RequestParamSchema = models_1.UserToSubscriptionSchema.pick({
|
|
9
|
+
uuid: true,
|
|
10
|
+
});
|
|
11
|
+
UpdateUserToSubscriptionCommand.RequestSchema = zod_1.z
|
|
12
|
+
.object({
|
|
13
|
+
userId: zod_1.z.string().uuid(),
|
|
14
|
+
subscriptionId: zod_1.z.string(),
|
|
15
|
+
initTokenBalance: zod_1.z.number(),
|
|
16
|
+
active: zod_1.z.coerce.boolean(),
|
|
17
|
+
tokenBalance: zod_1.z.number(),
|
|
18
|
+
status: zod_1.z.string(),
|
|
19
|
+
endDate: zod_1.z.coerce.date().nullable(),
|
|
20
|
+
marks: zod_1.z.array(zod_1.z.string()),
|
|
21
|
+
intervalEndDate: zod_1.z.coerce.date().nullable(),
|
|
22
|
+
})
|
|
23
|
+
.partial();
|
|
24
|
+
UpdateUserToSubscriptionCommand.ResponseSchema = zod_1.z.object({
|
|
25
|
+
data: models_1.UserToSubscriptionSchema,
|
|
26
|
+
});
|
|
27
|
+
})(UpdateUserToSubscriptionCommand || (exports.UpdateUserToSubscriptionCommand = UpdateUserToSubscriptionCommand = {}));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NumberFilter = exports.DateFilter = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.DateFilter = zod_1.z.object({
|
|
6
|
+
gt: zod_1.z.coerce.date().optional(),
|
|
7
|
+
gte: zod_1.z.coerce.date().optional(),
|
|
8
|
+
lt: zod_1.z.coerce.date().optional(),
|
|
9
|
+
lte: zod_1.z.coerce.date().optional(),
|
|
10
|
+
});
|
|
11
|
+
exports.NumberFilter = zod_1.z.object({
|
|
12
|
+
gt: zod_1.z.coerce.number().optional(),
|
|
13
|
+
gte: zod_1.z.coerce.number().optional(),
|
|
14
|
+
lt: zod_1.z.coerce.number().optional(),
|
|
15
|
+
lte: zod_1.z.coerce.number().optional(),
|
|
16
|
+
});
|
package/build/models/index.js
CHANGED
|
@@ -62,3 +62,4 @@ __exportStar(require("./prompt-category.schema"), exports);
|
|
|
62
62
|
__exportStar(require("./prompt-topic.schema"), exports);
|
|
63
63
|
__exportStar(require("./prompt.schema"), exports);
|
|
64
64
|
__exportStar(require("./folder.schema"), exports);
|
|
65
|
+
__exportStar(require("./filters.schema"), exports);
|
package/commands/index.ts
CHANGED
|
@@ -1,21 +1,55 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
|
-
import { UserSchema } from '../../models';
|
|
2
|
+
import { DateFilter, NumberFilter, UserSchema } from '../../models';
|
|
3
3
|
import { ROLE, SORT_ORDER, USER_SORT_BY, USER_STATUS } from '../../constants';
|
|
4
4
|
|
|
5
5
|
export namespace FindUsersByCriteriaCommand {
|
|
6
|
-
export const RequestSchema = z
|
|
7
|
-
|
|
6
|
+
export const RequestSchema = z.preprocess(
|
|
7
|
+
(input) => {
|
|
8
|
+
if (input && typeof input === 'object' && !Array.isArray(input)) {
|
|
9
|
+
const obj = { ...input } as Record<string, any>;
|
|
10
|
+
const onlyNormalize = ['createdAt', 'updatedAt', 'tokenBonusBalance'];
|
|
11
|
+
|
|
12
|
+
const relevantBracketed = Object.keys(obj).some((key) => {
|
|
13
|
+
const match = key.match(/^(\w+)\[(\w+)\]$/);
|
|
14
|
+
return match && onlyNormalize.includes(match[1]);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
if (!relevantBracketed) {
|
|
18
|
+
return obj;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const result = { ...obj };
|
|
22
|
+
for (const key of Object.keys(obj)) {
|
|
23
|
+
const match = key.match(/^(\w+)\[(\w+)\]$/);
|
|
24
|
+
if (match && onlyNormalize.includes(match[1])) {
|
|
25
|
+
const [, outer, inner] = match;
|
|
26
|
+
result[outer] = result[outer] || {};
|
|
27
|
+
result[outer][inner] = obj[key];
|
|
28
|
+
delete result[key];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
return input;
|
|
34
|
+
},
|
|
35
|
+
z.object({
|
|
8
36
|
uuid: z.string().uuid().optional(),
|
|
9
37
|
email: z.string().email().optional(),
|
|
10
38
|
status: z.nativeEnum(USER_STATUS).optional(),
|
|
11
39
|
role: z.nativeEnum(ROLE).optional(),
|
|
12
|
-
|
|
13
|
-
|
|
40
|
+
telegramId: z.coerce.number().optional(),
|
|
41
|
+
|
|
42
|
+
createdAt: DateFilter.optional(),
|
|
43
|
+
updatedAt: DateFilter.optional(),
|
|
44
|
+
tokenBonusBalance: NumberFilter.optional(),
|
|
14
45
|
|
|
15
46
|
sortBy: z.nativeEnum(USER_SORT_BY).optional(),
|
|
16
47
|
sortOrder: z.nativeEnum(SORT_ORDER).default(SORT_ORDER.DESC).optional(),
|
|
17
|
-
|
|
18
|
-
|
|
48
|
+
|
|
49
|
+
limit: z.coerce.number().min(1),
|
|
50
|
+
offset: z.coerce.number().min(0).default(0),
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
19
53
|
|
|
20
54
|
export type Request = z.infer<typeof RequestSchema>;
|
|
21
55
|
|
|
@@ -26,8 +60,12 @@ export namespace FindUsersByCriteriaCommand {
|
|
|
26
60
|
password: true,
|
|
27
61
|
passwordHash: true,
|
|
28
62
|
restoreTokenHash: true,
|
|
63
|
+
}).extend({
|
|
64
|
+
telegramId: z.number().nullable(),
|
|
29
65
|
}),
|
|
30
66
|
),
|
|
67
|
+
page: z.number(),
|
|
68
|
+
totalPages: z.number(),
|
|
31
69
|
});
|
|
32
70
|
|
|
33
71
|
export type Response = z.infer<typeof ResponseSchema>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './update-user-to-product.command';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { UserToProductSchema } from '../../models';
|
|
3
|
+
|
|
4
|
+
export namespace UpdateUserToProductCommand {
|
|
5
|
+
export const RequestParamSchema = UserToProductSchema.pick({
|
|
6
|
+
uuid: true,
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export type RequestParam = z.infer<typeof RequestParamSchema>;
|
|
10
|
+
|
|
11
|
+
export const RequestSchema = UserToProductSchema.pick({
|
|
12
|
+
initTokenBalance: true,
|
|
13
|
+
tokenBalance: true,
|
|
14
|
+
status: true,
|
|
15
|
+
}).partial();
|
|
16
|
+
|
|
17
|
+
export const ResponseSchema = z.object({
|
|
18
|
+
data: RequestParamSchema,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { UserToSubscriptionSchema } from '../../models';
|
|
3
|
+
|
|
4
|
+
export namespace UpdateUserToSubscriptionCommand {
|
|
5
|
+
export const RequestParamSchema = UserToSubscriptionSchema.pick({
|
|
6
|
+
uuid: true,
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export type RequestParam = z.infer<typeof RequestParamSchema>;
|
|
10
|
+
|
|
11
|
+
export const RequestSchema = z
|
|
12
|
+
.object({
|
|
13
|
+
userId: z.string().uuid(),
|
|
14
|
+
subscriptionId: z.string(),
|
|
15
|
+
initTokenBalance: z.number(),
|
|
16
|
+
active: z.coerce.boolean(),
|
|
17
|
+
tokenBalance: z.number(),
|
|
18
|
+
status: z.string(),
|
|
19
|
+
endDate: z.coerce.date().nullable(),
|
|
20
|
+
marks: z.array(z.string()),
|
|
21
|
+
intervalEndDate: z.coerce.date().nullable(),
|
|
22
|
+
})
|
|
23
|
+
.partial();
|
|
24
|
+
|
|
25
|
+
export const ResponseSchema = z.object({
|
|
26
|
+
data: UserToSubscriptionSchema,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const DateFilter = z.object({
|
|
4
|
+
gt: z.coerce.date().optional(),
|
|
5
|
+
gte: z.coerce.date().optional(),
|
|
6
|
+
lt: z.coerce.date().optional(),
|
|
7
|
+
lte: z.coerce.date().optional(),
|
|
8
|
+
});
|
|
9
|
+
export type DateFilter = z.infer<typeof DateFilter>;
|
|
10
|
+
|
|
11
|
+
export const NumberFilter = z.object({
|
|
12
|
+
gt: z.coerce.number().optional(),
|
|
13
|
+
gte: z.coerce.number().optional(),
|
|
14
|
+
lt: z.coerce.number().optional(),
|
|
15
|
+
lte: z.coerce.number().optional(),
|
|
16
|
+
});
|
|
17
|
+
export type NumberFilter = z.infer<typeof NumberFilter>;
|
package/models/index.ts
CHANGED