fix: refs for cassandra db
This commit is contained in:
parent
15a4be5431
commit
c2defdbaac
|
@ -1222,9 +1222,9 @@
|
|||
dependencies:
|
||||
"is-arrayish" "^0.2.1"
|
||||
|
||||
"esbuild-linux-64@0.14.9":
|
||||
"integrity" "sha512-WoEI+R6/PLZAxS7XagfQMFgRtLUi5cjqqU9VCfo3tnWmAXh/wt8QtUfCVVCcXVwZLS/RNvI19CtfjlrJU61nOg=="
|
||||
"resolved" "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.14.9.tgz"
|
||||
"esbuild-darwin-arm64@0.14.9":
|
||||
"integrity" "sha512-3ue+1T4FR5TaAu4/V1eFMG8Uwn0pgAwQZb/WwL1X78d5Cy8wOVQ67KNH1lsjU+y/9AcwMKZ9x0GGNxBB4a1Rbw=="
|
||||
"resolved" "https://registry.npmjs.org/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.14.9.tgz"
|
||||
"version" "0.14.9"
|
||||
|
||||
"esbuild@^0.14.9":
|
||||
|
|
|
@ -17,11 +17,9 @@ func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate *models.E
|
|||
emailTemplate.ID = uuid.New().String()
|
||||
emailTemplate.Key = emailTemplate.ID
|
||||
}
|
||||
|
||||
emailTemplate.Key = emailTemplate.ID
|
||||
emailTemplate.CreatedAt = time.Now().Unix()
|
||||
emailTemplate.UpdatedAt = time.Now().Unix()
|
||||
|
||||
emailTemplateCollection, _ := p.db.Collection(ctx, models.Collections.EmailTemplate)
|
||||
_, err := emailTemplateCollection.CreateDocument(ctx, emailTemplate)
|
||||
if err != nil {
|
||||
|
@ -33,13 +31,11 @@ func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate *models.E
|
|||
// UpdateEmailTemplate to update EmailTemplate
|
||||
func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate *models.EmailTemplate) (*model.EmailTemplate, error) {
|
||||
emailTemplate.UpdatedAt = time.Now().Unix()
|
||||
|
||||
emailTemplateCollection, _ := p.db.Collection(ctx, models.Collections.EmailTemplate)
|
||||
meta, err := emailTemplateCollection.UpdateDocument(ctx, emailTemplate.Key, emailTemplate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
emailTemplate.Key = meta.Key
|
||||
emailTemplate.ID = meta.ID.String()
|
||||
return emailTemplate.AsAPIEmailTemplate(), nil
|
||||
|
@ -57,22 +53,18 @@ func (p *provider) ListEmailTemplate(ctx context.Context, pagination *model.Pagi
|
|||
defer cursor.Close()
|
||||
paginationClone := pagination
|
||||
paginationClone.Total = cursor.Statistics().FullCount()
|
||||
|
||||
for {
|
||||
var emailTemplate *models.EmailTemplate
|
||||
meta, err := cursor.ReadDocument(ctx, &emailTemplate)
|
||||
|
||||
if arangoDriver.IsNoMoreDocuments(err) {
|
||||
break
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if meta.Key != "" {
|
||||
emailTemplates = append(emailTemplates, emailTemplate.AsAPIEmailTemplate())
|
||||
}
|
||||
}
|
||||
|
||||
return &model.EmailTemplates{
|
||||
Pagination: paginationClone,
|
||||
EmailTemplates: emailTemplates,
|
||||
|
@ -86,16 +78,14 @@ func (p *provider) GetEmailTemplateByID(ctx context.Context, emailTemplateID str
|
|||
bindVars := map[string]interface{}{
|
||||
"email_template_id": emailTemplateID,
|
||||
}
|
||||
|
||||
cursor, err := p.db.Query(ctx, query, bindVars)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer cursor.Close()
|
||||
|
||||
for {
|
||||
if !cursor.HasMore() {
|
||||
if emailTemplate.Key == "" {
|
||||
if emailTemplate == nil {
|
||||
return nil, fmt.Errorf("email template not found")
|
||||
}
|
||||
break
|
||||
|
@ -115,16 +105,14 @@ func (p *provider) GetEmailTemplateByEventName(ctx context.Context, eventName st
|
|||
bindVars := map[string]interface{}{
|
||||
"event_name": eventName,
|
||||
}
|
||||
|
||||
cursor, err := p.db.Query(ctx, query, bindVars)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer cursor.Close()
|
||||
|
||||
for {
|
||||
if !cursor.HasMore() {
|
||||
if emailTemplate.Key == "" {
|
||||
if emailTemplate == nil {
|
||||
return nil, fmt.Errorf("email template not found")
|
||||
}
|
||||
break
|
||||
|
|
|
@ -48,16 +48,14 @@ func (p *provider) UpdateEnv(ctx context.Context, env *models.Env) (*models.Env,
|
|||
func (p *provider) GetEnv(ctx context.Context) (*models.Env, error) {
|
||||
var env *models.Env
|
||||
query := fmt.Sprintf("FOR d in %s RETURN d", models.Collections.Env)
|
||||
|
||||
cursor, err := p.db.Query(ctx, query, nil)
|
||||
if err != nil {
|
||||
return env, err
|
||||
}
|
||||
defer cursor.Close()
|
||||
|
||||
for {
|
||||
if !cursor.HasMore() {
|
||||
if env.Key == "" {
|
||||
if env == nil {
|
||||
return env, fmt.Errorf("config not found")
|
||||
}
|
||||
break
|
||||
|
|
|
@ -44,10 +44,8 @@ func (p *provider) UpsertOTP(ctx context.Context, otpParam *models.OTP) (*models
|
|||
otp.Otp = otpParam.Otp
|
||||
otp.ExpiresAt = otpParam.ExpiresAt
|
||||
}
|
||||
|
||||
otp.UpdatedAt = time.Now().Unix()
|
||||
otpCollection, _ := p.db.Collection(ctx, models.Collections.OTP)
|
||||
|
||||
var meta driver.DocumentMeta
|
||||
var err error
|
||||
if shouldCreate {
|
||||
|
@ -55,11 +53,9 @@ func (p *provider) UpsertOTP(ctx context.Context, otpParam *models.OTP) (*models
|
|||
} else {
|
||||
meta, err = otpCollection.UpdateDocument(ctx, otp.Key, otp)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
otp.Key = meta.Key
|
||||
otp.ID = meta.ID.String()
|
||||
return otp, nil
|
||||
|
@ -67,21 +63,19 @@ func (p *provider) UpsertOTP(ctx context.Context, otpParam *models.OTP) (*models
|
|||
|
||||
// GetOTPByEmail to get otp for a given email address
|
||||
func (p *provider) GetOTPByEmail(ctx context.Context, emailAddress string) (*models.OTP, error) {
|
||||
var otp models.OTP
|
||||
var otp *models.OTP
|
||||
query := fmt.Sprintf("FOR d in %s FILTER d.email == @email RETURN d", models.Collections.OTP)
|
||||
bindVars := map[string]interface{}{
|
||||
"email": emailAddress,
|
||||
}
|
||||
|
||||
cursor, err := p.db.Query(ctx, query, bindVars)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer cursor.Close()
|
||||
|
||||
for {
|
||||
if !cursor.HasMore() {
|
||||
if otp.Key == "" {
|
||||
if otp == nil {
|
||||
return nil, fmt.Errorf("otp with given email not found")
|
||||
}
|
||||
break
|
||||
|
@ -91,13 +85,12 @@ func (p *provider) GetOTPByEmail(ctx context.Context, emailAddress string) (*mod
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &otp, nil
|
||||
return otp, nil
|
||||
}
|
||||
|
||||
// GetOTPByPhoneNumber to get otp for a given phone number
|
||||
func (p *provider) GetOTPByPhoneNumber(ctx context.Context, phoneNumber string) (*models.OTP, error) {
|
||||
var otp models.OTP
|
||||
var otp *models.OTP
|
||||
query := fmt.Sprintf("FOR d in %s FILTER d.phone_number == @phone_number RETURN d", models.Collections.OTP)
|
||||
bindVars := map[string]interface{}{
|
||||
"phone_number": phoneNumber,
|
||||
|
@ -109,7 +102,7 @@ func (p *provider) GetOTPByPhoneNumber(ctx context.Context, phoneNumber string)
|
|||
defer cursor.Close()
|
||||
for {
|
||||
if !cursor.HasMore() {
|
||||
if otp.Key == "" {
|
||||
if otp == nil {
|
||||
return nil, fmt.Errorf("otp with given phone_number not found")
|
||||
}
|
||||
break
|
||||
|
@ -119,8 +112,7 @@ func (p *provider) GetOTPByPhoneNumber(ctx context.Context, phoneNumber string)
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &otp, nil
|
||||
return otp, nil
|
||||
}
|
||||
|
||||
// DeleteOTP to delete otp
|
||||
|
@ -130,6 +122,5 @@ func (p *provider) DeleteOTP(ctx context.Context, otp *models.OTP) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -61,7 +61,6 @@ func NewProvider() (*provider, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var arangodb arangoDriver.Database
|
||||
dbName := memorystore.RequiredEnvStoreObj.GetRequiredEnv().DatabaseName
|
||||
arangodb_exists, err := arangoClient.DatabaseExists(ctx, dbName)
|
||||
|
@ -79,7 +78,6 @@ func NewProvider() (*provider, error) {
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
userCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.User)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -113,7 +111,6 @@ func NewProvider() (*provider, error) {
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
verificationRequestCollection, err := arangodb.Collection(ctx, models.Collections.VerificationRequest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -136,7 +133,6 @@ func NewProvider() (*provider, error) {
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
sessionCollection, err := arangodb.Collection(ctx, models.Collections.Session)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -144,7 +140,6 @@ func NewProvider() (*provider, error) {
|
|||
sessionCollection.EnsureHashIndex(ctx, []string{"user_id"}, &arangoDriver.EnsureHashIndexOptions{
|
||||
Sparse: true,
|
||||
})
|
||||
|
||||
envCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.Env)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -155,7 +150,6 @@ func NewProvider() (*provider, error) {
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
webhookCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.Webhook)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -166,7 +160,6 @@ func NewProvider() (*provider, error) {
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
webhookCollection, err := arangodb.Collection(ctx, models.Collections.Webhook)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -186,7 +179,6 @@ func NewProvider() (*provider, error) {
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
webhookLogCollection, err := arangodb.Collection(ctx, models.Collections.WebhookLog)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -194,7 +186,6 @@ func NewProvider() (*provider, error) {
|
|||
webhookLogCollection.EnsureHashIndex(ctx, []string{"webhook_id"}, &arangoDriver.EnsureHashIndexOptions{
|
||||
Sparse: true,
|
||||
})
|
||||
|
||||
emailTemplateCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.EmailTemplate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -205,7 +196,6 @@ func NewProvider() (*provider, error) {
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
emailTemplateCollection, err := arangodb.Collection(ctx, models.Collections.EmailTemplate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -214,7 +204,6 @@ func NewProvider() (*provider, error) {
|
|||
Unique: true,
|
||||
Sparse: true,
|
||||
})
|
||||
|
||||
otpCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.OTP)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -14,7 +14,6 @@ func (p *provider) AddSession(ctx context.Context, session *models.Session) erro
|
|||
session.ID = uuid.New().String()
|
||||
session.Key = session.ID
|
||||
}
|
||||
|
||||
session.CreatedAt = time.Now().Unix()
|
||||
session.UpdatedAt = time.Now().Unix()
|
||||
sessionCollection, _ := p.db.Collection(ctx, models.Collections.Session)
|
||||
|
@ -24,3 +23,8 @@ func (p *provider) AddSession(ctx context.Context, session *models.Session) erro
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteSession to delete session information from database
|
||||
func (p *provider) DeleteSession(ctx context.Context, userId string) error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -73,7 +73,6 @@ func (p *provider) DeleteUser(ctx context.Context, user *models.User) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
query := fmt.Sprintf(`FOR d IN %s FILTER d.user_id == @user_id REMOVE { _key: d._key } IN %s`, models.Collections.Session, models.Collections.Session)
|
||||
bindVars := map[string]interface{}{
|
||||
"user_id": user.Key,
|
||||
|
@ -83,7 +82,6 @@ func (p *provider) DeleteUser(ctx context.Context, user *models.User) error {
|
|||
return err
|
||||
}
|
||||
defer cursor.Close()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -93,16 +91,13 @@ func (p *provider) ListUsers(ctx context.Context, pagination *model.Pagination)
|
|||
sctx := arangoDriver.WithQueryFullCount(ctx)
|
||||
|
||||
query := fmt.Sprintf("FOR d in %s SORT d.created_at DESC LIMIT %d, %d RETURN d", models.Collections.User, pagination.Offset, pagination.Limit)
|
||||
|
||||
cursor, err := p.db.Query(sctx, query, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer cursor.Close()
|
||||
|
||||
paginationClone := pagination
|
||||
paginationClone.Total = cursor.Statistics().FullCount()
|
||||
|
||||
for {
|
||||
var user *models.User
|
||||
meta, err := cursor.ReadDocument(ctx, &user)
|
||||
|
@ -115,7 +110,6 @@ func (p *provider) ListUsers(ctx context.Context, pagination *model.Pagination)
|
|||
users = append(users, user.AsAPIUser())
|
||||
}
|
||||
}
|
||||
|
||||
return &model.Users{
|
||||
Pagination: paginationClone,
|
||||
Users: users,
|
||||
|
@ -136,7 +130,7 @@ func (p *provider) GetUserByEmail(ctx context.Context, email string) (*models.Us
|
|||
defer cursor.Close()
|
||||
for {
|
||||
if !cursor.HasMore() {
|
||||
if user.Key == "" {
|
||||
if user == nil {
|
||||
return user, fmt.Errorf("user not found")
|
||||
}
|
||||
break
|
||||
|
@ -163,7 +157,7 @@ func (p *provider) GetUserByID(ctx context.Context, id string) (*models.User, er
|
|||
defer cursor.Close()
|
||||
for {
|
||||
if !cursor.HasMore() {
|
||||
if user.Key == "" {
|
||||
if user == nil {
|
||||
return user, fmt.Errorf("user not found")
|
||||
}
|
||||
break
|
||||
|
@ -218,7 +212,7 @@ func (p *provider) GetUserByPhoneNumber(ctx context.Context, phoneNumber string)
|
|||
defer cursor.Close()
|
||||
for {
|
||||
if !cursor.HasMore() {
|
||||
if user.Key == "" {
|
||||
if user == nil {
|
||||
return nil, fmt.Errorf("user not found")
|
||||
}
|
||||
break
|
||||
|
|
|
@ -17,7 +17,6 @@ func (p *provider) AddVerificationRequest(ctx context.Context, verificationReque
|
|||
verificationRequest.ID = uuid.New().String()
|
||||
verificationRequest.Key = verificationRequest.ID
|
||||
}
|
||||
|
||||
verificationRequest.CreatedAt = time.Now().Unix()
|
||||
verificationRequest.UpdatedAt = time.Now().Unix()
|
||||
verificationRequestRequestCollection, _ := p.db.Collection(ctx, models.Collections.VerificationRequest)
|
||||
|
@ -27,7 +26,6 @@ func (p *provider) AddVerificationRequest(ctx context.Context, verificationReque
|
|||
}
|
||||
verificationRequest.Key = meta.Key
|
||||
verificationRequest.ID = meta.ID.String()
|
||||
|
||||
return verificationRequest, nil
|
||||
}
|
||||
|
||||
|
@ -38,16 +36,14 @@ func (p *provider) GetVerificationRequestByToken(ctx context.Context, token stri
|
|||
bindVars := map[string]interface{}{
|
||||
"token": token,
|
||||
}
|
||||
|
||||
cursor, err := p.db.Query(ctx, query, bindVars)
|
||||
if err != nil {
|
||||
return verificationRequest, err
|
||||
}
|
||||
defer cursor.Close()
|
||||
|
||||
for {
|
||||
if !cursor.HasMore() {
|
||||
if verificationRequest.Key == "" {
|
||||
if verificationRequest == nil {
|
||||
return verificationRequest, fmt.Errorf("verification request not found")
|
||||
}
|
||||
break
|
||||
|
@ -57,29 +53,25 @@ func (p *provider) GetVerificationRequestByToken(ctx context.Context, token stri
|
|||
return verificationRequest, err
|
||||
}
|
||||
}
|
||||
|
||||
return verificationRequest, nil
|
||||
}
|
||||
|
||||
// GetVerificationRequestByEmail to get verification request by email from database
|
||||
func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email string, identifier string) (*models.VerificationRequest, error) {
|
||||
var verificationRequest *models.VerificationRequest
|
||||
|
||||
query := fmt.Sprintf("FOR d in %s FILTER d.email == @email FILTER d.identifier == @identifier LIMIT 1 RETURN d", models.Collections.VerificationRequest)
|
||||
bindVars := map[string]interface{}{
|
||||
"email": email,
|
||||
"identifier": identifier,
|
||||
}
|
||||
|
||||
cursor, err := p.db.Query(ctx, query, bindVars)
|
||||
if err != nil {
|
||||
return verificationRequest, err
|
||||
}
|
||||
defer cursor.Close()
|
||||
|
||||
for {
|
||||
if !cursor.HasMore() {
|
||||
if verificationRequest.Key == "" {
|
||||
if verificationRequest == nil {
|
||||
return verificationRequest, fmt.Errorf("verification request not found")
|
||||
}
|
||||
break
|
||||
|
@ -89,7 +81,6 @@ func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email stri
|
|||
return verificationRequest, err
|
||||
}
|
||||
}
|
||||
|
||||
return verificationRequest, nil
|
||||
}
|
||||
|
||||
|
@ -120,7 +111,6 @@ func (p *provider) ListVerificationRequests(ctx context.Context, pagination *mod
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
return &model.VerificationRequests{
|
||||
VerificationRequests: verificationRequests,
|
||||
Pagination: paginationClone,
|
||||
|
|
|
@ -95,7 +95,7 @@ func (p *provider) GetWebhookByID(ctx context.Context, webhookID string) (*model
|
|||
defer cursor.Close()
|
||||
for {
|
||||
if !cursor.HasMore() {
|
||||
if webhook.Key == "" {
|
||||
if webhook == nil {
|
||||
return nil, fmt.Errorf("webhook not found")
|
||||
}
|
||||
break
|
||||
|
|
|
@ -17,7 +17,6 @@ func (p *provider) AddWebhookLog(ctx context.Context, webhookLog *models.Webhook
|
|||
webhookLog.ID = uuid.New().String()
|
||||
webhookLog.Key = webhookLog.ID
|
||||
}
|
||||
|
||||
webhookLog.Key = webhookLog.ID
|
||||
webhookLog.CreatedAt = time.Now().Unix()
|
||||
webhookLog.UpdatedAt = time.Now().Unix()
|
||||
|
@ -33,41 +32,33 @@ func (p *provider) AddWebhookLog(ctx context.Context, webhookLog *models.Webhook
|
|||
func (p *provider) ListWebhookLogs(ctx context.Context, pagination *model.Pagination, webhookID string) (*model.WebhookLogs, error) {
|
||||
webhookLogs := []*model.WebhookLog{}
|
||||
bindVariables := map[string]interface{}{}
|
||||
|
||||
query := fmt.Sprintf("FOR d in %s SORT d.created_at DESC LIMIT %d, %d RETURN d", models.Collections.WebhookLog, pagination.Offset, pagination.Limit)
|
||||
|
||||
if webhookID != "" {
|
||||
query = fmt.Sprintf("FOR d in %s FILTER d.webhook_id == @webhook_id SORT d.created_at DESC LIMIT %d, %d RETURN d", models.Collections.WebhookLog, pagination.Offset, pagination.Limit)
|
||||
bindVariables = map[string]interface{}{
|
||||
"webhook_id": webhookID,
|
||||
}
|
||||
}
|
||||
|
||||
sctx := arangoDriver.WithQueryFullCount(ctx)
|
||||
cursor, err := p.db.Query(sctx, query, bindVariables)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer cursor.Close()
|
||||
|
||||
paginationClone := pagination
|
||||
paginationClone.Total = cursor.Statistics().FullCount()
|
||||
|
||||
for {
|
||||
var webhookLog *models.WebhookLog
|
||||
meta, err := cursor.ReadDocument(ctx, &webhookLog)
|
||||
|
||||
if arangoDriver.IsNoMoreDocuments(err) {
|
||||
break
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if meta.Key != "" {
|
||||
webhookLogs = append(webhookLogs, webhookLog.AsAPIWebhookLog())
|
||||
}
|
||||
}
|
||||
|
||||
return &model.WebhookLogs{
|
||||
Pagination: paginationClone,
|
||||
WebhookLogs: webhookLogs,
|
||||
|
|
|
@ -19,29 +19,24 @@ func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate *models.E
|
|||
if emailTemplate.ID == "" {
|
||||
emailTemplate.ID = uuid.New().String()
|
||||
}
|
||||
|
||||
emailTemplate.Key = emailTemplate.ID
|
||||
emailTemplate.CreatedAt = time.Now().Unix()
|
||||
emailTemplate.UpdatedAt = time.Now().Unix()
|
||||
|
||||
existingEmailTemplate, _ := p.GetEmailTemplateByEventName(ctx, emailTemplate.EventName)
|
||||
if existingEmailTemplate != nil {
|
||||
return nil, fmt.Errorf("Email template with %s event_name already exists", emailTemplate.EventName)
|
||||
}
|
||||
|
||||
insertQuery := fmt.Sprintf("INSERT INTO %s (id, event_name, subject, design, template, created_at, updated_at) VALUES ('%s', '%s', '%s','%s','%s', %d, %d)", KeySpace+"."+models.Collections.EmailTemplate, emailTemplate.ID, emailTemplate.EventName, emailTemplate.Subject, emailTemplate.Design, emailTemplate.Template, emailTemplate.CreatedAt, emailTemplate.UpdatedAt)
|
||||
err := p.db.Query(insertQuery).Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return emailTemplate.AsAPIEmailTemplate(), nil
|
||||
}
|
||||
|
||||
// UpdateEmailTemplate to update EmailTemplate
|
||||
func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate *models.EmailTemplate) (*model.EmailTemplate, error) {
|
||||
emailTemplate.UpdatedAt = time.Now().Unix()
|
||||
|
||||
bytes, err := json.Marshal(emailTemplate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -54,22 +49,18 @@ func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate *model
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
updateFields := ""
|
||||
for key, value := range emailTemplateMap {
|
||||
if key == "_id" {
|
||||
continue
|
||||
}
|
||||
|
||||
if key == "_key" {
|
||||
continue
|
||||
}
|
||||
|
||||
if value == nil {
|
||||
updateFields += fmt.Sprintf("%s = null,", key)
|
||||
continue
|
||||
}
|
||||
|
||||
valueType := reflect.TypeOf(value)
|
||||
if valueType.Name() == "string" {
|
||||
updateFields += fmt.Sprintf("%s = '%s', ", key, value.(string))
|
||||
|
@ -95,7 +86,7 @@ func (p *provider) ListEmailTemplate(ctx context.Context, pagination *model.Pagi
|
|||
paginationClone := pagination
|
||||
|
||||
totalCountQuery := fmt.Sprintf(`SELECT COUNT(*) FROM %s`, KeySpace+"."+models.Collections.EmailTemplate)
|
||||
err := p.db.Query(totalCountQuery).Consistency(gocql.One).Scan(paginationClone.Total)
|
||||
err := p.db.Query(totalCountQuery).Consistency(gocql.One).Scan(&paginationClone.Total)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -109,7 +100,7 @@ func (p *provider) ListEmailTemplate(ctx context.Context, pagination *model.Pagi
|
|||
counter := int64(0)
|
||||
for scanner.Next() {
|
||||
if counter >= pagination.Offset {
|
||||
var emailTemplate *models.EmailTemplate
|
||||
var emailTemplate models.EmailTemplate
|
||||
err := scanner.Scan(&emailTemplate.ID, &emailTemplate.EventName, &emailTemplate.Subject, &emailTemplate.Design, &emailTemplate.Template, &emailTemplate.CreatedAt, &emailTemplate.UpdatedAt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -127,7 +118,7 @@ func (p *provider) ListEmailTemplate(ctx context.Context, pagination *model.Pagi
|
|||
|
||||
// GetEmailTemplateByID to get EmailTemplate by id
|
||||
func (p *provider) GetEmailTemplateByID(ctx context.Context, emailTemplateID string) (*model.EmailTemplate, error) {
|
||||
var emailTemplate *models.EmailTemplate
|
||||
var emailTemplate models.EmailTemplate
|
||||
query := fmt.Sprintf(`SELECT id, event_name, subject, design, template, created_at, updated_at FROM %s WHERE id = '%s' LIMIT 1`, KeySpace+"."+models.Collections.EmailTemplate, emailTemplateID)
|
||||
err := p.db.Query(query).Consistency(gocql.One).Scan(&emailTemplate.ID, &emailTemplate.EventName, &emailTemplate.Subject, &emailTemplate.Design, &emailTemplate.Template, &emailTemplate.CreatedAt, &emailTemplate.UpdatedAt)
|
||||
if err != nil {
|
||||
|
@ -138,7 +129,7 @@ func (p *provider) GetEmailTemplateByID(ctx context.Context, emailTemplateID str
|
|||
|
||||
// GetEmailTemplateByEventName to get EmailTemplate by event_name
|
||||
func (p *provider) GetEmailTemplateByEventName(ctx context.Context, eventName string) (*model.EmailTemplate, error) {
|
||||
var emailTemplate *models.EmailTemplate
|
||||
var emailTemplate models.EmailTemplate
|
||||
query := fmt.Sprintf(`SELECT id, event_name, subject, design, template, created_at, updated_at FROM %s WHERE event_name = '%s' LIMIT 1 ALLOW FILTERING`, KeySpace+"."+models.Collections.EmailTemplate, eventName)
|
||||
err := p.db.Query(query).Consistency(gocql.One).Scan(&emailTemplate.ID, &emailTemplate.EventName, &emailTemplate.Subject, &emailTemplate.Design, &emailTemplate.Template, &emailTemplate.CreatedAt, &emailTemplate.UpdatedAt)
|
||||
if err != nil {
|
||||
|
|
|
@ -15,7 +15,6 @@ func (p *provider) AddEnv(ctx context.Context, env *models.Env) (*models.Env, er
|
|||
if env.ID == "" {
|
||||
env.ID = uuid.New().String()
|
||||
}
|
||||
|
||||
env.CreatedAt = time.Now().Unix()
|
||||
env.UpdatedAt = time.Now().Unix()
|
||||
insertEnvQuery := fmt.Sprintf("INSERT INTO %s (id, env, hash, created_at, updated_at) VALUES ('%s', '%s', '%s', %d, %d)", KeySpace+"."+models.Collections.Env, env.ID, env.EnvData, env.Hash, env.CreatedAt, env.UpdatedAt)
|
||||
|
@ -30,7 +29,6 @@ func (p *provider) AddEnv(ctx context.Context, env *models.Env) (*models.Env, er
|
|||
// UpdateEnv to update environment information in database
|
||||
func (p *provider) UpdateEnv(ctx context.Context, env *models.Env) (*models.Env, error) {
|
||||
env.UpdatedAt = time.Now().Unix()
|
||||
|
||||
updateEnvQuery := fmt.Sprintf("UPDATE %s SET env = '%s', updated_at = %d WHERE id = '%s'", KeySpace+"."+models.Collections.Env, env.EnvData, env.UpdatedAt, env.ID)
|
||||
err := p.db.Query(updateEnvQuery).Exec()
|
||||
if err != nil {
|
||||
|
@ -41,13 +39,11 @@ func (p *provider) UpdateEnv(ctx context.Context, env *models.Env) (*models.Env,
|
|||
|
||||
// GetEnv to get environment information from database
|
||||
func (p *provider) GetEnv(ctx context.Context) (*models.Env, error) {
|
||||
var env *models.Env
|
||||
|
||||
var env models.Env
|
||||
query := fmt.Sprintf("SELECT id, env, hash, created_at, updated_at FROM %s LIMIT 1", KeySpace+"."+models.Collections.Env)
|
||||
err := p.db.Query(query).Consistency(gocql.One).Scan(&env.ID, &env.EnvData, &env.Hash, &env.CreatedAt, &env.UpdatedAt)
|
||||
if err != nil {
|
||||
return env, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return env, nil
|
||||
return &env, nil
|
||||
}
|
||||
|
|
|
@ -14,10 +14,8 @@ func (p *provider) AddSession(ctx context.Context, session *models.Session) erro
|
|||
if session.ID == "" {
|
||||
session.ID = uuid.New().String()
|
||||
}
|
||||
|
||||
session.CreatedAt = time.Now().Unix()
|
||||
session.UpdatedAt = time.Now().Unix()
|
||||
|
||||
insertSessionQuery := fmt.Sprintf("INSERT INTO %s (id, user_id, user_agent, ip, created_at, updated_at) VALUES ('%s', '%s', '%s', '%s', %d, %d)", KeySpace+"."+models.Collections.Session, session.ID, session.UserID, session.UserAgent, session.IP, session.CreatedAt, session.UpdatedAt)
|
||||
err := p.db.Query(insertSessionQuery).Exec()
|
||||
if err != nil {
|
||||
|
@ -25,3 +23,8 @@ func (p *provider) AddSession(ctx context.Context, session *models.Session) erro
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteSession to delete session information from database
|
||||
func (p *provider) DeleteSession(ctx context.Context, userId string) error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -77,7 +77,6 @@ func (p *provider) AddUser(ctx context.Context, user *models.User) (*models.User
|
|||
values = values[:len(values)-1] + ")"
|
||||
|
||||
query := fmt.Sprintf("INSERT INTO %s %s VALUES %s IF NOT EXISTS", KeySpace+"."+models.Collections.User, fields, values)
|
||||
|
||||
err = p.db.Query(query).Exec()
|
||||
if err != nil {
|
||||
return user, err
|
||||
|
@ -170,7 +169,7 @@ func (p *provider) ListUsers(ctx context.Context, pagination *model.Pagination)
|
|||
responseUsers := []*model.User{}
|
||||
paginationClone := pagination
|
||||
totalCountQuery := fmt.Sprintf(`SELECT COUNT(*) FROM %s`, KeySpace+"."+models.Collections.User)
|
||||
err := p.db.Query(totalCountQuery).Consistency(gocql.One).Scan(paginationClone.Total)
|
||||
err := p.db.Query(totalCountQuery).Consistency(gocql.One).Scan(&paginationClone.Total)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -183,8 +182,8 @@ func (p *provider) ListUsers(ctx context.Context, pagination *model.Pagination)
|
|||
counter := int64(0)
|
||||
for scanner.Next() {
|
||||
if counter >= pagination.Offset {
|
||||
var user *models.User
|
||||
err := scanner.Scan(user.ID, user.Email, user.EmailVerifiedAt, user.Password, user.SignupMethods, user.GivenName, user.FamilyName, user.MiddleName, user.Nickname, user.Birthdate, user.PhoneNumber, user.PhoneNumberVerifiedAt, user.Picture, user.Roles, user.RevokedTimestamp, user.IsMultiFactorAuthEnabled, user.CreatedAt, user.UpdatedAt)
|
||||
var user models.User
|
||||
err := scanner.Scan(&user.ID, &user.Email, &user.EmailVerifiedAt, &user.Password, &user.SignupMethods, &user.GivenName, &user.FamilyName, &user.MiddleName, &user.Nickname, &user.Birthdate, &user.PhoneNumber, &user.PhoneNumberVerifiedAt, &user.Picture, &user.Roles, &user.RevokedTimestamp, &user.IsMultiFactorAuthEnabled, &user.CreatedAt, &user.UpdatedAt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -200,24 +199,24 @@ func (p *provider) ListUsers(ctx context.Context, pagination *model.Pagination)
|
|||
|
||||
// GetUserByEmail to get user information from database using email address
|
||||
func (p *provider) GetUserByEmail(ctx context.Context, email string) (*models.User, error) {
|
||||
var user *models.User
|
||||
var user models.User
|
||||
query := fmt.Sprintf("SELECT id, email, email_verified_at, password, signup_methods, given_name, family_name, middle_name, nickname, birthdate, phone_number, phone_number_verified_at, picture, roles, revoked_timestamp, is_multi_factor_auth_enabled, created_at, updated_at FROM %s WHERE email = '%s' LIMIT 1 ALLOW FILTERING", KeySpace+"."+models.Collections.User, email)
|
||||
err := p.db.Query(query).Consistency(gocql.One).Scan(&user.ID, &user.Email, &user.EmailVerifiedAt, &user.Password, &user.SignupMethods, &user.GivenName, &user.FamilyName, &user.MiddleName, &user.Nickname, &user.Birthdate, &user.PhoneNumber, &user.PhoneNumberVerifiedAt, &user.Picture, &user.Roles, &user.RevokedTimestamp, &user.IsMultiFactorAuthEnabled, &user.CreatedAt, &user.UpdatedAt)
|
||||
if err != nil {
|
||||
return user, err
|
||||
return nil, err
|
||||
}
|
||||
return user, nil
|
||||
return &user, nil
|
||||
}
|
||||
|
||||
// GetUserByID to get user information from database using user ID
|
||||
func (p *provider) GetUserByID(ctx context.Context, id string) (*models.User, error) {
|
||||
var user *models.User
|
||||
var user models.User
|
||||
query := fmt.Sprintf("SELECT id, email, email_verified_at, password, signup_methods, given_name, family_name, middle_name, nickname, birthdate, phone_number, phone_number_verified_at, picture, roles, revoked_timestamp, is_multi_factor_auth_enabled, created_at, updated_at FROM %s WHERE id = '%s' LIMIT 1", KeySpace+"."+models.Collections.User, id)
|
||||
err := p.db.Query(query).Consistency(gocql.One).Scan(&user.ID, &user.Email, &user.EmailVerifiedAt, &user.Password, &user.SignupMethods, &user.GivenName, &user.FamilyName, &user.MiddleName, &user.Nickname, &user.Birthdate, &user.PhoneNumber, &user.PhoneNumberVerifiedAt, &user.Picture, &user.Roles, &user.RevokedTimestamp, &user.IsMultiFactorAuthEnabled, &user.CreatedAt, &user.UpdatedAt)
|
||||
if err != nil {
|
||||
return user, err
|
||||
return nil, err
|
||||
}
|
||||
return user, nil
|
||||
return &user, nil
|
||||
}
|
||||
|
||||
// UpdateUsers to update multiple users, with parameters of user IDs slice
|
||||
|
@ -306,11 +305,11 @@ func (p *provider) UpdateUsers(ctx context.Context, data map[string]interface{},
|
|||
|
||||
// GetUserByPhoneNumber to get user information from database using phone number
|
||||
func (p *provider) GetUserByPhoneNumber(ctx context.Context, phoneNumber string) (*models.User, error) {
|
||||
var user *models.User
|
||||
var user models.User
|
||||
query := fmt.Sprintf("SELECT id, email, email_verified_at, password, signup_methods, given_name, family_name, middle_name, nickname, birthdate, phone_number, phone_number_verified_at, picture, roles, revoked_timestamp, is_multi_factor_auth_enabled, created_at, updated_at FROM %s WHERE phone_number = '%s' LIMIT 1 ALLOW FILTERING", KeySpace+"."+models.Collections.User, phoneNumber)
|
||||
err := p.db.Query(query).Consistency(gocql.One).Scan(user.ID, user.Email, user.EmailVerifiedAt, user.Password, user.SignupMethods, user.GivenName, user.FamilyName, user.MiddleName, user.Nickname, user.Birthdate, user.PhoneNumber, user.PhoneNumberVerifiedAt, user.Picture, user.Roles, user.RevokedTimestamp, user.IsMultiFactorAuthEnabled, user.CreatedAt, user.UpdatedAt)
|
||||
err := p.db.Query(query).Consistency(gocql.One).Scan(&user.ID, &user.Email, &user.EmailVerifiedAt, &user.Password, &user.SignupMethods, &user.GivenName, &user.FamilyName, &user.MiddleName, &user.Nickname, &user.Birthdate, &user.PhoneNumber, &user.PhoneNumberVerifiedAt, &user.Picture, &user.Roles, &user.RevokedTimestamp, &user.IsMultiFactorAuthEnabled, &user.CreatedAt, &user.UpdatedAt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return user, nil
|
||||
return &user, nil
|
||||
}
|
||||
|
|
|
@ -30,27 +30,27 @@ func (p *provider) AddVerificationRequest(ctx context.Context, verificationReque
|
|||
|
||||
// GetVerificationRequestByToken to get verification request from database using token
|
||||
func (p *provider) GetVerificationRequestByToken(ctx context.Context, token string) (*models.VerificationRequest, error) {
|
||||
var verificationRequest *models.VerificationRequest
|
||||
var verificationRequest models.VerificationRequest
|
||||
query := fmt.Sprintf(`SELECT id, jwt_token, identifier, expires_at, email, nonce, redirect_uri, created_at, updated_at FROM %s WHERE jwt_token = '%s' LIMIT 1`, KeySpace+"."+models.Collections.VerificationRequest, token)
|
||||
|
||||
err := p.db.Query(query).Consistency(gocql.One).Scan(&verificationRequest.ID, &verificationRequest.Token, &verificationRequest.Identifier, &verificationRequest.ExpiresAt, &verificationRequest.Email, &verificationRequest.Nonce, &verificationRequest.RedirectURI, &verificationRequest.CreatedAt, &verificationRequest.UpdatedAt)
|
||||
if err != nil {
|
||||
return verificationRequest, err
|
||||
return nil, err
|
||||
}
|
||||
return verificationRequest, nil
|
||||
return &verificationRequest, nil
|
||||
}
|
||||
|
||||
// GetVerificationRequestByEmail to get verification request by email from database
|
||||
func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email string, identifier string) (*models.VerificationRequest, error) {
|
||||
var verificationRequest *models.VerificationRequest
|
||||
var verificationRequest models.VerificationRequest
|
||||
query := fmt.Sprintf(`SELECT id, jwt_token, identifier, expires_at, email, nonce, redirect_uri, created_at, updated_at FROM %s WHERE email = '%s' AND identifier = '%s' LIMIT 1 ALLOW FILTERING`, KeySpace+"."+models.Collections.VerificationRequest, email, identifier)
|
||||
|
||||
err := p.db.Query(query).Consistency(gocql.One).Scan(&verificationRequest.ID, &verificationRequest.Token, &verificationRequest.Identifier, &verificationRequest.ExpiresAt, &verificationRequest.Email, &verificationRequest.Nonce, &verificationRequest.RedirectURI, &verificationRequest.CreatedAt, &verificationRequest.UpdatedAt)
|
||||
if err != nil {
|
||||
return verificationRequest, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return verificationRequest, nil
|
||||
return &verificationRequest, nil
|
||||
}
|
||||
|
||||
// ListVerificationRequests to get list of verification requests from database
|
||||
|
@ -58,11 +58,10 @@ func (p *provider) ListVerificationRequests(ctx context.Context, pagination *mod
|
|||
var verificationRequests []*model.VerificationRequest
|
||||
paginationClone := pagination
|
||||
totalCountQuery := fmt.Sprintf(`SELECT COUNT(*) FROM %s`, KeySpace+"."+models.Collections.VerificationRequest)
|
||||
err := p.db.Query(totalCountQuery).Consistency(gocql.One).Scan(paginationClone.Total)
|
||||
err := p.db.Query(totalCountQuery).Consistency(gocql.One).Scan(&paginationClone.Total)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// there is no offset in cassandra
|
||||
// so we fetch till limit + offset
|
||||
// and return the results from offset to limit
|
||||
|
@ -72,9 +71,10 @@ func (p *provider) ListVerificationRequests(ctx context.Context, pagination *mod
|
|||
counter := int64(0)
|
||||
for scanner.Next() {
|
||||
if counter >= pagination.Offset {
|
||||
var verificationRequest *models.VerificationRequest
|
||||
var verificationRequest models.VerificationRequest
|
||||
err := scanner.Scan(&verificationRequest.ID, &verificationRequest.Token, &verificationRequest.Identifier, &verificationRequest.ExpiresAt, &verificationRequest.Email, &verificationRequest.Nonce, &verificationRequest.RedirectURI, &verificationRequest.CreatedAt, &verificationRequest.UpdatedAt)
|
||||
if err != nil {
|
||||
fmt.Println("=> getting error here...", err)
|
||||
return nil, err
|
||||
}
|
||||
verificationRequests = append(verificationRequests, verificationRequest.AsAPIVerificationRequest())
|
||||
|
|
|
@ -85,7 +85,7 @@ func (p *provider) ListWebhook(ctx context.Context, pagination *model.Pagination
|
|||
webhooks := []*model.Webhook{}
|
||||
paginationClone := pagination
|
||||
totalCountQuery := fmt.Sprintf(`SELECT COUNT(*) FROM %s`, KeySpace+"."+models.Collections.Webhook)
|
||||
err := p.db.Query(totalCountQuery).Consistency(gocql.One).Scan(paginationClone.Total)
|
||||
err := p.db.Query(totalCountQuery).Consistency(gocql.One).Scan(&paginationClone.Total)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ func (p *provider) ListWebhook(ctx context.Context, pagination *model.Pagination
|
|||
counter := int64(0)
|
||||
for scanner.Next() {
|
||||
if counter >= pagination.Offset {
|
||||
var webhook *models.Webhook
|
||||
var webhook models.Webhook
|
||||
err := scanner.Scan(&webhook.ID, &webhook.EventDescription, &webhook.EventName, &webhook.EndPoint, &webhook.Headers, &webhook.Enabled, &webhook.CreatedAt, &webhook.UpdatedAt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -115,7 +115,7 @@ func (p *provider) ListWebhook(ctx context.Context, pagination *model.Pagination
|
|||
|
||||
// GetWebhookByID to get webhook by id
|
||||
func (p *provider) GetWebhookByID(ctx context.Context, webhookID string) (*model.Webhook, error) {
|
||||
var webhook *models.Webhook
|
||||
var webhook models.Webhook
|
||||
query := fmt.Sprintf(`SELECT id, event_description, event_name, endpoint, headers, enabled, created_at, updated_at FROM %s WHERE id = '%s' LIMIT 1`, KeySpace+"."+models.Collections.Webhook, webhookID)
|
||||
err := p.db.Query(query).Consistency(gocql.One).Scan(&webhook.ID, &webhook.EventDescription, &webhook.EventName, &webhook.EndPoint, &webhook.Headers, &webhook.Enabled, &webhook.CreatedAt, &webhook.UpdatedAt)
|
||||
if err != nil {
|
||||
|
@ -130,7 +130,7 @@ func (p *provider) GetWebhookByEventName(ctx context.Context, eventName string)
|
|||
scanner := p.db.Query(query).Iter().Scanner()
|
||||
webhooks := []*model.Webhook{}
|
||||
for scanner.Next() {
|
||||
var webhook *models.Webhook
|
||||
var webhook models.Webhook
|
||||
err := scanner.Scan(&webhook.ID, &webhook.EventDescription, &webhook.EventName, &webhook.EndPoint, &webhook.Headers, &webhook.Enabled, &webhook.CreatedAt, &webhook.UpdatedAt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -38,13 +38,12 @@ func (p *provider) ListWebhookLogs(ctx context.Context, pagination *model.Pagina
|
|||
// so we fetch till limit + offset
|
||||
// and return the results from offset to limit
|
||||
query := fmt.Sprintf("SELECT id, http_status, response, request, webhook_id, created_at, updated_at FROM %s LIMIT %d", KeySpace+"."+models.Collections.WebhookLog, pagination.Limit+pagination.Offset)
|
||||
|
||||
if webhookID != "" {
|
||||
totalCountQuery = fmt.Sprintf(`SELECT COUNT(*) FROM %s WHERE webhook_id='%s' ALLOW FILTERING`, KeySpace+"."+models.Collections.WebhookLog, webhookID)
|
||||
query = fmt.Sprintf("SELECT id, http_status, response, request, webhook_id, created_at, updated_at FROM %s WHERE webhook_id = '%s' LIMIT %d ALLOW FILTERING", KeySpace+"."+models.Collections.WebhookLog, webhookID, pagination.Limit+pagination.Offset)
|
||||
}
|
||||
|
||||
err := p.db.Query(totalCountQuery).Consistency(gocql.One).Scan(paginationClone.Total)
|
||||
err := p.db.Query(totalCountQuery).Consistency(gocql.One).Scan(&paginationClone.Total)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -53,7 +52,7 @@ func (p *provider) ListWebhookLogs(ctx context.Context, pagination *model.Pagina
|
|||
counter := int64(0)
|
||||
for scanner.Next() {
|
||||
if counter >= pagination.Offset {
|
||||
var webhookLog *models.WebhookLog
|
||||
var webhookLog models.WebhookLog
|
||||
err := scanner.Scan(&webhookLog.ID, &webhookLog.HttpStatus, &webhookLog.Response, &webhookLog.Request, &webhookLog.WebhookID, &webhookLog.CreatedAt, &webhookLog.UpdatedAt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -116,38 +116,32 @@ func (p *provider) GetEmailTemplateByID(ctx context.Context, emailTemplateID str
|
|||
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
||||
PositionalParameters: []interface{}{emailTemplateID},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = q.One(&emailTemplate)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return emailTemplate.AsAPIEmailTemplate(), nil
|
||||
}
|
||||
|
||||
// GetEmailTemplateByEventName to get EmailTemplate by event_name
|
||||
func (p *provider) GetEmailTemplateByEventName(ctx context.Context, eventName string) (*model.EmailTemplate, error) {
|
||||
var emailTemplate *models.EmailTemplate
|
||||
var emailTemplate models.EmailTemplate
|
||||
query := fmt.Sprintf("SELECT _id, event_name, subject, design, template, created_at, updated_at FROM %s.%s WHERE event_name=$1 LIMIT 1", p.scopeName, models.Collections.EmailTemplate)
|
||||
q, err := p.db.Query(query, &gocb.QueryOptions{
|
||||
Context: ctx,
|
||||
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
||||
PositionalParameters: []interface{}{eventName},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = q.One(&emailTemplate)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return emailTemplate.AsAPIEmailTemplate(), nil
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ func (p *provider) AddEnv(ctx context.Context, env *models.Env) (*models.Env, er
|
|||
env.UpdatedAt = time.Now().Unix()
|
||||
env.Key = env.ID
|
||||
env.EncryptionKey = env.Hash
|
||||
|
||||
insertOpt := gocb.InsertOptions{
|
||||
Context: ctx,
|
||||
}
|
||||
|
@ -40,11 +39,9 @@ func (p *provider) UpdateEnv(ctx context.Context, env *models.Env) (*models.Env,
|
|||
Context: ctx,
|
||||
PositionalParameters: []interface{}{env.EnvData, env.UpdatedAt, env.UpdatedAt, env.ID},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return env, err
|
||||
}
|
||||
|
||||
return env, nil
|
||||
}
|
||||
|
||||
|
@ -61,7 +58,6 @@ func (p *provider) GetEnv(ctx context.Context) (*models.Env, error) {
|
|||
return env, err
|
||||
}
|
||||
err = q.One(&env)
|
||||
|
||||
if err != nil {
|
||||
return env, err
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ func (p *provider) AddSession(ctx context.Context, session *models.Session) erro
|
|||
if session.ID == "" {
|
||||
session.ID = uuid.New().String()
|
||||
}
|
||||
|
||||
session.CreatedAt = time.Now().Unix()
|
||||
session.UpdatedAt = time.Now().Unix()
|
||||
insertOpt := gocb.InsertOptions{
|
||||
|
@ -24,7 +23,6 @@ func (p *provider) AddSession(ctx context.Context, session *models.Session) erro
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -41,14 +41,11 @@ func GetSetFields(webhookMap map[string]interface{}) (string, map[string]interfa
|
|||
|
||||
func (p *provider) GetTotalDocs(ctx context.Context, collection string) (int64, error) {
|
||||
totalDocs := TotalDocs{}
|
||||
|
||||
countQuery := fmt.Sprintf("SELECT COUNT(*) as Total FROM %s.%s", p.scopeName, collection)
|
||||
queryRes, err := p.db.Query(countQuery, &gocb.QueryOptions{
|
||||
Context: ctx,
|
||||
})
|
||||
|
||||
queryRes.One(&totalDocs)
|
||||
|
||||
if err != nil {
|
||||
return totalDocs.Total, err
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ func (p *provider) ListUsers(ctx context.Context, pagination *model.Pagination)
|
|||
}
|
||||
paginationClone.Total = total
|
||||
for queryResult.Next() {
|
||||
var user *models.User
|
||||
var user models.User
|
||||
err := queryResult.Row(&user)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
|
@ -17,7 +17,6 @@ func (p *provider) AddVerificationRequest(ctx context.Context, verificationReque
|
|||
if verificationRequest.ID == "" {
|
||||
verificationRequest.ID = uuid.New().String()
|
||||
}
|
||||
|
||||
verificationRequest.Key = verificationRequest.ID
|
||||
verificationRequest.CreatedAt = time.Now().Unix()
|
||||
verificationRequest.UpdatedAt = time.Now().Unix()
|
||||
|
@ -28,7 +27,6 @@ func (p *provider) AddVerificationRequest(ctx context.Context, verificationReque
|
|||
if err != nil {
|
||||
return verificationRequest, err
|
||||
}
|
||||
|
||||
return verificationRequest, nil
|
||||
}
|
||||
|
||||
|
@ -95,7 +93,7 @@ func (p *provider) ListVerificationRequests(ctx context.Context, pagination *mod
|
|||
return nil, err
|
||||
}
|
||||
for queryResult.Next() {
|
||||
var verificationRequest *models.VerificationRequest
|
||||
var verificationRequest models.VerificationRequest
|
||||
err := queryResult.Row(&verificationRequest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
|
@ -89,7 +89,7 @@ func (p *provider) ListWebhook(ctx context.Context, pagination *model.Pagination
|
|||
return nil, err
|
||||
}
|
||||
for queryResult.Next() {
|
||||
var webhook *models.Webhook
|
||||
var webhook models.Webhook
|
||||
err := queryResult.Row(&webhook)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -162,11 +162,9 @@ func (p *provider) DeleteWebhook(ctx context.Context, webhook *model.Webhook) er
|
|||
Context: ctx,
|
||||
}
|
||||
_, err := p.db.Collection(models.Collections.Webhook).Remove(webhook.ID, &removeOpt)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
query := fmt.Sprintf(`DELETE FROM %s.%s WHERE webhook_id=$webhook_id`, p.scopeName, models.Collections.WebhookLog)
|
||||
_, err = p.db.Query(query, &gocb.QueryOptions{
|
||||
Context: ctx,
|
||||
|
@ -176,6 +174,5 @@ func (p *provider) DeleteWebhook(ctx context.Context, webhook *model.Webhook) er
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -17,11 +17,9 @@ func (p *provider) AddWebhookLog(ctx context.Context, webhookLog *models.Webhook
|
|||
if webhookLog.ID == "" {
|
||||
webhookLog.ID = uuid.New().String()
|
||||
}
|
||||
|
||||
webhookLog.Key = webhookLog.ID
|
||||
webhookLog.CreatedAt = time.Now().Unix()
|
||||
webhookLog.UpdatedAt = time.Now().Unix()
|
||||
|
||||
insertOpt := gocb.InsertOptions{
|
||||
Context: ctx,
|
||||
}
|
||||
|
@ -29,7 +27,6 @@ func (p *provider) AddWebhookLog(ctx context.Context, webhookLog *models.Webhook
|
|||
if err != nil {
|
||||
return webhookLog.AsAPIWebhookLog(), err
|
||||
}
|
||||
|
||||
return webhookLog.AsAPIWebhookLog(), nil
|
||||
}
|
||||
|
||||
|
@ -37,11 +34,9 @@ func (p *provider) AddWebhookLog(ctx context.Context, webhookLog *models.Webhook
|
|||
func (p *provider) ListWebhookLogs(ctx context.Context, pagination *model.Pagination, webhookID string) (*model.WebhookLogs, error) {
|
||||
var query string
|
||||
var err error
|
||||
|
||||
webhookLogs := []*model.WebhookLog{}
|
||||
params := make(map[string]interface{}, 1)
|
||||
paginationClone := pagination
|
||||
|
||||
params["webhookID"] = webhookID
|
||||
params["offset"] = paginationClone.Offset
|
||||
params["limit"] = paginationClone.Limit
|
||||
|
@ -55,25 +50,22 @@ func (p *provider) ListWebhookLogs(ctx context.Context, pagination *model.Pagina
|
|||
} else {
|
||||
query = fmt.Sprintf("SELECT _id, http_status, response, request, webhook_id, created_at, updated_at FROM %s.%s OFFSET $offset LIMIT $limit", p.scopeName, models.Collections.WebhookLog)
|
||||
}
|
||||
|
||||
queryResult, err := p.db.Query(query, &gocb.QueryOptions{
|
||||
Context: ctx,
|
||||
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
||||
NamedParameters: params,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for queryResult.Next() {
|
||||
var webhookLog *models.WebhookLog
|
||||
var webhookLog models.WebhookLog
|
||||
err := queryResult.Row(&webhookLog)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
webhookLogs = append(webhookLogs, webhookLog.AsAPIWebhookLog())
|
||||
}
|
||||
|
||||
if err := queryResult.Err(); err != nil {
|
||||
return nil, err
|
||||
|
||||
|
|
|
@ -43,22 +43,18 @@ func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate *model
|
|||
|
||||
// ListEmailTemplates to list EmailTemplate
|
||||
func (p *provider) ListEmailTemplate(ctx context.Context, pagination *model.Pagination) (*model.EmailTemplates, error) {
|
||||
|
||||
var emailTemplate *models.EmailTemplate
|
||||
var iter dynamo.PagingIter
|
||||
var lastEval dynamo.PagingKey
|
||||
var iteration int64 = 0
|
||||
|
||||
collection := p.db.Table(models.Collections.EmailTemplate)
|
||||
emailTemplates := []*model.EmailTemplate{}
|
||||
paginationClone := pagination
|
||||
scanner := collection.Scan()
|
||||
count, err := scanner.Count()
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for (paginationClone.Offset + paginationClone.Limit) > iteration {
|
||||
iter = scanner.StartFrom(lastEval).Limit(paginationClone.Limit).Iter()
|
||||
for iter.NextWithContext(ctx, &emailTemplate) {
|
||||
|
@ -69,9 +65,7 @@ func (p *provider) ListEmailTemplate(ctx context.Context, pagination *model.Pagi
|
|||
lastEval = iter.LastEvaluatedKey()
|
||||
iteration += paginationClone.Limit
|
||||
}
|
||||
|
||||
paginationClone.Total = count
|
||||
|
||||
return &model.EmailTemplates{
|
||||
Pagination: paginationClone,
|
||||
EmailTemplates: emailTemplates,
|
||||
|
@ -111,7 +105,6 @@ func (p *provider) GetEmailTemplateByEventName(ctx context.Context, eventName st
|
|||
func (p *provider) DeleteEmailTemplate(ctx context.Context, emailTemplate *model.EmailTemplate) error {
|
||||
collection := p.db.Table(models.Collections.EmailTemplate)
|
||||
err := collection.Delete("id", emailTemplate.ID).RunWithContext(ctx)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -13,22 +13,16 @@ import (
|
|||
// AddEnv to save environment information in database
|
||||
func (p *provider) AddEnv(ctx context.Context, env *models.Env) (*models.Env, error) {
|
||||
collection := p.db.Table(models.Collections.Env)
|
||||
|
||||
if env.ID == "" {
|
||||
env.ID = uuid.New().String()
|
||||
}
|
||||
|
||||
env.Key = env.ID
|
||||
|
||||
env.CreatedAt = time.Now().Unix()
|
||||
env.UpdatedAt = time.Now().Unix()
|
||||
|
||||
err := collection.Put(env).RunWithContext(ctx)
|
||||
|
||||
if err != nil {
|
||||
return env, err
|
||||
}
|
||||
|
||||
return env, nil
|
||||
}
|
||||
|
||||
|
@ -36,9 +30,7 @@ func (p *provider) AddEnv(ctx context.Context, env *models.Env) (*models.Env, er
|
|||
func (p *provider) UpdateEnv(ctx context.Context, env *models.Env) (*models.Env, error) {
|
||||
collection := p.db.Table(models.Collections.Env)
|
||||
env.UpdatedAt = time.Now().Unix()
|
||||
|
||||
err := UpdateByHashKey(collection, "id", env.ID, env)
|
||||
|
||||
if err != nil {
|
||||
return env, err
|
||||
}
|
||||
|
@ -48,24 +40,19 @@ func (p *provider) UpdateEnv(ctx context.Context, env *models.Env) (*models.Env,
|
|||
// GetEnv to get environment information from database
|
||||
func (p *provider) GetEnv(ctx context.Context) (*models.Env, error) {
|
||||
var env *models.Env
|
||||
|
||||
collection := p.db.Table(models.Collections.Env)
|
||||
// As there is no Findone supported.
|
||||
iter := collection.Scan().Limit(1).Iter()
|
||||
|
||||
for iter.NextWithContext(ctx, &env) {
|
||||
if env.ID == "" {
|
||||
if env == nil {
|
||||
return env, errors.New("no documets found")
|
||||
} else {
|
||||
return env, nil
|
||||
}
|
||||
}
|
||||
|
||||
err := iter.Err()
|
||||
|
||||
if err != nil {
|
||||
return env, fmt.Errorf("config not found")
|
||||
}
|
||||
|
||||
return env, nil
|
||||
}
|
||||
|
|
|
@ -91,7 +91,6 @@ func (p *provider) GetOTPByPhoneNumber(ctx context.Context, phoneNumber string)
|
|||
// DeleteOTP to delete otp
|
||||
func (p *provider) DeleteOTP(ctx context.Context, otp *models.OTP) error {
|
||||
collection := p.db.Table(models.Collections.OTP)
|
||||
|
||||
if otp.ID != "" {
|
||||
err := collection.Delete("id", otp.ID).RunWithContext(ctx)
|
||||
if err != nil {
|
||||
|
|
|
@ -42,10 +42,8 @@ func NewProvider() (*provider, error) {
|
|||
} else {
|
||||
log.Debugf("%s or %s or %s not found. Trying to load default credentials from aws config", constants.EnvAwsRegion, constants.EnvAwsAccessKeyID, constants.EnvAwsSecretAccessKey)
|
||||
}
|
||||
|
||||
session := session.Must(session.NewSession(&config))
|
||||
db := dynamo.New(session)
|
||||
|
||||
db.CreateTable(models.Collections.User, models.User{}).Wait()
|
||||
db.CreateTable(models.Collections.Session, models.Session{}).Wait()
|
||||
db.CreateTable(models.Collections.EmailTemplate, models.EmailTemplate{}).Wait()
|
||||
|
@ -54,7 +52,6 @@ func NewProvider() (*provider, error) {
|
|||
db.CreateTable(models.Collections.VerificationRequest, models.VerificationRequest{}).Wait()
|
||||
db.CreateTable(models.Collections.Webhook, models.Webhook{}).Wait()
|
||||
db.CreateTable(models.Collections.WebhookLog, models.WebhookLog{}).Wait()
|
||||
|
||||
return &provider{
|
||||
db: db,
|
||||
}, nil
|
||||
|
|
|
@ -11,11 +11,9 @@ import (
|
|||
// AddSession to save session information in database
|
||||
func (p *provider) AddSession(ctx context.Context, session *models.Session) error {
|
||||
collection := p.db.Table(models.Collections.Session)
|
||||
|
||||
if session.ID == "" {
|
||||
session.ID = uuid.New().String()
|
||||
}
|
||||
|
||||
session.CreatedAt = time.Now().Unix()
|
||||
session.UpdatedAt = time.Now().Unix()
|
||||
err := collection.Put(session).RunWithContext(ctx)
|
||||
|
|
|
@ -9,16 +9,13 @@ import (
|
|||
func UpdateByHashKey(table dynamo.Table, hashKey string, hashValue string, item interface{}) error {
|
||||
existingValue, err := dynamo.MarshalItem(item)
|
||||
var i interface{}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
nullableValue, err := dynamodbattribute.MarshalMap(item)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
u := table.Update(hashKey, hashValue)
|
||||
for k, v := range existingValue {
|
||||
if k == hashKey {
|
||||
|
@ -26,7 +23,6 @@ func UpdateByHashKey(table dynamo.Table, hashKey string, hashValue string, item
|
|||
}
|
||||
u = u.Set(k, v)
|
||||
}
|
||||
|
||||
for k, v := range nullableValue {
|
||||
if k == hashKey {
|
||||
continue
|
||||
|
@ -36,11 +32,9 @@ func UpdateByHashKey(table dynamo.Table, hashKey string, hashValue string, item
|
|||
u = u.SetNullable(k, v)
|
||||
}
|
||||
}
|
||||
|
||||
err = u.Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ import (
|
|||
// AddVerification to save verification request in database
|
||||
func (p *provider) AddVerificationRequest(ctx context.Context, verificationRequest *models.VerificationRequest) (*models.VerificationRequest, error) {
|
||||
collection := p.db.Table(models.Collections.VerificationRequest)
|
||||
|
||||
if verificationRequest.ID == "" {
|
||||
verificationRequest.ID = uuid.New().String()
|
||||
verificationRequest.CreatedAt = time.Now().Unix()
|
||||
|
@ -23,7 +22,6 @@ func (p *provider) AddVerificationRequest(ctx context.Context, verificationReque
|
|||
return verificationRequest, err
|
||||
}
|
||||
}
|
||||
|
||||
return verificationRequest, nil
|
||||
}
|
||||
|
||||
|
@ -31,12 +29,10 @@ func (p *provider) AddVerificationRequest(ctx context.Context, verificationReque
|
|||
func (p *provider) GetVerificationRequestByToken(ctx context.Context, token string) (*models.VerificationRequest, error) {
|
||||
collection := p.db.Table(models.Collections.VerificationRequest)
|
||||
var verificationRequest *models.VerificationRequest
|
||||
|
||||
iter := collection.Scan().Filter("'token' = ?", token).Iter()
|
||||
for iter.NextWithContext(ctx, &verificationRequest) {
|
||||
return verificationRequest, nil
|
||||
}
|
||||
|
||||
err := iter.Err()
|
||||
if err != nil {
|
||||
return verificationRequest, err
|
||||
|
@ -52,7 +48,6 @@ func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email stri
|
|||
for iter.NextWithContext(ctx, &verificationRequest) {
|
||||
return verificationRequest, nil
|
||||
}
|
||||
|
||||
err := iter.Err()
|
||||
if err != nil {
|
||||
return verificationRequest, err
|
||||
|
@ -67,17 +62,13 @@ func (p *provider) ListVerificationRequests(ctx context.Context, pagination *mod
|
|||
var lastEval dynamo.PagingKey
|
||||
var iter dynamo.PagingIter
|
||||
var iteration int64 = 0
|
||||
|
||||
collection := p.db.Table(models.Collections.VerificationRequest)
|
||||
paginationClone := pagination
|
||||
|
||||
scanner := collection.Scan()
|
||||
count, err := scanner.Count()
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for (paginationClone.Offset + paginationClone.Limit) > iteration {
|
||||
iter = scanner.StartFrom(lastEval).Limit(paginationClone.Limit).Iter()
|
||||
for iter.NextWithContext(ctx, &verificationRequest) {
|
||||
|
@ -92,9 +83,7 @@ func (p *provider) ListVerificationRequests(ctx context.Context, pagination *mod
|
|||
lastEval = iter.LastEvaluatedKey()
|
||||
iteration += paginationClone.Limit
|
||||
}
|
||||
|
||||
paginationClone.Total = count
|
||||
|
||||
return &model.VerificationRequests{
|
||||
VerificationRequests: verificationRequests,
|
||||
Pagination: paginationClone,
|
||||
|
@ -104,7 +93,6 @@ func (p *provider) ListVerificationRequests(ctx context.Context, pagination *mod
|
|||
// DeleteVerificationRequest to delete verification request from database
|
||||
func (p *provider) DeleteVerificationRequest(ctx context.Context, verificationRequest *models.VerificationRequest) error {
|
||||
collection := p.db.Table(models.Collections.VerificationRequest)
|
||||
|
||||
if verificationRequest.ID != "" {
|
||||
err := collection.Delete("id", verificationRequest.ID).RunWithContext(ctx)
|
||||
|
||||
|
|
|
@ -13,16 +13,13 @@ import (
|
|||
// AddWebhookLog to add webhook log
|
||||
func (p *provider) AddWebhookLog(ctx context.Context, webhookLog *models.WebhookLog) (*model.WebhookLog, error) {
|
||||
collection := p.db.Table(models.Collections.WebhookLog)
|
||||
|
||||
if webhookLog.ID == "" {
|
||||
webhookLog.ID = uuid.New().String()
|
||||
}
|
||||
|
||||
webhookLog.Key = webhookLog.ID
|
||||
webhookLog.CreatedAt = time.Now().Unix()
|
||||
webhookLog.UpdatedAt = time.Now().Unix()
|
||||
err := collection.Put(webhookLog).RunWithContext(ctx)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -42,7 +39,6 @@ func (p *provider) ListWebhookLogs(ctx context.Context, pagination *model.Pagina
|
|||
collection := p.db.Table(models.Collections.WebhookLog)
|
||||
paginationClone := pagination
|
||||
scanner := collection.Scan()
|
||||
|
||||
if webhookID != "" {
|
||||
iter = scanner.Index("webhook_id").Filter("'webhook_id' = ?", webhookID).Iter()
|
||||
for iter.NextWithContext(ctx, &webhookLog) {
|
||||
|
@ -68,7 +64,6 @@ func (p *provider) ListWebhookLogs(ctx context.Context, pagination *model.Pagina
|
|||
iteration += paginationClone.Limit
|
||||
}
|
||||
}
|
||||
|
||||
paginationClone.Total = count
|
||||
// paginationClone.Cursor = iter.LastEvaluatedKey()
|
||||
return &model.WebhookLogs{
|
||||
|
|
|
@ -16,11 +16,9 @@ func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate *models.E
|
|||
if emailTemplate.ID == "" {
|
||||
emailTemplate.ID = uuid.New().String()
|
||||
}
|
||||
|
||||
emailTemplate.Key = emailTemplate.ID
|
||||
emailTemplate.CreatedAt = time.Now().Unix()
|
||||
emailTemplate.UpdatedAt = time.Now().Unix()
|
||||
|
||||
emailTemplateCollection := p.db.Collection(models.Collections.EmailTemplate, options.Collection())
|
||||
_, err := emailTemplateCollection.InsertOne(ctx, emailTemplate)
|
||||
if err != nil {
|
||||
|
@ -32,13 +30,11 @@ func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate *models.E
|
|||
// UpdateEmailTemplate to update EmailTemplate
|
||||
func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate *models.EmailTemplate) (*model.EmailTemplate, error) {
|
||||
emailTemplate.UpdatedAt = time.Now().Unix()
|
||||
|
||||
emailTemplateCollection := p.db.Collection(models.Collections.EmailTemplate, options.Collection())
|
||||
_, err := emailTemplateCollection.UpdateOne(ctx, bson.M{"_id": bson.M{"$eq": emailTemplate.ID}}, bson.M{"$set": emailTemplate}, options.MergeUpdateOptions())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return emailTemplate.AsAPIEmailTemplate(), nil
|
||||
}
|
||||
|
||||
|
@ -49,23 +45,18 @@ func (p *provider) ListEmailTemplate(ctx context.Context, pagination *model.Pagi
|
|||
opts.SetLimit(pagination.Limit)
|
||||
opts.SetSkip(pagination.Offset)
|
||||
opts.SetSort(bson.M{"created_at": -1})
|
||||
|
||||
paginationClone := pagination
|
||||
|
||||
emailTemplateCollection := p.db.Collection(models.Collections.EmailTemplate, options.Collection())
|
||||
count, err := emailTemplateCollection.CountDocuments(ctx, bson.M{}, options.Count())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
paginationClone.Total = count
|
||||
|
||||
cursor, err := emailTemplateCollection.Find(ctx, bson.M{}, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer cursor.Close(ctx)
|
||||
|
||||
for cursor.Next(ctx) {
|
||||
var emailTemplate *models.EmailTemplate
|
||||
err := cursor.Decode(&emailTemplate)
|
||||
|
@ -74,7 +65,6 @@ func (p *provider) ListEmailTemplate(ctx context.Context, pagination *model.Pagi
|
|||
}
|
||||
emailTemplates = append(emailTemplates, emailTemplate.AsAPIEmailTemplate())
|
||||
}
|
||||
|
||||
return &model.EmailTemplates{
|
||||
Pagination: paginationClone,
|
||||
EmailTemplates: emailTemplates,
|
||||
|
@ -110,6 +100,5 @@ func (p *provider) DeleteEmailTemplate(ctx context.Context, emailTemplate *model
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ func (p *provider) AddEnv(ctx context.Context, env *models.Env) (*models.Env, er
|
|||
if env.ID == "" {
|
||||
env.ID = uuid.New().String()
|
||||
}
|
||||
|
||||
env.CreatedAt = time.Now().Unix()
|
||||
env.UpdatedAt = time.Now().Unix()
|
||||
env.Key = env.ID
|
||||
|
@ -48,17 +47,14 @@ func (p *provider) GetEnv(ctx context.Context) (*models.Env, error) {
|
|||
return env, err
|
||||
}
|
||||
defer cursor.Close(ctx)
|
||||
|
||||
for cursor.Next(nil) {
|
||||
err := cursor.Decode(&env)
|
||||
if err != nil {
|
||||
return env, err
|
||||
}
|
||||
}
|
||||
|
||||
if env.ID == "" {
|
||||
if env == nil {
|
||||
return env, fmt.Errorf("config not found")
|
||||
}
|
||||
|
||||
return env, nil
|
||||
}
|
||||
|
|
|
@ -25,3 +25,8 @@ func (p *provider) AddSession(ctx context.Context, session *models.Session) erro
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteSession to delete session information from database
|
||||
func (p *provider) DeleteSession(ctx context.Context, userId string) error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ func (p *provider) AddSession(ctx context.Context, session *models.Session) erro
|
|||
if session.ID == "" {
|
||||
session.ID = uuid.New().String()
|
||||
}
|
||||
|
||||
session.CreatedAt = time.Now().Unix()
|
||||
session.UpdatedAt = time.Now().Unix()
|
||||
return nil
|
||||
|
|
|
@ -39,6 +39,8 @@ type Provider interface {
|
|||
|
||||
// AddSession to save session information in database
|
||||
AddSession(ctx context.Context, session *models.Session) error
|
||||
// DeleteSession to delete session information from database
|
||||
DeleteSession(ctx context.Context, userId string) error
|
||||
|
||||
// AddEnv to save environment information in database
|
||||
AddEnv(ctx context.Context, env *models.Env) (*models.Env, error)
|
||||
|
|
|
@ -27,3 +27,8 @@ func (p *provider) AddSession(ctx context.Context, session *models.Session) erro
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteSession to delete session information from database
|
||||
func (p *provider) DeleteSession(ctx context.Context, userId string) error {
|
||||
return nil
|
||||
}
|
||||
|
|
2
server/env/env.go
vendored
2
server/env/env.go
vendored
|
@ -19,7 +19,7 @@ import (
|
|||
// InitEnv to initialize EnvData and through error if required env are not present
|
||||
func InitAllEnv() error {
|
||||
envData, err := GetEnvData()
|
||||
if err != nil {
|
||||
if err != nil || envData == nil {
|
||||
log.Info("No env data found in db, using local clone of env data")
|
||||
// get clone of current store
|
||||
envData, err = memorystore.Provider.GetEnvStore()
|
||||
|
|
7
server/env/persist_env.go
vendored
7
server/env/persist_env.go
vendored
|
@ -62,7 +62,7 @@ func GetEnvData() (map[string]interface{}, error) {
|
|||
ctx := context.Background()
|
||||
env, err := db.Provider.GetEnv(ctx)
|
||||
// config not found in db
|
||||
if err != nil {
|
||||
if err != nil || env == nil {
|
||||
log.Debug("Error while getting env data from db: ", err)
|
||||
return result, err
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ func PersistEnv() error {
|
|||
ctx := context.Background()
|
||||
env, err := db.Provider.GetEnv(ctx)
|
||||
// config not found in db
|
||||
if err != nil || env.EnvData == "" {
|
||||
if err != nil || env == nil {
|
||||
// AES encryption needs 32 bit key only, so we chop off last 4 characters from 36 bit uuid
|
||||
hash := uuid.New().String()[:36-4]
|
||||
err := memorystore.Provider.UpdateEnvVariable(constants.EnvKeyEncryptionKey, hash)
|
||||
|
@ -121,19 +121,16 @@ func PersistEnv() error {
|
|||
return err
|
||||
}
|
||||
encodedHash := crypto.EncryptB64(hash)
|
||||
|
||||
res, err := memorystore.Provider.GetEnvStore()
|
||||
if err != nil {
|
||||
log.Debug("Error while getting env store: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
encryptedConfig, err := crypto.EncryptEnvData(res)
|
||||
if err != nil {
|
||||
log.Debug("Error while encrypting env data: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
env = &models.Env{
|
||||
Hash: encodedHash,
|
||||
EnvData: encryptedConfig,
|
||||
|
|
|
@ -81,6 +81,7 @@ func SignupResolver(ctx context.Context, params model.SignUpInput) (*model.AuthR
|
|||
log.Debug("Failed to get user by email: ", err)
|
||||
}
|
||||
|
||||
if existingUser != nil {
|
||||
if existingUser.EmailVerifiedAt != nil {
|
||||
// email is verified
|
||||
log.Debug("Email is already verified and signed up.")
|
||||
|
@ -89,6 +90,7 @@ func SignupResolver(ctx context.Context, params model.SignUpInput) (*model.AuthR
|
|||
log.Debug("Email is already signed up. Verification pending...")
|
||||
return res, fmt.Errorf("%s has already signed up. please complete the email verification process or reset the password", params.Email)
|
||||
}
|
||||
}
|
||||
|
||||
inputRoles := []string{}
|
||||
if len(params.Roles) > 0 {
|
||||
|
@ -116,13 +118,10 @@ func SignupResolver(ctx context.Context, params model.SignUpInput) (*model.AuthR
|
|||
inputRoles = strings.Split(inputRolesString, ",")
|
||||
}
|
||||
}
|
||||
|
||||
user := &models.User{
|
||||
Email: params.Email,
|
||||
}
|
||||
|
||||
user.Roles = strings.Join(inputRoles, ",")
|
||||
|
||||
password, _ := crypto.EncryptPassword(params.Password)
|
||||
user.Password = &password
|
||||
|
||||
|
|
|
@ -61,8 +61,9 @@ func VerifyOtpResolver(ctx context.Context, params model.VerifyOTPRequest) (*mod
|
|||
} else {
|
||||
user, err = db.Provider.GetUserByPhoneNumber(ctx, refs.StringValue(params.PhoneNumber))
|
||||
}
|
||||
if user.ID == "" && err != nil {
|
||||
log.Debug("Failed to get user by email: ", err)
|
||||
if user == nil || err != nil {
|
||||
fmt.Println("=> failing here....", err)
|
||||
log.Debug("Failed to get user by email or phone number: ", err)
|
||||
return res, err
|
||||
}
|
||||
isSignUp := user.EmailVerifiedAt == nil && user.PhoneNumberVerifiedAt == nil
|
||||
|
|
|
@ -17,11 +17,10 @@ func adminSignupTests(t *testing.T, s TestSetup) {
|
|||
_, err := resolvers.AdminSignupResolver(ctx, model.AdminSignupInput{
|
||||
AdminSecret: "admin",
|
||||
})
|
||||
|
||||
assert.NotNil(t, err)
|
||||
// reset env for test to pass
|
||||
memorystore.Provider.UpdateEnvVariable(constants.EnvKeyAdminSecret, "")
|
||||
|
||||
err = memorystore.Provider.UpdateEnvVariable(constants.EnvKeyAdminSecret, "")
|
||||
assert.Nil(t, err)
|
||||
_, err = resolvers.AdminSignupResolver(ctx, model.AdminSignupInput{
|
||||
AdminSecret: "admin123",
|
||||
})
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"github.com/authorizerdev/authorizer/server/constants"
|
||||
"github.com/authorizerdev/authorizer/server/db"
|
||||
"github.com/authorizerdev/authorizer/server/db/models"
|
||||
"github.com/authorizerdev/authorizer/server/env"
|
||||
"github.com/authorizerdev/authorizer/server/memorystore"
|
||||
"github.com/authorizerdev/authorizer/server/utils"
|
||||
|
@ -78,8 +79,10 @@ func TestResolvers(t *testing.T) {
|
|||
|
||||
// clean the persisted config for test to use fresh config
|
||||
envData, err := db.Provider.GetEnv(ctx)
|
||||
if err == nil && envData.ID != "" {
|
||||
envData.EnvData = ""
|
||||
if err == nil && envData == nil {
|
||||
envData = &models.Env{
|
||||
EnvData: "",
|
||||
}
|
||||
_, err = db.Provider.UpdateEnv(ctx, envData)
|
||||
if err != nil {
|
||||
t.Logf("Error updating env: %s", err.Error())
|
||||
|
|
|
@ -44,9 +44,7 @@ func verificationRequestsTest(t *testing.T, s TestSetup) {
|
|||
assert.Nil(t, err)
|
||||
req.Header.Set("Cookie", fmt.Sprintf("%s=%s", constants.AdminCookieName, h))
|
||||
requests, err = resolvers.VerificationRequestsResolver(ctx, pagination)
|
||||
|
||||
assert.Nil(t, err)
|
||||
|
||||
rLen := len(requests.VerificationRequests)
|
||||
assert.GreaterOrEqual(t, rLen, 1)
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
func GetPagination(paginatedInput *model.PaginatedInput) *model.Pagination {
|
||||
limit := int64(constants.DefaultLimit)
|
||||
page := int64(1)
|
||||
|
||||
if paginatedInput != nil && paginatedInput.Pagination != nil {
|
||||
if paginatedInput.Pagination.Limit != nil {
|
||||
limit = *paginatedInput.Pagination.Limit
|
||||
|
|
Loading…
Reference in New Issue
Block a user