Files
OwnCord/Server/db/invite_queries.go
T
Claude d769b8bdb6 refactor(server/db): delegate invites + attachments to dbgen (D2)
invites: CreateInvite, GetInvite, UseInviteAtomic, RevokeInvite,
ListInvites. attachments: CreateAttachment, GetAttachmentByID,
GetAttachmentWithChannel, DeleteOrphanedAttachments. Added ptrI64toI /
ptrItoI64 helpers for the *int64<->*int narrowing (invite max_uses,
attachment width/height). LinkAttachmentsToMessage and
GetAttachmentsByMessageIDs keep raw SQL (variable-length IN() lists sqlc
can't express). Behavior and signatures unchanged.

Verified: go build ./...; go test ./db (Invite, Attachment).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UA17KPvqGBX3XbXYnMf1rA
2026-07-19 15:36:59 +00:00

27 lines
669 B
Go

package db
import "fmt"
// ListInvites returns invites ordered by creation time descending.
// M-12: Limited to 200 rows to prevent unbounded result sets.
func (d *DB) ListInvites() ([]*Invite, error) {
rows, err := d.q.ListInvites(dbCtx())
if err != nil {
return nil, fmt.Errorf("ListInvites: %w", err)
}
invites := make([]*Invite, 0, len(rows))
for _, r := range rows {
invites = append(invites, &Invite{
ID: r.ID,
Code: r.Code,
CreatedBy: r.CreatedBy,
Uses: int(r.UseCount),
MaxUses: ptrI64toI(r.MaxUses),
ExpiresAt: r.ExpiresAt,
Revoked: r.Revoked != 0,
CreatedAt: r.CreatedAt,
})
}
return invites, nil
}