~evanj/cms

31447a2652f9d428e949980e958beed19e9357f2 — Evan M Jones 10 months ago 4acbe35
Fix(db/invite): Don't query for expired invites when select'ing list of
invites.
1 files changed, 11 insertions(+), 5 deletions(-)

M internal/s/db/invite.go
M internal/s/db/invite.go => internal/s/db/invite.go +11 -5
@@ 36,14 36,14 @@ var (
	`

	queryList = `
		SELECT ID FROM cms_invite WHERE ORG_ID=? AND EXPIRES < ? AND USED=FALSE ORDER BY ID DESC
		SELECT ID FROM cms_invite WHERE ORG_ID=? AND EXPIRES < ? AND EXPIRES > ? AND USED=FALSE ORDER BY ID DESC
	`

	queryUse = `
		UPDATE cms_invite SET USED=TRUE WHERE ID=?
	`

	layout = "2006-01-02 15:04:05"
	mysqlTimeLayout = "2006-01-02 15:04:05"
)

func (db *DB) InviteNew(o org.Org) (invite.Invite, error) {


@@ 99,12 99,12 @@ func (db *DB) inviteGet(t *sql.Tx, id string) (invite.Invite, error) {
		return nil, err
	}

	created, err := time.Parse(layout, i.createdStr)
	created, err := time.Parse(mysqlTimeLayout, i.createdStr)
	if err != nil {
		return nil, err
	}

	expires, err := time.Parse(layout, i.expiresStr)
	expires, err := time.Parse(mysqlTimeLayout, i.expiresStr)
	if err != nil {
		return nil, err
	}


@@ 160,7 160,13 @@ func (db *DB) inviteAccept(t *sql.Tx, i invite.Invite, u, p, v string) (user.Use
}

func (db *DB) InviteList(o org.Org) (r []invite.Invite, err error) {
	rows, err := db.Query(queryList, o.ID(), time.Now().UTC().Add(1*time.Hour).Format(layout))
	var (
		now  = time.Now().UTC()
		from = now.Format(mysqlTimeLayout)
		to   = now.Add(1 * time.Hour).Format(mysqlTimeLayout)
	)

	rows, err := db.Query(queryList, o.ID(), to, from)
	if err != nil {
		return nil, err
	}