Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion backend/src/controllers/users.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ async function getByTelegramId(req, res, next) {
}
}

async function getByTelegramIds(req, res, next) {
try {
const user = await usersService.getUsers(req.params.telegramIds);
if (!user) {
return res.status(404).json({ error: "User not found" });
}

return res.json(user);
} catch (error) {
return next(error);
}
}


async function listBotInstallations(req, res, next) {
try {
res.json(
Expand All @@ -61,4 +75,4 @@ async function patch(req, res, next) {
}
}

export { allowed, getByTelegramId, list, listBotInstallations, patch, upsert };
export { allowed, getByTelegramId,getByTelegramIds, list, listBotInstallations, patch, upsert };
22 changes: 22 additions & 0 deletions backend/src/repositories/users.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,31 @@ async function findUserByTelegramId(db, telegramId) {
return result.rows[0] || null;
}

async function findUsersByTelegramIds(db, telegramIds) {
const ids = Array.isArray(telegramIds) ? telegramIds : [telegramIds];

if (ids.length === 0) {
return [];
}

const result = await db.query(
`SELECT *
FROM users
WHERE telegram_id = ANY($1::bigint[])`,
[ids],
);

return result.rows;
}

async function getUserByTelegramId(telegramId) {
return mapUser(await findUserByTelegramId({ query }, telegramId));
}

async function getUsersByTelegramIds(telegramIds) {
return mapUser(await findUserByTelegramId({ query }, telegramId));
}

async function getAllUsers() {
const result = await query(
`SELECT *
Expand Down Expand Up @@ -202,6 +223,7 @@ export {
getAllowedUsers,
getAllUsers,
getUserByTelegramId,
getUsersByTelegramIds,
mapUser,
telegramDisplayName,
updateUserByTelegramId,
Expand Down
2 changes: 2 additions & 0 deletions backend/src/routes/users.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Router } from "express";
import {
allowed,
getByTelegramId,
getByTelegramIds,
list,
listBotInstallations,
patch,
Expand All @@ -18,6 +19,7 @@ router.get(
listBotInstallations,
);
router.get("/api/users/:telegramId", getByTelegramId);
router.get("/api/users-ids/:telegramIds", getByTelegramIds);
router.patch("/api/users/:telegramId", patch);

export default router;
7 changes: 7 additions & 0 deletions backend/src/services/users.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
getAllowedTelegramUsers,
getAllUsers,
getUserByTelegramId,
getUsersByTelegramIds,
updateUserByTelegramId,
upsertTelegramUser,
} from "../repositories/users.repository.js";
Expand All @@ -21,10 +22,15 @@ async function listUsers() {
return getAllUsers();
}


async function getUser(telegramId) {
return getUserByTelegramId(telegramId);
}

async function getUsers(telegramIds) {
return getUsersByTelegramIds(telegramIds);
}

async function updateUser(telegramId, data) {
return updateUserByTelegramId(telegramId, data);
}
Expand All @@ -36,6 +42,7 @@ async function listBotInstallations(telegramUserId) {
export {
getAllowedUsers,
getUser,
getUsers,
listBotInstallations,
listUsers,
updateUser,
Expand Down
13 changes: 0 additions & 13 deletions package-lock.json

This file was deleted.

33 changes: 0 additions & 33 deletions package.json

This file was deleted.

4 changes: 2 additions & 2 deletions tele_bot/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ LABEL org.opencontainers.image.licenses="MIT"

WORKDIR /app

COPY package*.json ./
COPY ./package.json ./package-lock.json ./
RUN npm ci --omit=dev

COPY . .
COPY ./src ./src

CMD ["npm", "start"]
Loading
Loading