Skip to content

Commit e1d33cd

Browse files
committed
feat: add support for user lookup by Telegram ID and email
- Added new routes and methods to find users by Telegram ID and email - Updated users schema to include telegramId and email fields - Implemented repository methods for unique user field lookups - Enhanced users service to support fetching users by Telegram ID or email - Updated contract library version to 0.2.0
1 parent b5cae3f commit e1d33cd

31 files changed

+597
-214
lines changed

libs/contract/api/controllers/users.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ export const USERS_ROUTES = {
1616
BULK: {
1717
DELETE_BY_STATUS: 'bulk/delete-by-status',
1818
},
19+
GET_BY_TELEGRAM_ID: 'tg',
20+
GET_BY_EMAIL: 'email',
1921
} as const;

libs/contract/api/routes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ export const REST_API = {
6868
BULK: {
6969
DELETE_BY_STATUS: `${ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.BULK.DELETE_BY_STATUS}`,
7070
},
71+
GET_BY_TELEGRAM_ID: (telegramId: string) =>
72+
`${ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.GET_BY_TELEGRAM_ID}/${telegramId}`,
73+
GET_BY_EMAIL: (email: string) =>
74+
`${ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.GET_BY_EMAIL}/${email}`,
7175
},
7276
SUBSCRIPTION: {
7377
GET: (shortUuid: string) =>

libs/contract/commands/users/create-user.command.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ export namespace CreateUserCommand {
105105
.describe('Date format: 2025-01-17T15:38:45.065Z')
106106
.optional(),
107107
description: z.string().optional(),
108+
109+
telegramId: z.number().optional(),
110+
email: z.string().optional(),
111+
108112
activateAllInbounds: z.boolean().optional(),
109113
});
110114

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { z } from 'zod';
2+
3+
import { UsersSchema } from '../../models/users.schema';
4+
import { REST_API } from '../../api';
5+
import { LastConnectedNodeSchema } from '../../models';
6+
7+
export namespace GetUserByEmailCommand {
8+
export const url = REST_API.USERS.GET_BY_EMAIL;
9+
export const TSQ_url = url(':email');
10+
11+
export const RequestSchema = z.object({
12+
email: z.string(),
13+
});
14+
15+
export type Request = z.infer<typeof RequestSchema>;
16+
17+
export const ResponseSchema = z.object({
18+
response: z.array(
19+
UsersSchema.extend({
20+
subscriptionUrl: z.string(),
21+
lastConnectedNode: LastConnectedNodeSchema,
22+
}),
23+
),
24+
});
25+
26+
export type Response = z.infer<typeof ResponseSchema>;
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { z } from 'zod';
2+
3+
import { UsersSchema } from '../../models/users.schema';
4+
import { REST_API } from '../../api';
5+
import { LastConnectedNodeSchema } from '../../models';
6+
7+
export namespace GetUserByTelegramIdCommand {
8+
export const url = REST_API.USERS.GET_BY_TELEGRAM_ID;
9+
export const TSQ_url = url(':telegramId');
10+
11+
export const RequestSchema = z.object({
12+
telegramId: z.string(),
13+
});
14+
15+
export type Request = z.infer<typeof RequestSchema>;
16+
17+
export const ResponseSchema = z.object({
18+
response: z.array(
19+
UsersSchema.extend({
20+
subscriptionUrl: z.string(),
21+
lastConnectedNode: LastConnectedNodeSchema,
22+
}),
23+
),
24+
});
25+
26+
export type Response = z.infer<typeof ResponseSchema>;
27+
}

libs/contract/commands/users/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ export * from './reset-user-traffic.command';
1111
export * from './revoke-user-subscription.command';
1212
export * from './update-user.command';
1313
export * from './bulk';
14+
export * from './get-user-by-telegram-id.command';
15+
export * from './get-user-by-email.command';

libs/contract/commands/users/update-user.command.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ export namespace UpdateUserCommand {
4949
.describe('Expiration date: 2025-01-17T15:38:45.065Z')
5050
.optional(),
5151
description: z.string().optional(),
52+
53+
telegramId: z.number().optional(),
54+
email: z.string().optional(),
5255
});
5356

5457
export type Request = z.infer<typeof RequestSchema>;

libs/contract/constants/errors/errors.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,14 @@ export const ERRORS = {
306306
httpCode: 500,
307307
}),
308308
},
309+
USERS_NOT_FOUND: {
310+
code: 'A062',
311+
message: 'Users not found',
312+
httpCode: 404,
313+
},
314+
GET_USER_BY_UNIQUE_FIELDS_NOT_FOUND: {
315+
code: 'A063',
316+
message: 'User with specified params not found',
317+
httpCode: 404,
318+
},
309319
} as const;

libs/contract/models/users.schema.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ export const UsersSchema = z.object({
5858

5959
description: z.nullable(z.string()),
6060

61+
telegramId: z.nullable(z.number()),
62+
email: z.nullable(z.string()),
63+
6164
createdAt: z
6265
.string()
6366
.datetime()

libs/contract/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@remnawave/backend-contract",
3-
"version": "0.1.15",
3+
"version": "0.2.0",
44
"public": true,
55
"license": "AGPL-3.0-only",
66
"description": "A contract library for Remnawave Backend. It can be used in backend and frontend.",

0 commit comments

Comments
 (0)