@purpleschool/gptbot 0.12.45 → 0.12.47

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 (37) hide show
  1. package/api/controllers/http/team-account.ts +1 -0
  2. package/api/routes.ts +1 -0
  3. package/build/api/controllers/http/team-account.js +1 -0
  4. package/build/api/routes.js +1 -0
  5. package/build/commands/subscription/get-available-upgrades.command.js +4 -0
  6. package/build/commands/subscription/upgrade-subscription.command.js +1 -0
  7. package/build/commands/team-account/create-manual-team-subscription-upgrade.command.js +17 -0
  8. package/build/commands/team-account/create-team-account-invoice-payment.command.js +6 -2
  9. package/build/commands/team-account/find-team-accounts-by-name.command.js +6 -0
  10. package/build/commands/team-account/get-invoice-for-payment.command.js +6 -0
  11. package/build/commands/team-account/index.js +1 -0
  12. package/build/commands/team-to-subscription/add-team-to-subscription.command.js +1 -0
  13. package/build/commands/team-to-subscription/update-team-to-subscription.command.js +1 -0
  14. package/build/constants/page/enums/page-sort-by.enum.js +3 -0
  15. package/build/constants/team-account/enums/index.js +2 -0
  16. package/build/constants/team-account/enums/invoice-for-payment-sort-by.enum.js +14 -0
  17. package/build/constants/team-account/enums/team-account-admin-sort-by.enum.js +11 -0
  18. package/build/models/invoice-for-payment.schema.js +20 -7
  19. package/build/models/team-account/team-account-with-balance.schema.js +9 -0
  20. package/build/models/team-account/team-to-subscription.schema.js +1 -0
  21. package/commands/subscription/get-available-upgrades.command.ts +7 -0
  22. package/commands/subscription/upgrade-subscription.command.ts +2 -1
  23. package/commands/team-account/create-manual-team-subscription-upgrade.command.ts +19 -0
  24. package/commands/team-account/create-team-account-invoice-payment.command.ts +7 -3
  25. package/commands/team-account/find-team-accounts-by-name.command.ts +6 -0
  26. package/commands/team-account/get-invoice-for-payment.command.ts +6 -0
  27. package/commands/team-account/index.ts +1 -0
  28. package/commands/team-to-subscription/add-team-to-subscription.command.ts +1 -0
  29. package/commands/team-to-subscription/update-team-to-subscription.command.ts +1 -0
  30. package/constants/page/enums/page-sort-by.enum.ts +3 -0
  31. package/constants/team-account/enums/index.ts +2 -0
  32. package/constants/team-account/enums/invoice-for-payment-sort-by.enum.ts +10 -0
  33. package/constants/team-account/enums/team-account-admin-sort-by.enum.ts +7 -0
  34. package/models/invoice-for-payment.schema.ts +20 -7
  35. package/models/team-account/team-account-with-balance.schema.ts +9 -0
  36. package/models/team-account/team-to-subscription.schema.ts +1 -0
  37. package/package.json +1 -1
@@ -20,6 +20,7 @@ export const TEAM_ACCOUNT_ROUTES = {
20
20
  GET_STATISTICS_OVERVIEW: 'statistics/overview',
21
21
  GET_STATISTICS_BY_MONTH: 'statistics/by-month',
22
22
  CREATE_MANUAL_SUBSCRIPTION: 'manual/subscription',
23
+ CREATE_MANUAL_SUBSCRIPTION_UPGRADE: 'manual/subscription/upgrade',
23
24
  CREATE_MANUAL_PRODUCT: 'manual/product',
24
25
  CREATE_INVOICE_PAYMENT: 'invoice-payment',
25
26
  ADMIN_FIND_BY_NAME: 'admin/find',
package/api/routes.ts CHANGED
@@ -211,6 +211,7 @@ export const REST_API = {
211
211
  CANCEL_TRIAL_SUBSCRIPTION: `${ROOT}/${CONTROLLERS.TEAM_ACCOUNT_CONTROLLER}/${CONTROLLERS.TEAM_ACCOUNT_ROUTES.CANCEL_TRIAL_SUBSCRIPTION}`,
212
212
  GET_BALANCE: `${ROOT}/${CONTROLLERS.TEAM_ACCOUNT_CONTROLLER}/${CONTROLLERS.TEAM_ACCOUNT_ROUTES.GET_BALANCE}`,
213
213
  CREATE_MANUAL_SUBSCRIPTION: `${ROOT}/${CONTROLLERS.TEAM_ACCOUNT_CONTROLLER}/${CONTROLLERS.TEAM_ACCOUNT_ROUTES.CREATE_MANUAL_SUBSCRIPTION}`,
214
+ CREATE_MANUAL_SUBSCRIPTION_UPGRADE: `${ROOT}/${CONTROLLERS.TEAM_ACCOUNT_CONTROLLER}/${CONTROLLERS.TEAM_ACCOUNT_ROUTES.CREATE_MANUAL_SUBSCRIPTION_UPGRADE}`,
214
215
  CREATE_MANUAL_PRODUCT: `${ROOT}/${CONTROLLERS.TEAM_ACCOUNT_CONTROLLER}/${CONTROLLERS.TEAM_ACCOUNT_ROUTES.CREATE_MANUAL_PRODUCT}`,
215
216
  CREATE_INVOICE_PAYMENT: `${ROOT}/${CONTROLLERS.TEAM_ACCOUNT_CONTROLLER}/${CONTROLLERS.TEAM_ACCOUNT_ROUTES.CREATE_INVOICE_PAYMENT}`,
216
217
  ADMIN_FIND_BY_NAME: `${ROOT}/${CONTROLLERS.TEAM_ACCOUNT_CONTROLLER}/${CONTROLLERS.TEAM_ACCOUNT_ROUTES.ADMIN_FIND_BY_NAME}`,
@@ -22,6 +22,7 @@ exports.TEAM_ACCOUNT_ROUTES = {
22
22
  GET_STATISTICS_OVERVIEW: 'statistics/overview',
23
23
  GET_STATISTICS_BY_MONTH: 'statistics/by-month',
24
24
  CREATE_MANUAL_SUBSCRIPTION: 'manual/subscription',
25
+ CREATE_MANUAL_SUBSCRIPTION_UPGRADE: 'manual/subscription/upgrade',
25
26
  CREATE_MANUAL_PRODUCT: 'manual/product',
26
27
  CREATE_INVOICE_PAYMENT: 'invoice-payment',
27
28
  ADMIN_FIND_BY_NAME: 'admin/find',
@@ -207,6 +207,7 @@ exports.REST_API = {
207
207
  CANCEL_TRIAL_SUBSCRIPTION: `${exports.ROOT}/${CONTROLLERS.TEAM_ACCOUNT_CONTROLLER}/${CONTROLLERS.TEAM_ACCOUNT_ROUTES.CANCEL_TRIAL_SUBSCRIPTION}`,
208
208
  GET_BALANCE: `${exports.ROOT}/${CONTROLLERS.TEAM_ACCOUNT_CONTROLLER}/${CONTROLLERS.TEAM_ACCOUNT_ROUTES.GET_BALANCE}`,
209
209
  CREATE_MANUAL_SUBSCRIPTION: `${exports.ROOT}/${CONTROLLERS.TEAM_ACCOUNT_CONTROLLER}/${CONTROLLERS.TEAM_ACCOUNT_ROUTES.CREATE_MANUAL_SUBSCRIPTION}`,
210
+ CREATE_MANUAL_SUBSCRIPTION_UPGRADE: `${exports.ROOT}/${CONTROLLERS.TEAM_ACCOUNT_CONTROLLER}/${CONTROLLERS.TEAM_ACCOUNT_ROUTES.CREATE_MANUAL_SUBSCRIPTION_UPGRADE}`,
210
211
  CREATE_MANUAL_PRODUCT: `${exports.ROOT}/${CONTROLLERS.TEAM_ACCOUNT_CONTROLLER}/${CONTROLLERS.TEAM_ACCOUNT_ROUTES.CREATE_MANUAL_PRODUCT}`,
211
212
  CREATE_INVOICE_PAYMENT: `${exports.ROOT}/${CONTROLLERS.TEAM_ACCOUNT_CONTROLLER}/${CONTROLLERS.TEAM_ACCOUNT_ROUTES.CREATE_INVOICE_PAYMENT}`,
212
213
  ADMIN_FIND_BY_NAME: `${exports.ROOT}/${CONTROLLERS.TEAM_ACCOUNT_CONTROLLER}/${CONTROLLERS.TEAM_ACCOUNT_ROUTES.ADMIN_FIND_BY_NAME}`,
@@ -2,12 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GetAvailableUpgradesCommand = void 0;
4
4
  const zod_1 = require("zod");
5
+ const constants_1 = require("../../constants");
5
6
  const models_1 = require("../../models");
6
7
  const subscription_upgrade_schema_1 = require("../../models/subscription-upgrade-schema");
7
8
  const subscription_feature_schema_1 = require("../../models/subscription-feature.schema");
8
9
  var GetAvailableUpgradesCommand;
9
10
  (function (GetAvailableUpgradesCommand) {
10
11
  GetAvailableUpgradesCommand.RequestSchema = models_1.SubscriptionSchema.pick({});
12
+ GetAvailableUpgradesCommand.RequestQuerySchema = zod_1.z.object({
13
+ billingScope: zod_1.z.nativeEnum(constants_1.BILLING_SCOPE).default(constants_1.BILLING_SCOPE.USER),
14
+ });
11
15
  GetAvailableUpgradesCommand.ResponseSchema = zod_1.z.object({
12
16
  features: zod_1.z.record(zod_1.z.string().uuid(), zod_1.z.array(subscription_feature_schema_1.SubscriptionFeatureSchema)),
13
17
  subscriptions: zod_1.z.array(subscription_upgrade_schema_1.SubscriptionUpgradeSchema),
@@ -10,6 +10,7 @@ var UpgradeSubscriptionCommand;
10
10
  upgradeSubscriptionId: zod_1.z.string().uuid(),
11
11
  promocode: zod_1.z.string().optional(),
12
12
  provider: zod_1.z.nativeEnum(constants_1.PAYMENT_PROVIDER).optional().default(constants_1.PAYMENT_PROVIDER.CLOUDPAYMENTS),
13
+ billingScope: zod_1.z.nativeEnum(constants_1.BILLING_SCOPE).default(constants_1.BILLING_SCOPE.USER),
13
14
  });
14
15
  UpgradeSubscriptionCommand.RequestParamSchema = models_1.UserToSubscriptionSchema.pick({
15
16
  uuid: true,
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CreateManualTeamSubscriptionUpgradeCommand = void 0;
4
+ const zod_1 = require("zod");
5
+ const models_1 = require("../../models");
6
+ var CreateManualTeamSubscriptionUpgradeCommand;
7
+ (function (CreateManualTeamSubscriptionUpgradeCommand) {
8
+ CreateManualTeamSubscriptionUpgradeCommand.RequestSchema = zod_1.z.object({
9
+ teamAccountId: zod_1.z.string().uuid(),
10
+ subscriptionId: zod_1.z.string().uuid(),
11
+ durationMonths: zod_1.z.number().int().min(1).max(36).optional(),
12
+ upgradeFromSubscriptionId: zod_1.z.string().uuid(),
13
+ });
14
+ CreateManualTeamSubscriptionUpgradeCommand.ResponseSchema = zod_1.z.object({
15
+ data: models_1.TeamToSubscriptionSchema,
16
+ });
17
+ })(CreateManualTeamSubscriptionUpgradeCommand || (exports.CreateManualTeamSubscriptionUpgradeCommand = CreateManualTeamSubscriptionUpgradeCommand = {}));
@@ -12,9 +12,13 @@ var CreateTeamAccountInvoicePaymentCommand;
12
12
  amount: zod_1.z.number().positive(),
13
13
  subscriptionUuid: zod_1.z.string().uuid().optional(),
14
14
  productUuid: zod_1.z.string().uuid().optional(),
15
+ upgradeSubscriptionUuid: zod_1.z.string().uuid().optional(),
15
16
  })
16
- .refine(({ subscriptionUuid, productUuid }) => Number(Boolean(subscriptionUuid)) + Number(Boolean(productUuid)) === 1, {
17
- message: 'Нужно передать ровно один идентификатор: subscriptionUuid или productUuid',
17
+ .refine(({ subscriptionUuid, productUuid, upgradeSubscriptionUuid }) => Number(Boolean(subscriptionUuid)) +
18
+ Number(Boolean(productUuid)) +
19
+ Number(Boolean(upgradeSubscriptionUuid)) ===
20
+ 1, {
21
+ message: 'Нужно передать ровно один идентификатор: subscriptionUuid, productUuid или upgradeSubscriptionUuid',
18
22
  });
19
23
  CreateTeamAccountInvoicePaymentCommand.ResponseSchema = zod_1.z.object({
20
24
  data: zod_1.z.object({
@@ -3,12 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FindTeamAccountsByNameCommand = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const models_1 = require("../../models");
6
+ const constants_1 = require("../../constants");
6
7
  var FindTeamAccountsByNameCommand;
7
8
  (function (FindTeamAccountsByNameCommand) {
8
9
  FindTeamAccountsByNameCommand.RequestSchema = zod_1.z.object({
9
10
  name: zod_1.z.string().trim().min(1).optional(),
10
11
  limit: zod_1.z.coerce.number().int().min(1).max(100).default(20).optional(),
11
12
  offset: zod_1.z.coerce.number().int().min(0).default(0).optional(),
13
+ sortBy: zod_1.z
14
+ .nativeEnum(constants_1.TEAM_ACCOUNT_ADMIN_SORT_BY)
15
+ .default(constants_1.TEAM_ACCOUNT_ADMIN_SORT_BY.CREATED_AT)
16
+ .optional(),
17
+ sortOrder: zod_1.z.nativeEnum(constants_1.SORT_ORDER).default(constants_1.SORT_ORDER.DESC).optional(),
12
18
  });
13
19
  FindTeamAccountsByNameCommand.ResponseSchema = zod_1.z.object({
14
20
  data: zod_1.z.array(models_1.TeamAccountWithBalanceSchema),
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GetInvoiceForPaymentCommand = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const models_1 = require("../../models");
6
+ const constants_1 = require("../../constants");
6
7
  var GetInvoiceForPaymentCommand;
7
8
  (function (GetInvoiceForPaymentCommand) {
8
9
  GetInvoiceForPaymentCommand.RequestQuerySchema = zod_1.z.object({
@@ -15,6 +16,11 @@ var GetInvoiceForPaymentCommand;
15
16
  dateTo: zod_1.z.coerce.date().optional(),
16
17
  limit: zod_1.z.coerce.number().int().min(1).max(100).default(20).optional(),
17
18
  offset: zod_1.z.coerce.number().int().min(0).default(0).optional(),
19
+ sortBy: zod_1.z
20
+ .nativeEnum(constants_1.INVOICE_FOR_PAYMENT_SORT_BY)
21
+ .default(constants_1.INVOICE_FOR_PAYMENT_SORT_BY.CREATED_AT)
22
+ .optional(),
23
+ sortOrder: zod_1.z.nativeEnum(constants_1.SORT_ORDER).default(constants_1.SORT_ORDER.DESC).optional(),
18
24
  });
19
25
  GetInvoiceForPaymentCommand.ResponseSchema = zod_1.z.object({
20
26
  data: zod_1.z.array(models_1.InvoiceForPaymentSchema),
@@ -36,6 +36,7 @@ __exportStar(require("./get-team-account-statistics-overview.command"), exports)
36
36
  __exportStar(require("./get-team-account-statistics-by-month.command"), exports);
37
37
  __exportStar(require("./get-team-account-balance.command"), exports);
38
38
  __exportStar(require("./create-manual-team-subscription.command"), exports);
39
+ __exportStar(require("./create-manual-team-subscription-upgrade.command"), exports);
39
40
  __exportStar(require("./create-manual-team-product.command"), exports);
40
41
  __exportStar(require("./find-team-accounts-by-name.command"), exports);
41
42
  __exportStar(require("./find-team-account-by-uuid.command"), exports);
@@ -11,6 +11,7 @@ var AddTeamToSubscriptionCommand;
11
11
  cloudPaymentsSubscriptionId: zod_1.z.string().optional(),
12
12
  zenpaymentsInvoiceNumber: zod_1.z.string().optional(),
13
13
  startDate: zod_1.z.coerce.date().optional(),
14
+ upgradedFromSubscriptionId: zod_1.z.string().uuid().nullable().optional(),
14
15
  downgradedFromTeamSubscriptionId: zod_1.z.string().uuid().nullable().optional(),
15
16
  orderId: zod_1.z.string().uuid(),
16
17
  });
@@ -22,6 +22,7 @@ var UpdateTeamToSubscriptionCommand;
22
22
  type: true,
23
23
  intervalEndDate: true,
24
24
  marks: true,
25
+ upgradedFromSubscriptionId: true,
25
26
  downgradedFromTeamSubscriptionId: true,
26
27
  orderId: true,
27
28
  }).partial();
@@ -5,4 +5,7 @@ var PAGE_SORT_BY;
5
5
  (function (PAGE_SORT_BY) {
6
6
  PAGE_SORT_BY["CREATED_AT"] = "createdAt";
7
7
  PAGE_SORT_BY["UPDATED_AT"] = "updatedAt";
8
+ PAGE_SORT_BY["TITLE"] = "title";
9
+ PAGE_SORT_BY["CATEGORY_NAME"] = "categoryName";
10
+ PAGE_SORT_BY["CATEGORY_ID"] = "categoryId";
8
11
  })(PAGE_SORT_BY || (exports.PAGE_SORT_BY = PAGE_SORT_BY = {}));
@@ -14,7 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./invoice-for-payment-sort-by.enum"), exports);
17
18
  __exportStar(require("./team-account-invite-status.enum"), exports);
19
+ __exportStar(require("./team-account-admin-sort-by.enum"), exports);
18
20
  __exportStar(require("./team-account-member-role.enum"), exports);
19
21
  __exportStar(require("./team-account-member-status.enum"), exports);
20
22
  __exportStar(require("./team-account-operation-type.enum"), exports);
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.INVOICE_FOR_PAYMENT_SORT_BY = void 0;
4
+ var INVOICE_FOR_PAYMENT_SORT_BY;
5
+ (function (INVOICE_FOR_PAYMENT_SORT_BY) {
6
+ INVOICE_FOR_PAYMENT_SORT_BY["INVOICE_NUMBER"] = "invoiceNumber";
7
+ INVOICE_FOR_PAYMENT_SORT_BY["SUM"] = "sum";
8
+ INVOICE_FOR_PAYMENT_SORT_BY["CREATED_AT"] = "createdAt";
9
+ INVOICE_FOR_PAYMENT_SORT_BY["UPDATED_AT"] = "updatedAt";
10
+ INVOICE_FOR_PAYMENT_SORT_BY["USER_ID"] = "userId";
11
+ INVOICE_FOR_PAYMENT_SORT_BY["TEAM_ACCOUNT_ID"] = "teamAccountId";
12
+ INVOICE_FOR_PAYMENT_SORT_BY["ORDER_ID"] = "orderId";
13
+ INVOICE_FOR_PAYMENT_SORT_BY["PAYMENT_ID"] = "paymentId";
14
+ })(INVOICE_FOR_PAYMENT_SORT_BY || (exports.INVOICE_FOR_PAYMENT_SORT_BY = INVOICE_FOR_PAYMENT_SORT_BY = {}));
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TEAM_ACCOUNT_ADMIN_SORT_BY = void 0;
4
+ var TEAM_ACCOUNT_ADMIN_SORT_BY;
5
+ (function (TEAM_ACCOUNT_ADMIN_SORT_BY) {
6
+ TEAM_ACCOUNT_ADMIN_SORT_BY["NAME"] = "name";
7
+ TEAM_ACCOUNT_ADMIN_SORT_BY["EMAIL"] = "email";
8
+ TEAM_ACCOUNT_ADMIN_SORT_BY["CREATED_AT"] = "createdAt";
9
+ TEAM_ACCOUNT_ADMIN_SORT_BY["UPDATED_AT"] = "updatedAt";
10
+ TEAM_ACCOUNT_ADMIN_SORT_BY["SUBSCRIPTION_ENDS_AT"] = "subscriptionEndsAt";
11
+ })(TEAM_ACCOUNT_ADMIN_SORT_BY || (exports.TEAM_ACCOUNT_ADMIN_SORT_BY = TEAM_ACCOUNT_ADMIN_SORT_BY = {}));
@@ -2,13 +2,26 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InvoiceForPaymentSchema = exports.InvoiceForPaymentPayloadSchema = void 0;
4
4
  const zod_1 = require("zod");
5
- exports.InvoiceForPaymentPayloadSchema = zod_1.z.object({
6
- email: zod_1.z.string().email(),
7
- name: zod_1.z.string(),
8
- inn: zod_1.z.string(),
9
- amount: zod_1.z.number(),
10
- itemName: zod_1.z.string(),
11
- });
5
+ exports.InvoiceForPaymentPayloadSchema = zod_1.z.discriminatedUnion('invoiceType', [
6
+ zod_1.z.object({
7
+ invoiceType: zod_1.z.literal('purchase'),
8
+ email: zod_1.z.string().email(),
9
+ name: zod_1.z.string(),
10
+ inn: zod_1.z.string(),
11
+ amount: zod_1.z.number(),
12
+ itemName: zod_1.z.string(),
13
+ }),
14
+ zod_1.z.object({
15
+ invoiceType: zod_1.z.literal('subscription_upgrade'),
16
+ email: zod_1.z.string().email(),
17
+ name: zod_1.z.string(),
18
+ inn: zod_1.z.string(),
19
+ amount: zod_1.z.number(),
20
+ fromSubscriptionName: zod_1.z.string(),
21
+ toSubscriptionName: zod_1.z.string(),
22
+ durationMonths: zod_1.z.number(),
23
+ }),
24
+ ]);
12
25
  exports.InvoiceForPaymentSchema = zod_1.z.object({
13
26
  uuid: zod_1.z.string().uuid(),
14
27
  userId: zod_1.z.string().uuid(),
@@ -10,6 +10,15 @@ exports.TeamAccountWithBalanceSchema = team_account_schema_1.TeamAccountSchema.e
10
10
  productBalance: zod_1.z.number(),
11
11
  carriedOverBalance: zod_1.z.number(),
12
12
  }),
13
+ subscription: zod_1.z.object({
14
+ isActive: zod_1.z.boolean(),
15
+ activeUntil: zod_1.z.date().nullable(),
16
+ planName: zod_1.z.string().nullable(),
17
+ }),
18
+ balanceUsage: zod_1.z.object({
19
+ spent: zod_1.z.number(),
20
+ total: zod_1.z.number().nullable(),
21
+ }),
13
22
  invoicesCount: zod_1.z.number(),
14
23
  membersCount: zod_1.z.number(),
15
24
  maxSeats: zod_1.z.number(),
@@ -21,6 +21,7 @@ exports.TeamToSubscriptionSchema = zod_1.z.object({
21
21
  type: zod_1.z.nativeEnum(constants_1.USER_TO_SUBSCRIPTION_TYPE),
22
22
  intervalEndDate: zod_1.z.date().nullable(),
23
23
  marks: zod_1.z.array(zod_1.z.nativeEnum(constants_1.USER_TO_SUBSCRIPTION_MARKS)),
24
+ upgradedFromSubscriptionId: zod_1.z.string().uuid().nullable(),
24
25
  downgradedFromTeamSubscriptionId: zod_1.z.string().uuid().nullable(),
25
26
  orderId: zod_1.z.string().uuid().nullable(),
26
27
  createdAt: zod_1.z.date(),
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { BILLING_SCOPE } from '../../constants';
2
3
  import { SubscriptionSchema } from '../../models';
3
4
  import { SubscriptionUpgradeSchema } from '../../models/subscription-upgrade-schema';
4
5
  import { SubscriptionFeatureSchema } from '../../models/subscription-feature.schema';
@@ -8,6 +9,12 @@ export namespace GetAvailableUpgradesCommand {
8
9
 
9
10
  export type Request = z.infer<typeof RequestSchema>;
10
11
 
12
+ export const RequestQuerySchema = z.object({
13
+ billingScope: z.nativeEnum(BILLING_SCOPE).default(BILLING_SCOPE.USER),
14
+ });
15
+
16
+ export type RequestQuery = z.infer<typeof RequestQuerySchema>;
17
+
11
18
  export const ResponseSchema = z.object({
12
19
  features: z.record(z.string().uuid(), z.array(SubscriptionFeatureSchema)),
13
20
  subscriptions: z.array(SubscriptionUpgradeSchema),
@@ -1,12 +1,13 @@
1
1
  import { z } from 'zod';
2
2
  import { UserToSubscriptionSchema } from '../../models';
3
- import { PAYMENT_PROVIDER } from '../../constants';
3
+ import { BILLING_SCOPE, PAYMENT_PROVIDER } from '../../constants';
4
4
 
5
5
  export namespace UpgradeSubscriptionCommand {
6
6
  export const RequestSchema = z.object({
7
7
  upgradeSubscriptionId: z.string().uuid(),
8
8
  promocode: z.string().optional(),
9
9
  provider: z.nativeEnum(PAYMENT_PROVIDER).optional().default(PAYMENT_PROVIDER.CLOUDPAYMENTS),
10
+ billingScope: z.nativeEnum(BILLING_SCOPE).default(BILLING_SCOPE.USER),
10
11
  });
11
12
 
12
13
  export const RequestParamSchema = UserToSubscriptionSchema.pick({
@@ -0,0 +1,19 @@
1
+ import { z } from 'zod';
2
+ import { TeamToSubscriptionSchema } from '../../models';
3
+
4
+ export namespace CreateManualTeamSubscriptionUpgradeCommand {
5
+ export const RequestSchema = z.object({
6
+ teamAccountId: z.string().uuid(),
7
+ subscriptionId: z.string().uuid(),
8
+ durationMonths: z.number().int().min(1).max(36).optional(),
9
+ upgradeFromSubscriptionId: z.string().uuid(),
10
+ });
11
+
12
+ export type Request = z.infer<typeof RequestSchema>;
13
+
14
+ export const ResponseSchema = z.object({
15
+ data: TeamToSubscriptionSchema,
16
+ });
17
+
18
+ export type Response = z.infer<typeof ResponseSchema>;
19
+ }
@@ -9,13 +9,17 @@ export namespace CreateTeamAccountInvoicePaymentCommand {
9
9
  amount: z.number().positive(),
10
10
  subscriptionUuid: z.string().uuid().optional(),
11
11
  productUuid: z.string().uuid().optional(),
12
+ upgradeSubscriptionUuid: z.string().uuid().optional(),
12
13
  })
13
14
  .refine(
14
- ({ subscriptionUuid, productUuid }) =>
15
- Number(Boolean(subscriptionUuid)) + Number(Boolean(productUuid)) === 1,
15
+ ({ subscriptionUuid, productUuid, upgradeSubscriptionUuid }) =>
16
+ Number(Boolean(subscriptionUuid)) +
17
+ Number(Boolean(productUuid)) +
18
+ Number(Boolean(upgradeSubscriptionUuid)) ===
19
+ 1,
16
20
  {
17
21
  message:
18
- 'Нужно передать ровно один идентификатор: subscriptionUuid или productUuid',
22
+ 'Нужно передать ровно один идентификатор: subscriptionUuid, productUuid или upgradeSubscriptionUuid',
19
23
  },
20
24
  );
21
25
 
@@ -1,11 +1,17 @@
1
1
  import { z } from 'zod';
2
2
  import { TeamAccountWithBalanceSchema } from '../../models';
3
+ import { SORT_ORDER, TEAM_ACCOUNT_ADMIN_SORT_BY } from '../../constants';
3
4
 
4
5
  export namespace FindTeamAccountsByNameCommand {
5
6
  export const RequestSchema = z.object({
6
7
  name: z.string().trim().min(1).optional(),
7
8
  limit: z.coerce.number().int().min(1).max(100).default(20).optional(),
8
9
  offset: z.coerce.number().int().min(0).default(0).optional(),
10
+ sortBy: z
11
+ .nativeEnum(TEAM_ACCOUNT_ADMIN_SORT_BY)
12
+ .default(TEAM_ACCOUNT_ADMIN_SORT_BY.CREATED_AT)
13
+ .optional(),
14
+ sortOrder: z.nativeEnum(SORT_ORDER).default(SORT_ORDER.DESC).optional(),
9
15
  });
10
16
 
11
17
  export type Request = z.infer<typeof RequestSchema>;
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { InvoiceForPaymentSchema } from '../../models';
3
+ import { INVOICE_FOR_PAYMENT_SORT_BY, SORT_ORDER } from '../../constants';
3
4
 
4
5
  export namespace GetInvoiceForPaymentCommand {
5
6
  export const RequestQuerySchema = z.object({
@@ -12,6 +13,11 @@ export namespace GetInvoiceForPaymentCommand {
12
13
  dateTo: z.coerce.date().optional(),
13
14
  limit: z.coerce.number().int().min(1).max(100).default(20).optional(),
14
15
  offset: z.coerce.number().int().min(0).default(0).optional(),
16
+ sortBy: z
17
+ .nativeEnum(INVOICE_FOR_PAYMENT_SORT_BY)
18
+ .default(INVOICE_FOR_PAYMENT_SORT_BY.CREATED_AT)
19
+ .optional(),
20
+ sortOrder: z.nativeEnum(SORT_ORDER).default(SORT_ORDER.DESC).optional(),
15
21
  });
16
22
 
17
23
  export type RequestQuery = z.infer<typeof RequestQuerySchema>;
@@ -20,6 +20,7 @@ export * from './get-team-account-statistics-overview.command';
20
20
  export * from './get-team-account-statistics-by-month.command';
21
21
  export * from './get-team-account-balance.command';
22
22
  export * from './create-manual-team-subscription.command';
23
+ export * from './create-manual-team-subscription-upgrade.command';
23
24
  export * from './create-manual-team-product.command';
24
25
  export * from './find-team-accounts-by-name.command';
25
26
  export * from './find-team-account-by-uuid.command';
@@ -8,6 +8,7 @@ export namespace AddTeamToSubscriptionCommand {
8
8
  cloudPaymentsSubscriptionId: z.string().optional(),
9
9
  zenpaymentsInvoiceNumber: z.string().optional(),
10
10
  startDate: z.coerce.date().optional(),
11
+ upgradedFromSubscriptionId: z.string().uuid().nullable().optional(),
11
12
  downgradedFromTeamSubscriptionId: z.string().uuid().nullable().optional(),
12
13
  orderId: z.string().uuid(),
13
14
  });
@@ -22,6 +22,7 @@ export namespace UpdateTeamToSubscriptionCommand {
22
22
  type: true,
23
23
  intervalEndDate: true,
24
24
  marks: true,
25
+ upgradedFromSubscriptionId: true,
25
26
  downgradedFromTeamSubscriptionId: true,
26
27
  orderId: true,
27
28
  }).partial();
@@ -1,4 +1,7 @@
1
1
  export enum PAGE_SORT_BY {
2
2
  CREATED_AT = 'createdAt',
3
3
  UPDATED_AT = 'updatedAt',
4
+ TITLE = 'title',
5
+ CATEGORY_NAME = 'categoryName',
6
+ CATEGORY_ID = 'categoryId',
4
7
  }
@@ -1,4 +1,6 @@
1
+ export * from './invoice-for-payment-sort-by.enum';
1
2
  export * from './team-account-invite-status.enum';
3
+ export * from './team-account-admin-sort-by.enum';
2
4
  export * from './team-account-member-role.enum';
3
5
  export * from './team-account-member-status.enum';
4
6
  export * from './team-account-operation-type.enum';
@@ -0,0 +1,10 @@
1
+ export enum INVOICE_FOR_PAYMENT_SORT_BY {
2
+ INVOICE_NUMBER = 'invoiceNumber',
3
+ SUM = 'sum',
4
+ CREATED_AT = 'createdAt',
5
+ UPDATED_AT = 'updatedAt',
6
+ USER_ID = 'userId',
7
+ TEAM_ACCOUNT_ID = 'teamAccountId',
8
+ ORDER_ID = 'orderId',
9
+ PAYMENT_ID = 'paymentId',
10
+ }
@@ -0,0 +1,7 @@
1
+ export enum TEAM_ACCOUNT_ADMIN_SORT_BY {
2
+ NAME = 'name',
3
+ EMAIL = 'email',
4
+ CREATED_AT = 'createdAt',
5
+ UPDATED_AT = 'updatedAt',
6
+ SUBSCRIPTION_ENDS_AT = 'subscriptionEndsAt',
7
+ }
@@ -1,12 +1,25 @@
1
1
  import { z } from 'zod';
2
2
 
3
- export const InvoiceForPaymentPayloadSchema = z.object({
4
- email: z.string().email(),
5
- name: z.string(),
6
- inn: z.string(),
7
- amount: z.number(),
8
- itemName: z.string(),
9
- });
3
+ export const InvoiceForPaymentPayloadSchema = z.discriminatedUnion('invoiceType', [
4
+ z.object({
5
+ invoiceType: z.literal('purchase'),
6
+ email: z.string().email(),
7
+ name: z.string(),
8
+ inn: z.string(),
9
+ amount: z.number(),
10
+ itemName: z.string(),
11
+ }),
12
+ z.object({
13
+ invoiceType: z.literal('subscription_upgrade'),
14
+ email: z.string().email(),
15
+ name: z.string(),
16
+ inn: z.string(),
17
+ amount: z.number(),
18
+ fromSubscriptionName: z.string(),
19
+ toSubscriptionName: z.string(),
20
+ durationMonths: z.number(),
21
+ }),
22
+ ]);
10
23
 
11
24
  export const InvoiceForPaymentSchema = z.object({
12
25
  uuid: z.string().uuid(),
@@ -8,6 +8,15 @@ export const TeamAccountWithBalanceSchema = TeamAccountSchema.extend({
8
8
  productBalance: z.number(),
9
9
  carriedOverBalance: z.number(),
10
10
  }),
11
+ subscription: z.object({
12
+ isActive: z.boolean(),
13
+ activeUntil: z.date().nullable(),
14
+ planName: z.string().nullable(),
15
+ }),
16
+ balanceUsage: z.object({
17
+ spent: z.number(),
18
+ total: z.number().nullable(),
19
+ }),
11
20
  invoicesCount: z.number(),
12
21
  membersCount: z.number(),
13
22
  maxSeats: z.number(),
@@ -23,6 +23,7 @@ export const TeamToSubscriptionSchema = z.object({
23
23
  type: z.nativeEnum(USER_TO_SUBSCRIPTION_TYPE),
24
24
  intervalEndDate: z.date().nullable(),
25
25
  marks: z.array(z.nativeEnum(USER_TO_SUBSCRIPTION_MARKS)),
26
+ upgradedFromSubscriptionId: z.string().uuid().nullable(),
26
27
  downgradedFromTeamSubscriptionId: z.string().uuid().nullable(),
27
28
  orderId: z.string().uuid().nullable(),
28
29
  createdAt: z.date(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purpleschool/gptbot",
3
- "version": "0.12.45",
3
+ "version": "0.12.47",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",