stmt,err:=Db.Preparex("SELECT a.*, b.company, b.title, b.message, b.domain FROM account a, organization b WHERE b.refid=a.orgid and a.orgid=? and a.userid=? AND b.active=1")
deferutility.Close(stmt)
iferr!=nil{
log.Error(fmt.Sprintf("Unable to prepare select for account by user %s",userID),err)
return
}
err=stmt.Get(&account,p.Context.OrgID,userID)
iferr!=sql.ErrNoRows&&err!=nil{
log.Error(fmt.Sprintf("Unable to execute select for account by user %s",userID),err)
return
}
return
}
// GetUserAccounts returns a slice of database account records, for all organizations that the userID is a member of, in organization title order.
err=Db.Select(&t,"SELECT a.*, b.company, b.title, b.message, b.domain FROM account a, organization b WHERE a.userid=? AND a.orgid=b.refid AND b.active=1 ORDER BY b.title",userID)
iferr!=sql.ErrNoRows&&err!=nil{
log.Error(fmt.Sprintf("Unable to execute select account for user %s",userID),err)
}
return
}
// GetAccountsByOrg returns a slice of database account records, for all users in the client's organization.
err=Db.Select(&t,"SELECT a.*, b.company, b.title, b.message, b.domain FROM account a, organization b WHERE a.orgid=b.refid AND a.orgid=? AND b.active=1",p.Context.OrgID)
iferr!=sql.ErrNoRows&&err!=nil{
log.Error(fmt.Sprintf("Unable to execute select account for org %s",p.Context.OrgID),err)
}
return
}
// UpdateAccount updates the database record for the given account to the given values.
stmt,err:=p.Context.Transaction.PrepareNamed("UPDATE account SET userid=:userid, admin=:admin, editor=:editor, revised=:revised WHERE orgid=:orgid AND refid=:refid")
deferutility.Close(stmt)
iferr!=nil{
log.Error(fmt.Sprintf("Unable to prepare update for account %s",account.RefID),err)
return
}
_,err=stmt.Exec(&account)
iferr!=sql.ErrNoRows&&err!=nil{
log.Error(fmt.Sprintf("Unable to execute update for account %s",account.RefID),err)
return
}
return
}
// HasOrgAccount returns if the given orgID has valid userID.