~evanj/cms

ce1376fafcd1233f8f280d81595846a3ec1684cb — Evan M Jones 9 months ago 9730576 + 31447a2
Merge branch 'master' of git.sr.ht:~evanj/cms
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
	}