2026-03-14 20:52:11 +01:00
|
|
|
package db
|
|
|
|
|
|
2026-07-23 17:03:52 +02:00
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
)
|
2026-03-14 20:52:11 +01:00
|
|
|
|
2026-04-04 16:48:57 +00:00
|
|
|
// ListInvites returns invites ordered by creation time descending.
|
|
|
|
|
// M-12: Limited to 200 rows to prevent unbounded result sets.
|
2026-07-23 17:03:52 +02:00
|
|
|
func (d *DB) ListInvites(ctx context.Context) ([]*Invite, error) {
|
|
|
|
|
rows, err := d.q.ListInvites(ctx)
|
2026-03-14 20:52:11 +01:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("ListInvites: %w", err)
|
|
|
|
|
}
|
2026-07-19 15:36:59 +00:00
|
|
|
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,
|
|
|
|
|
})
|
2026-03-14 20:52:11 +01:00
|
|
|
}
|
2026-07-19 15:36:59 +00:00
|
|
|
return invites, nil
|
2026-03-14 20:52:11 +01:00
|
|
|
}
|