Remove tenant service pattern
Signed-off-by: Bryan Frimin <bryan@probo.com>
This commit is contained in:
@@ -51,7 +51,8 @@ func (r *assetResolver) ThirdParties(ctx context.Context, obj *types.Asset, firs
|
||||
return nil, err
|
||||
}
|
||||
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
scope := coredata.NewScopeFromObjectID(obj.ID)
|
||||
prb := r.probo
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.ThirdPartyOrderField]{
|
||||
Field: coredata.ThirdPartyOrderFieldCreatedAt,
|
||||
@@ -66,7 +67,7 @@ func (r *assetResolver) ThirdParties(ctx context.Context, obj *types.Asset, firs
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
page, err := prb.ThirdParties.ListForAssetID(ctx, obj.ID, cursor)
|
||||
page, err := prb.ThirdParties.ListForAssetID(ctx, scope, obj.ID, cursor)
|
||||
if err != nil {
|
||||
r.logger.ErrorCtx(ctx, "cannot list asset thirdParties", log.Error(err))
|
||||
return nil, gqlutils.Internal(ctx)
|
||||
@@ -81,15 +82,16 @@ func (r *assetResolver) Organization(ctx context.Context, obj *types.Asset) (*ty
|
||||
return nil, err
|
||||
}
|
||||
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
scope := coredata.NewScopeFromObjectID(obj.ID)
|
||||
prb := r.probo
|
||||
|
||||
asset, err := prb.Assets.Get(ctx, obj.ID)
|
||||
asset, err := prb.Assets.Get(ctx, scope, obj.ID)
|
||||
if err != nil {
|
||||
r.logger.ErrorCtx(ctx, "cannot load audit", log.Error(err))
|
||||
return nil, gqlutils.Internal(ctx)
|
||||
}
|
||||
|
||||
org, err := prb.Organizations.Get(ctx, asset.OrganizationID)
|
||||
org, err := prb.Organizations.Get(ctx, scope, asset.OrganizationID)
|
||||
if err != nil {
|
||||
if errors.Is(err, coredata.ErrResourceNotFound) {
|
||||
return nil, gqlutils.NotFound(ctx, err)
|
||||
@@ -114,11 +116,12 @@ func (r *assetConnectionResolver) TotalCount(ctx context.Context, obj *types.Ass
|
||||
return 0, err
|
||||
}
|
||||
|
||||
prb := r.ProboService(ctx, obj.ParentID.TenantID())
|
||||
scope := coredata.NewScopeFromObjectID(obj.ParentID)
|
||||
prb := r.probo
|
||||
|
||||
switch obj.Resolver.(type) {
|
||||
case *organizationResolver:
|
||||
count, err := prb.Assets.CountForOrganizationID(ctx, obj.ParentID)
|
||||
count, err := prb.Assets.CountForOrganizationID(ctx, scope, obj.ParentID)
|
||||
if err != nil {
|
||||
r.logger.ErrorCtx(ctx, "cannot count assets", log.Error(err))
|
||||
return 0, gqlutils.Internal(ctx)
|
||||
@@ -158,7 +161,8 @@ func (r *datumResolver) ThirdParties(ctx context.Context, obj *types.Datum, firs
|
||||
return nil, err
|
||||
}
|
||||
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
scope := coredata.NewScopeFromObjectID(obj.ID)
|
||||
prb := r.probo
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.ThirdPartyOrderField]{
|
||||
Field: coredata.ThirdPartyOrderFieldCreatedAt,
|
||||
@@ -173,7 +177,7 @@ func (r *datumResolver) ThirdParties(ctx context.Context, obj *types.Datum, firs
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
page, err := prb.Data.ListThirdParties(ctx, obj.ID, cursor)
|
||||
page, err := prb.Data.ListThirdParties(ctx, scope, obj.ID, cursor)
|
||||
if err != nil {
|
||||
r.logger.ErrorCtx(ctx, "cannot list data thirdParties", log.Error(err))
|
||||
return nil, gqlutils.Internal(ctx)
|
||||
@@ -215,11 +219,12 @@ func (r *datumConnectionResolver) TotalCount(ctx context.Context, obj *types.Dat
|
||||
return 0, err
|
||||
}
|
||||
|
||||
prb := r.ProboService(ctx, obj.ParentID.TenantID())
|
||||
scope := coredata.NewScopeFromObjectID(obj.ParentID)
|
||||
prb := r.probo
|
||||
|
||||
switch obj.Resolver.(type) {
|
||||
case *organizationResolver:
|
||||
count, err := prb.Data.CountForOrganizationID(ctx, obj.ParentID)
|
||||
count, err := prb.Data.CountForOrganizationID(ctx, scope, obj.ParentID)
|
||||
if err != nil {
|
||||
r.logger.ErrorCtx(ctx, "cannot count data", log.Error(err))
|
||||
return 0, gqlutils.Internal(ctx)
|
||||
@@ -239,10 +244,11 @@ func (r *mutationResolver) CreateAsset(ctx context.Context, input types.CreateAs
|
||||
return nil, err
|
||||
}
|
||||
|
||||
prb := r.ProboService(ctx, input.OrganizationID.TenantID())
|
||||
scope := coredata.NewScopeFromObjectID(input.OrganizationID)
|
||||
prb := r.probo
|
||||
|
||||
asset, err := prb.Assets.Create(
|
||||
ctx,
|
||||
ctx, scope,
|
||||
probo.CreateAssetRequest{
|
||||
OrganizationID: input.OrganizationID,
|
||||
Name: input.Name,
|
||||
@@ -274,10 +280,11 @@ func (r *mutationResolver) UpdateAsset(ctx context.Context, input types.UpdateAs
|
||||
return nil, err
|
||||
}
|
||||
|
||||
prb := r.ProboService(ctx, input.ID.TenantID())
|
||||
scope := coredata.NewScopeFromObjectID(input.ID)
|
||||
prb := r.probo
|
||||
|
||||
asset, err := prb.Assets.Update(
|
||||
ctx,
|
||||
ctx, scope,
|
||||
probo.UpdateAssetRequest{
|
||||
ID: input.ID,
|
||||
Name: input.Name,
|
||||
@@ -309,9 +316,10 @@ func (r *mutationResolver) DeleteAsset(ctx context.Context, input types.DeleteAs
|
||||
return nil, err
|
||||
}
|
||||
|
||||
prb := r.ProboService(ctx, input.AssetID.TenantID())
|
||||
scope := coredata.NewScopeFromObjectID(input.AssetID)
|
||||
prb := r.probo
|
||||
|
||||
err := prb.Assets.Delete(ctx, input.AssetID)
|
||||
err := prb.Assets.Delete(ctx, scope, input.AssetID)
|
||||
if err != nil {
|
||||
r.logger.ErrorCtx(ctx, "cannot delete asset", log.Error(err))
|
||||
return nil, gqlutils.Internal(ctx)
|
||||
@@ -328,10 +336,11 @@ func (r *mutationResolver) CreateDatum(ctx context.Context, input types.CreateDa
|
||||
return nil, err
|
||||
}
|
||||
|
||||
prb := r.ProboService(ctx, input.OrganizationID.TenantID())
|
||||
scope := coredata.NewScopeFromObjectID(input.OrganizationID)
|
||||
prb := r.probo
|
||||
|
||||
data, err := prb.Data.Create(
|
||||
ctx,
|
||||
ctx, scope,
|
||||
probo.CreateDatumRequest{
|
||||
OrganizationID: input.OrganizationID,
|
||||
Name: input.Name,
|
||||
@@ -361,10 +370,11 @@ func (r *mutationResolver) UpdateDatum(ctx context.Context, input types.UpdateDa
|
||||
return nil, err
|
||||
}
|
||||
|
||||
prb := r.ProboService(ctx, input.ID.TenantID())
|
||||
scope := coredata.NewScopeFromObjectID(input.ID)
|
||||
prb := r.probo
|
||||
|
||||
datum, err := prb.Data.Update(
|
||||
ctx,
|
||||
ctx, scope,
|
||||
probo.UpdateDatumRequest{
|
||||
ID: input.ID,
|
||||
Name: input.Name,
|
||||
@@ -394,9 +404,10 @@ func (r *mutationResolver) DeleteDatum(ctx context.Context, input types.DeleteDa
|
||||
return nil, err
|
||||
}
|
||||
|
||||
prb := r.ProboService(ctx, input.DatumID.TenantID())
|
||||
scope := coredata.NewScopeFromObjectID(input.DatumID)
|
||||
prb := r.probo
|
||||
|
||||
if err := prb.Data.Delete(ctx, input.DatumID); err != nil {
|
||||
if err := prb.Data.Delete(ctx, scope, input.DatumID); err != nil {
|
||||
r.logger.ErrorCtx(ctx, "cannot delete datum", log.Error(err))
|
||||
return nil, gqlutils.Internal(ctx)
|
||||
}
|
||||
@@ -412,9 +423,10 @@ func (r *mutationResolver) PublishDataList(ctx context.Context, input types.Publ
|
||||
return nil, err
|
||||
}
|
||||
|
||||
prb := r.ProboService(ctx, input.OrganizationID.TenantID())
|
||||
scope := coredata.NewScopeFromObjectID(input.OrganizationID)
|
||||
prb := r.probo
|
||||
|
||||
document, documentVersion, err := prb.GeneratedDocuments.PublishDataList(ctx, input.OrganizationID, input.ApproverIds, input.Minor)
|
||||
document, documentVersion, err := prb.GeneratedDocuments.PublishDataList(ctx, scope, input.OrganizationID, input.ApproverIds, input.Minor)
|
||||
if err != nil {
|
||||
if errors.Is(err, coredata.ErrResourceAlreadyExists) {
|
||||
return nil, gqlutils.Conflict(ctx, err)
|
||||
@@ -441,9 +453,10 @@ func (r *mutationResolver) PublishAssetList(ctx context.Context, input types.Pub
|
||||
return nil, err
|
||||
}
|
||||
|
||||
prb := r.ProboService(ctx, input.OrganizationID.TenantID())
|
||||
scope := coredata.NewScopeFromObjectID(input.OrganizationID)
|
||||
prb := r.probo
|
||||
|
||||
document, documentVersion, err := prb.GeneratedDocuments.PublishAssetList(ctx, input.OrganizationID, input.ApproverIds, input.Minor)
|
||||
document, documentVersion, err := prb.GeneratedDocuments.PublishAssetList(ctx, scope, input.OrganizationID, input.ApproverIds, input.Minor)
|
||||
if err != nil {
|
||||
if errors.Is(err, coredata.ErrResourceAlreadyExists) {
|
||||
return nil, gqlutils.Conflict(ctx, err)
|
||||
|
||||
Reference in New Issue
Block a user