authorizer/server/db/models/verification_requests.go

44 lines
2.1 KiB
Go
Raw Normal View History

2022-01-21 06:48:07 +00:00
package models
import (
"strings"
"github.com/authorizerdev/authorizer/server/graph/model"
2022-07-15 16:41:08 +00:00
"github.com/authorizerdev/authorizer/server/refs"
)
2022-04-21 07:06:22 +00:00
// Note: any change here should be reflected in providers/casandra/provider.go as it does not have model support in collection creation
2022-01-21 06:48:07 +00:00
// VerificationRequest model for db
type VerificationRequest struct {
2022-10-02 19:38:12 +00:00
Key string `json:"_key,omitempty" bson:"_key" cql:"_key,omitempty" dynamo:"key,omitempty"` // for arangodb
ID string `gorm:"primaryKey;type:char(36)" json:"_id" bson:"_id" cql:"id" dynamo:"id,hash"`
Token string `gorm:"type:text" json:"token" bson:"token" cql:"jwt_token" dynamo:"token"` // token is reserved keyword in cassandra
Identifier string `gorm:"uniqueIndex:idx_email_identifier;type:varchar(64)" json:"identifier" bson:"identifier" cql:"identifier" dynamo:"identifier"`
ExpiresAt int64 `json:"expires_at" bson:"expires_at" cql:"expires_at" dynamo:"expires_at"`
Email string `gorm:"uniqueIndex:idx_email_identifier;type:varchar(256)" json:"email" bson:"email" cql:"email" dynamo:"email"`
Nonce string `gorm:"type:text" json:"nonce" bson:"nonce" cql:"nonce" dynamo:"nonce"`
RedirectURI string `gorm:"type:text" json:"redirect_uri" bson:"redirect_uri" cql:"redirect_uri" dynamo:"redirect_uri"`
CreatedAt int64 `json:"created_at" bson:"created_at" cql:"created_at" dynamo:"created_at"`
UpdatedAt int64 `json:"updated_at" bson:"updated_at" cql:"updated_at" dynamo:"updated_at"`
2022-01-21 06:48:07 +00:00
}
func (v *VerificationRequest) AsAPIVerificationRequest() *model.VerificationRequest {
id := v.ID
if strings.Contains(id, Collections.VerificationRequest+"/") {
id = strings.TrimPrefix(id, Collections.VerificationRequest+"/")
}
2022-07-15 16:41:08 +00:00
return &model.VerificationRequest{
ID: id,
2022-07-15 16:41:08 +00:00
Token: refs.NewStringRef(v.Token),
2022-07-15 16:43:00 +00:00
Identifier: refs.NewStringRef(v.Identifier),
2022-07-15 16:41:08 +00:00
Expires: refs.NewInt64Ref(v.ExpiresAt),
Email: refs.NewStringRef(v.Email),
Nonce: refs.NewStringRef(v.Nonce),
RedirectURI: refs.NewStringRef(v.RedirectURI),
CreatedAt: refs.NewInt64Ref(v.CreatedAt),
UpdatedAt: refs.NewInt64Ref(v.UpdatedAt),
}
}