/
bank_account.resolvers.go
112 lines (97 loc) · 4.44 KB
/
bank_account.resolvers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package resolver
// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
// Code generated by github.com/99designs/gqlgen version v0.17.45
import (
"context"
"errors"
"github.com/99designs/gqlgen/graphql"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-api/graph/model"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-api/mapper"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-api/tracing"
"github.com/opentracing/opentracing-go/log"
)
// BankAccountCreate is the resolver for the bankAccount_Create field.
func (r *mutationResolver) BankAccountCreate(ctx context.Context, input *model.BankAccountCreateInput) (*model.BankAccount, error) {
ctx, span := tracing.StartGraphQLTracerSpan(ctx, "MutationResolver.BankAccountCreate", graphql.GetOperationContext(ctx))
defer span.Finish()
tracing.SetDefaultResolverSpanTags(ctx, span)
tracing.LogObjectAsJson(span, "input", input)
bankAccountId, err := r.Services.BankAccountService.CreateTenantBankAccount(ctx, input)
if err != nil {
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "Failed to create bank account")
return &model.BankAccount{Metadata: &model.Metadata{
ID: bankAccountId,
}}, err
}
createdBankAccountEntity, err := r.Services.BankAccountService.GetTenantBankAccount(ctx, bankAccountId)
if err != nil {
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "Bank account not yet available.")
return &model.BankAccount{Metadata: &model.Metadata{
ID: bankAccountId,
}}, nil
}
span.LogFields(log.String("response.bankAccountId", bankAccountId))
return mapper.MapEntityToBankAccount(createdBankAccountEntity), nil
}
// BankAccountUpdate is the resolver for the bankAccount_Update field.
func (r *mutationResolver) BankAccountUpdate(ctx context.Context, input *model.BankAccountUpdateInput) (*model.BankAccount, error) {
ctx, span := tracing.StartGraphQLTracerSpan(ctx, "MutationResolver.BankAccountUpdate", graphql.GetOperationContext(ctx))
defer span.Finish()
tracing.SetDefaultResolverSpanTags(ctx, span)
tracing.LogObjectAsJson(span, "input", input)
if input.ID == "" {
err := errors.New("missing bank account id")
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "Missing bank account id")
return nil, nil
}
err := r.Services.BankAccountService.UpdateTenantBankAccount(ctx, input)
if err != nil {
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "Failed to update bank account")
return nil, err
}
updatedBankAccountEntity, err := r.Services.BankAccountService.GetTenantBankAccount(ctx, input.ID)
if err != nil {
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "Failed to fetch bank account details")
return nil, nil
}
return mapper.MapEntityToBankAccount(updatedBankAccountEntity), nil
}
// BankAccountDelete is the resolver for the bankAccount_Delete field.
func (r *mutationResolver) BankAccountDelete(ctx context.Context, id string) (*model.DeleteResponse, error) {
ctx, span := tracing.StartGraphQLTracerSpan(ctx, "MutationResolver.BankAccountDelete", graphql.GetOperationContext(ctx))
defer span.Finish()
tracing.SetDefaultResolverSpanTags(ctx, span)
tracing.LogObjectAsJson(span, "id", id)
if id == "" {
err := errors.New("missing bank account id")
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "Missing bank account id")
return &model.DeleteResponse{Accepted: false, Completed: false}, nil
}
deletionCompleted, err := r.Services.BankAccountService.DeleteTenantBankAccount(ctx, id)
if err != nil {
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "Failed to delete bank account")
return &model.DeleteResponse{Accepted: false, Completed: false}, nil
}
return &model.DeleteResponse{Accepted: true, Completed: deletionCompleted}, nil
}
// BankAccounts is the resolver for the bankAccounts field.
func (r *queryResolver) BankAccounts(ctx context.Context) ([]*model.BankAccount, error) {
ctx, span := tracing.StartGraphQLTracerSpan(ctx, "QueryResolver.BankAccounts", graphql.GetOperationContext(ctx))
defer span.Finish()
tracing.SetDefaultResolverSpanTags(ctx, span)
bankAccountEntities, err := r.Services.BankAccountService.GetTenantBankAccounts(ctx)
if err != nil {
tracing.TraceErr(span, err)
graphql.AddErrorf(ctx, "Failed to fetch bank accounts")
return nil, err
}
return mapper.MapEntitiesToBankAccounts(bankAccountEntities), nil
}