@remnawave/backend-contract 0.0.2 → 0.0.3

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,16 @@ 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 = ['username', 'shortUuid', 'subscriptionUuid', 'uuid'];
10
20
  GetAllUsersCommand.RequestQuerySchema = zod_1.z.object({
11
21
  limit: zod_1.z
12
22
  .string()
@@ -16,8 +26,15 @@ var GetAllUsersCommand;
16
26
  .string()
17
27
  .default('0')
18
28
  .transform((val) => parseInt(val)),
29
+ orderBy: zod_1.z.enum(GetAllUsersCommand.SortableFields).default('createdAt'),
30
+ orderDir: zod_1.z.enum(['asc', 'desc']).default('desc'),
31
+ search: zod_1.z.string().optional(),
32
+ searchBy: zod_1.z.enum(GetAllUsersCommand.SearchableFields).default('username'),
19
33
  });
20
34
  GetAllUsersCommand.ResponseSchema = zod_1.z.object({
21
- response: zod_1.z.array(users_schema_1.UsersSchema),
35
+ response: zod_1.z.object({
36
+ users: zod_1.z.array(users_schema_1.UsersSchema),
37
+ total: zod_1.z.number(),
38
+ }),
22
39
  });
23
40
  })(GetAllUsersCommand || (exports.GetAllUsersCommand = GetAllUsersCommand = {}));
@@ -5,6 +5,21 @@ 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 = ['username', 'shortUuid', 'subscriptionUuid', 'uuid'] as const;
19
+
20
+ export type SortableField = (typeof SortableFields)[number];
21
+ export type SearchableField = (typeof SearchableFields)[number];
22
+
8
23
  export const RequestQuerySchema = z.object({
9
24
  limit: z
10
25
  .string()
@@ -14,12 +29,21 @@ export namespace GetAllUsersCommand {
14
29
  .string()
15
30
  .default('0')
16
31
  .transform((val) => parseInt(val)),
32
+ orderBy: z.enum(SortableFields).default('createdAt'),
33
+ orderDir: z.enum(['asc', 'desc']).default('desc'),
34
+ search: z.string().optional(),
35
+ searchBy: z.enum(SearchableFields).default('username'),
17
36
  });
18
37
 
38
+ // !TODO: add searchBy validation
39
+
19
40
  export type RequestQuery = z.infer<typeof RequestQuerySchema>;
20
41
 
21
42
  export const ResponseSchema = z.object({
22
- response: z.array(UsersSchema),
43
+ response: z.object({
44
+ users: z.array(UsersSchema),
45
+ total: z.number(),
46
+ }),
23
47
  });
24
48
 
25
49
  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.3",
4
4
  "description": "A contract library for Remnawave",
5
5
  "main": "index.js",
6
6
  "scripts": {