Fix like/dislike errors and implement native chat system
This commit is contained in:
@@ -44,7 +44,7 @@ export class MatchingService {
|
||||
|
||||
// Получить профили пользователей
|
||||
const userProfile = await this.profileService.getProfileByTelegramId(telegramId);
|
||||
const targetProfile = await this.profileService.getProfileByUserId(targetTelegramId); if (!userProfile || !targetProfile) {
|
||||
const targetProfile = await this.profileService.getProfileByTelegramId(targetTelegramId); if (!userProfile || !targetProfile) {
|
||||
throw new BotError('Profile not found', 'PROFILE_NOT_FOUND', 400);
|
||||
}
|
||||
|
||||
@@ -82,26 +82,37 @@ export class MatchingService {
|
||||
`, [targetUserId, userId]);
|
||||
|
||||
if (reciprocalSwipe.rows.length > 0) {
|
||||
isMatch = true;
|
||||
const matchId = uuidv4();
|
||||
const isSuperMatch = swipeType === 'superlike' || reciprocalSwipe.rows[0].direction === 'super';
|
||||
// Проверяем, что матч еще не существует
|
||||
const existingMatch = await client.query(`
|
||||
SELECT * FROM matches
|
||||
WHERE (user1_id = $1 AND user2_id = $2) OR (user1_id = $2 AND user2_id = $1)
|
||||
`, [userId, targetUserId]);
|
||||
|
||||
// Создаем матч
|
||||
await client.query(`
|
||||
INSERT INTO matches (id, user1_id, user2_id, matched_at, status)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
`, [matchId, userId, targetUserId, new Date(), 'active']);
|
||||
if (existingMatch.rows.length === 0) {
|
||||
isMatch = true;
|
||||
const matchId = uuidv4();
|
||||
const isSuperMatch = swipeType === 'superlike' || reciprocalSwipe.rows[0].direction === 'super';
|
||||
|
||||
match = new Match({
|
||||
id: matchId,
|
||||
userId1: userId,
|
||||
userId2: targetUserId,
|
||||
createdAt: new Date(),
|
||||
isActive: true,
|
||||
isSuperMatch: false,
|
||||
unreadCount1: 0,
|
||||
unreadCount2: 0
|
||||
});
|
||||
// Упорядочиваем пользователей для консистентности
|
||||
const [user1Id, user2Id] = userId < targetUserId ? [userId, targetUserId] : [targetUserId, userId];
|
||||
|
||||
// Создаем матч
|
||||
await client.query(`
|
||||
INSERT INTO matches (id, user1_id, user2_id, matched_at, status)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
`, [matchId, user1Id, user2Id, new Date(), 'active']);
|
||||
|
||||
match = new Match({
|
||||
id: matchId,
|
||||
userId1: user1Id,
|
||||
userId2: user2Id,
|
||||
createdAt: new Date(),
|
||||
isActive: true,
|
||||
isSuperMatch: isSuperMatch,
|
||||
unreadCount1: 0,
|
||||
unreadCount2: 0
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user