Fix JSON format issues with photos and add multi-photo gallery support

This commit is contained in:
2025-09-18 10:38:29 +09:00
parent bdd7d0424f
commit e275a9856b
13 changed files with 953 additions and 77 deletions

View File

@@ -152,6 +152,89 @@ export class MatchingService {
return this.mapEntityToSwipe(result.rows[0]);
}
// Получить свайп между двумя пользователями (псевдоним для getSwipe)
async getSwipeBetweenUsers(userId: string, targetUserId: string): Promise<Swipe | null> {
return this.getSwipe(userId, targetUserId);
}
// Создать свайп (лайк, дислайк или суперлайк)
async createSwipe(userId: string, targetUserId: string, swipeType: SwipeType): Promise<{
swipe: Swipe;
isMatch: boolean;
match?: Match;
}> {
const swipeId = uuidv4();
let isMatch = false;
let match: Match | undefined;
await transaction(async (client) => {
// Создаем свайп
await client.query(`
INSERT INTO swipes (id, user_id, target_user_id, type, created_at)
VALUES ($1, $2, $3, $4, $5)
`, [swipeId, userId, targetUserId, swipeType, new Date()]);
// Если это лайк или суперлайк, проверяем взаимность
if (swipeType === 'like' || swipeType === 'superlike') {
const reciprocalSwipe = await client.query(`
SELECT * FROM swipes
WHERE user_id = $1 AND target_user_id = $2 AND type IN ('like', 'superlike')
`, [targetUserId, userId]);
if (reciprocalSwipe.rows.length > 0) {
// Проверяем, что матч еще не существует
const existingMatch = await client.query(`
SELECT * FROM matches
WHERE (user_id_1 = $1 AND user_id_2 = $2) OR (user_id_1 = $2 AND user_id_2 = $1)
`, [userId, targetUserId]);
if (existingMatch.rows.length === 0) {
isMatch = true;
const matchId = uuidv4();
const isSuperMatch = swipeType === 'superlike' || reciprocalSwipe.rows[0].type === 'superlike';
// Упорядочиваем пользователей для консистентности
const [user1Id, user2Id] = userId < targetUserId ? [userId, targetUserId] : [targetUserId, userId];
// Создаем матч
await client.query(`
INSERT INTO matches (id, user_id_1, user_id_2, created_at, is_active, is_super_match)
VALUES ($1, $2, $3, $4, $5, $6)
`, [matchId, user1Id, user2Id, new Date(), true, isSuperMatch]);
match = new Match({
id: matchId,
userId1: user1Id,
userId2: user2Id,
createdAt: new Date(),
isActive: true,
isSuperMatch: isSuperMatch,
unreadCount1: 0,
unreadCount2: 0
});
// Обновляем свайпы, отмечая что они образуют матч
await client.query(`
UPDATE swipes SET is_match = true
WHERE (user_id = $1 AND target_user_id = $2) OR (user_id = $2 AND target_user_id = $1)
`, [userId, targetUserId]);
}
}
}
});
const swipe = new Swipe({
id: swipeId,
userId,
targetUserId,
type: swipeType,
timestamp: new Date(),
isMatch
});
return { swipe, isMatch, match };
}
// Получить все матчи пользователя по telegram ID
async getUserMatches(telegramId: string, limit: number = 50): Promise<Match[]> {