правки
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/TelegramExchange/pkg/transaction"
|
||||
"github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain"
|
||||
@@ -19,6 +20,7 @@ SET telegram_id = $2,
|
||||
access_hash = $5,
|
||||
pts = $6,
|
||||
is_accessible = $7,
|
||||
invite_link = $8,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = $1;`
|
||||
|
||||
@@ -32,6 +34,23 @@ WHERE id = $1;`
|
||||
usernameDTO = pgtype.Text{Valid: false}
|
||||
}
|
||||
|
||||
inviteLink := strings.TrimSpace(channel.InviteLink)
|
||||
var inviteLinkDTO pgtype.Text
|
||||
if inviteLink != "" {
|
||||
inviteLinkDTO = pgtype.Text{String: inviteLink, Valid: true}
|
||||
} else {
|
||||
inviteLinkDTO = pgtype.Text{Valid: false}
|
||||
}
|
||||
|
||||
// Log warning if both identity fields are empty (will violate CHECK constraint)
|
||||
if !usernameDTO.Valid && !inviteLinkDTO.Valid {
|
||||
log.Warn().
|
||||
Str("channel_id", channel.ID.String()).
|
||||
Int64("telegram_id", channel.TelegramID).
|
||||
Str("title", channel.Title).
|
||||
Msg("UpdateChannel: both username and invite_link are empty, this may violate CHECK constraint")
|
||||
}
|
||||
|
||||
dto := updateChannelDTO{
|
||||
ID: pgtype.UUID{Bytes: channel.ID, Valid: true},
|
||||
TelegramID: pgtype.Int8{Int64: channel.TelegramID, Valid: true},
|
||||
@@ -40,9 +59,10 @@ WHERE id = $1;`
|
||||
AccessHash: pgtype.Int8{Int64: channel.AccessHash, Valid: true},
|
||||
Pts: pgtype.Int4{Int32: int32(channel.Pts), Valid: true},
|
||||
IsAccessible: pgtype.Bool{Bool: channel.IsAccessible, Valid: true},
|
||||
InviteLink: inviteLinkDTO,
|
||||
}
|
||||
|
||||
_, err := txOrPool.Exec(ctx, query, dto.ID, dto.TelegramID, dto.Username, dto.Title, dto.AccessHash, dto.Pts, dto.IsAccessible)
|
||||
_, err := txOrPool.Exec(ctx, query, dto.ID, dto.TelegramID, dto.Username, dto.Title, dto.AccessHash, dto.Pts, dto.IsAccessible, dto.InviteLink)
|
||||
if err != nil {
|
||||
return fmt.Errorf("txOrPool.Exec: %w", err)
|
||||
}
|
||||
@@ -58,4 +78,5 @@ type updateChannelDTO struct {
|
||||
AccessHash pgtype.Int8
|
||||
Pts pgtype.Int4
|
||||
IsAccessible pgtype.Bool
|
||||
InviteLink pgtype.Text
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user