(ctx context.Context, projectID string, createdByUserID *string, afterID string, limit int)
| 1578 | } |
| 1579 | |
| 1580 | func (c *connection) FindMagicAuthTokensWithUser(ctx context.Context, projectID string, createdByUserID *string, afterID string, limit int) ([]*database.MagicAuthTokenWithUser, error) { |
| 1581 | n := 1 |
| 1582 | where := fmt.Sprintf("t.project_id=$%d", n) |
| 1583 | args := []any{projectID} |
| 1584 | n++ |
| 1585 | |
| 1586 | if createdByUserID != nil { |
| 1587 | where = fmt.Sprintf("%s AND t.created_by_user_id=$%d", where, n) |
| 1588 | args = append(args, *createdByUserID) |
| 1589 | n++ |
| 1590 | } |
| 1591 | |
| 1592 | if afterID != "" { |
| 1593 | where = fmt.Sprintf("%s AND t.id>$%d", where, n) |
| 1594 | args = append(args, afterID) |
| 1595 | n++ |
| 1596 | } |
| 1597 | |
| 1598 | where += " AND (t.expires_on IS NULL OR t.expires_on > now()) AND t.internal=false" |
| 1599 | |
| 1600 | qry := fmt.Sprintf("SELECT t.*, COALESCE(u.email, '') AS created_by_user_email FROM magic_auth_tokens t LEFT JOIN users u ON t.created_by_user_id=u.id WHERE %s ORDER BY t.id LIMIT $%d", where, n) |
| 1601 | args = append(args, limit) |
| 1602 | |
| 1603 | var dtos []*magicAuthTokenWithUserDTO |
| 1604 | err := c.getDB(ctx).SelectContext(ctx, &dtos, qry, args...) |
| 1605 | if err != nil { |
| 1606 | return nil, parseErr("magic auth tokens", err) |
| 1607 | } |
| 1608 | |
| 1609 | res := make([]*database.MagicAuthTokenWithUser, len(dtos)) |
| 1610 | for i, dto := range dtos { |
| 1611 | var err error |
| 1612 | res[i], err = c.magicAuthTokenWithUserFromDTO(dto) |
| 1613 | if err != nil { |
| 1614 | return nil, err |
| 1615 | } |
| 1616 | } |
| 1617 | return res, nil |
| 1618 | } |
| 1619 | |
| 1620 | func (c *connection) FindMagicAuthToken(ctx context.Context, id string, withSecret bool) (*database.MagicAuthToken, error) { |
| 1621 | res := &magicAuthTokenDTO{} |
nothing calls this directly
no test coverage detected