feat: implement resolvers

This commit is contained in:
Lakhan Samani
2022-07-10 21:49:33 +05:30
parent 09c3eafe6b
commit e91a819067
87 changed files with 1807 additions and 428 deletions

View File

@@ -1,6 +1,7 @@
package mongodb
import (
"context"
"time"
"github.com/authorizerdev/authorizer/server/db/models"
@@ -10,7 +11,7 @@ import (
)
// AddSession to save session information in database
func (p *provider) AddSession(session models.Session) error {
func (p *provider) AddSession(ctx context.Context, session models.Session) error {
if session.ID == "" {
session.ID = uuid.New().String()
}
@@ -19,7 +20,7 @@ func (p *provider) AddSession(session models.Session) error {
session.CreatedAt = time.Now().Unix()
session.UpdatedAt = time.Now().Unix()
sessionCollection := p.db.Collection(models.Collections.Session, options.Collection())
_, err := sessionCollection.InsertOne(nil, session)
_, err := sessionCollection.InsertOne(ctx, session)
if err != nil {
return err
}
@@ -27,9 +28,9 @@ func (p *provider) AddSession(session models.Session) error {
}
// DeleteSession to delete session information from database
func (p *provider) DeleteSession(userId string) error {
func (p *provider) DeleteSession(ctx context.Context, userId string) error {
sessionCollection := p.db.Collection(models.Collections.Session, options.Collection())
_, err := sessionCollection.DeleteMany(nil, bson.M{"user_id": userId}, options.Delete())
_, err := sessionCollection.DeleteMany(ctx, bson.M{"user_id": userId}, options.Delete())
if err != nil {
return err
}