diff --git a/crm/internal/repository/repository.go b/crm/internal/repository/repository.go index c93a728d2..30c026c18 100644 --- a/crm/internal/repository/repository.go +++ b/crm/internal/repository/repository.go @@ -4,6 +4,10 @@ import ( "context" "github.com/titpetric/factory" + + "github.com/crusttech/crust/internal/auth" + "github.com/crusttech/crust/internal/organization" + "github.com/crusttech/crust/messaging/types" ) type ( @@ -18,6 +22,19 @@ func DB(ctx context.Context) *factory.DB { return factory.Database.MustGet("crm").With(ctx) } +// Identity returns the User ID from context +func Identity(ctx context.Context) uint64 { + return auth.GetIdentityFromContext(ctx).Identity() +} + +// Organisation returns the Organisation from context +func Organization(ctx context.Context) *types.Organisation { + return &types.Organisation{ + organization.GetFromContext(ctx), + } +} + +// With updates repository and database contexts func (r *repository) With(ctx context.Context, db *factory.DB) *repository { return &repository{ ctx: ctx,