@remnawave/backend-contract 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.REST_API = exports.ROOT = void 0;
27
37
  const CONTROLLERS = __importStar(require("./controllers"));
@@ -7,6 +7,22 @@ const users_schema_1 = require("../../models/users.schema");
7
7
  var GetAllUsersCommand;
8
8
  (function (GetAllUsersCommand) {
9
9
  GetAllUsersCommand.url = api_1.REST_API.USERS.GET_ALL;
10
+ GetAllUsersCommand.SortableFields = [
11
+ 'username',
12
+ 'status',
13
+ 'expireAt',
14
+ 'createdAt',
15
+ 'onlineAt',
16
+ 'usedTrafficBytes',
17
+ 'trafficLimitBytes',
18
+ ];
19
+ GetAllUsersCommand.SearchableFields = [
20
+ 'username',
21
+ 'shortUuid',
22
+ 'subscriptionUuid',
23
+ 'uuid',
24
+ 'status',
25
+ ];
10
26
  GetAllUsersCommand.RequestQuerySchema = zod_1.z.object({
11
27
  limit: zod_1.z
12
28
  .string()
@@ -16,8 +32,15 @@ var GetAllUsersCommand;
16
32
  .string()
17
33
  .default('0')
18
34
  .transform((val) => parseInt(val)),
35
+ orderBy: zod_1.z.enum(GetAllUsersCommand.SortableFields).default('createdAt'),
36
+ orderDir: zod_1.z.enum(['asc', 'desc']).default('desc'),
37
+ search: zod_1.z.string().optional(),
38
+ searchBy: zod_1.z.enum(GetAllUsersCommand.SearchableFields).default('username'),
19
39
  });
20
40
  GetAllUsersCommand.ResponseSchema = zod_1.z.object({
21
- response: zod_1.z.array(users_schema_1.UsersSchema),
41
+ response: zod_1.z.object({
42
+ users: zod_1.z.array(users_schema_1.UsersSchema),
43
+ total: zod_1.z.number(),
44
+ }),
22
45
  });
23
46
  })(GetAllUsersCommand || (exports.GetAllUsersCommand = GetAllUsersCommand = {}));
@@ -5,6 +5,27 @@ import { UsersSchema } from '../../models/users.schema';
5
5
  export namespace GetAllUsersCommand {
6
6
  export const url = REST_API.USERS.GET_ALL;
7
7
 
8
+ export const SortableFields = [
9
+ 'username',
10
+ 'status',
11
+ 'expireAt',
12
+ 'createdAt',
13
+ 'onlineAt',
14
+ 'usedTrafficBytes',
15
+ 'trafficLimitBytes',
16
+ ] as const;
17
+
18
+ export const SearchableFields = [
19
+ 'username',
20
+ 'shortUuid',
21
+ 'subscriptionUuid',
22
+ 'uuid',
23
+ 'status',
24
+ ] as const;
25
+
26
+ export type SortableField = (typeof SortableFields)[number];
27
+ export type SearchableField = (typeof SearchableFields)[number];
28
+
8
29
  export const RequestQuerySchema = z.object({
9
30
  limit: z
10
31
  .string()
@@ -14,12 +35,21 @@ export namespace GetAllUsersCommand {
14
35
  .string()
15
36
  .default('0')
16
37
  .transform((val) => parseInt(val)),
38
+ orderBy: z.enum(SortableFields).default('createdAt'),
39
+ orderDir: z.enum(['asc', 'desc']).default('desc'),
40
+ search: z.string().optional(),
41
+ searchBy: z.enum(SearchableFields).default('username'),
17
42
  });
18
43
 
44
+ // !TODO: add searchBy validation
45
+
19
46
  export type RequestQuery = z.infer<typeof RequestQuerySchema>;
20
47
 
21
48
  export const ResponseSchema = z.object({
22
- response: z.array(UsersSchema),
49
+ response: z.object({
50
+ users: z.array(UsersSchema),
51
+ total: z.number(),
52
+ }),
23
53
  });
24
54
 
25
55
  export type Response = z.infer<typeof ResponseSchema>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remnawave/backend-contract",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "A contract library for Remnawave",
5
5
  "main": "index.js",
6
6
  "scripts": {