91 lines
3.1 KiB
Markdown
91 lines
3.1 KiB
Markdown
# Исправления ошибок в коде
|
||
|
||
## Проблема: Несоответствие имен столбцов в таблице swipes
|
||
|
||
В коде обнаружены несоответствия в названиях столбцов при работе с таблицей `swipes`. Используются два разных варианта именования:
|
||
|
||
1. `user_id` и `target_user_id`
|
||
2. `swiper_id` и `swiped_id`
|
||
|
||
Судя по ошибкам в консоли и анализу кода, корректными именами столбцов являются `user_id` и `target_user_id`.
|
||
|
||
## Необходимые исправления
|
||
|
||
### 1. В файле `profileService.ts` - метод `deleteProfile`:
|
||
|
||
```typescript
|
||
// Неверно:
|
||
await client.query('DELETE FROM swipes WHERE swiper_id = $1 OR swiped_id = $1', [userId]);
|
||
|
||
// Исправить на:
|
||
await client.query('DELETE FROM swipes WHERE user_id = $1 OR target_user_id = $1', [userId]);
|
||
```
|
||
|
||
### 2. В файле `matchingService.ts` - метод `performSwipe`:
|
||
|
||
```typescript
|
||
// Неверно:
|
||
const reciprocalSwipe = await client.query(`
|
||
SELECT * FROM swipes
|
||
WHERE swiper_id = $1 AND swiped_id = $2 AND direction IN ('right', 'super')
|
||
`, [targetUserId, userId]);
|
||
|
||
// Исправить на:
|
||
const reciprocalSwipe = await client.query(`
|
||
SELECT * FROM swipes
|
||
WHERE user_id = $1 AND target_user_id = $2 AND direction IN ('right', 'super')
|
||
`, [targetUserId, userId]);
|
||
```
|
||
|
||
### 3. В файле `matchingService.ts` - метод `getRecentLikes`:
|
||
|
||
```typescript
|
||
// Неверно (если используется метод mapEntityToSwipe):
|
||
private mapEntityToSwipe(entity: any): Swipe {
|
||
return new Swipe({
|
||
id: entity.id,
|
||
userId: entity.swiper_id,
|
||
targetUserId: entity.swiped_id,
|
||
type: this.convertDirectionToSwipeType(entity.direction),
|
||
timestamp: entity.created_at,
|
||
isMatch: entity.is_match
|
||
});
|
||
}
|
||
|
||
// Исправить на:
|
||
private mapEntityToSwipe(entity: any): Swipe {
|
||
return new Swipe({
|
||
id: entity.id,
|
||
userId: entity.user_id,
|
||
targetUserId: entity.target_user_id,
|
||
type: this.convertDirectionToSwipeType(entity.direction),
|
||
timestamp: entity.created_at,
|
||
isMatch: entity.is_match
|
||
});
|
||
}
|
||
```
|
||
|
||
### 4. В файле `matchingService.ts` - метод `getDailySwipeStats`:
|
||
|
||
```typescript
|
||
// Неверно:
|
||
const result = await query(`
|
||
SELECT direction, COUNT(*) as count
|
||
FROM swipes
|
||
WHERE swiper_id = $1 AND created_at >= $2
|
||
GROUP BY direction
|
||
`, [userId, today]);
|
||
|
||
// Исправить на:
|
||
const result = await query(`
|
||
SELECT direction, COUNT(*) as count
|
||
FROM swipes
|
||
WHERE user_id = $1 AND created_at >= $2
|
||
GROUP BY direction
|
||
`, [userId, today]);
|
||
```
|
||
|
||
## Примечание
|
||
|
||
После внесения исправлений рекомендуется проверить все остальные места в коде, где могут использоваться эти имена столбцов, и убедиться в их согласованности.
|