-
Notifications
You must be signed in to change notification settings - Fork 0
/
apply_for_verification_mutation.go
64 lines (48 loc) · 1.37 KB
/
apply_for_verification_mutation.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
package community_api_go
import (
"context"
"errors"
am "github.com/214alphadev/community-authentication-middleware"
)
type applyForVerificationResponse struct {
error error
application *application
}
func (r applyForVerificationResponse) Error() *string {
switch r.error {
case nil:
return nil
default:
e := r.error.Error()
return &e
}
}
func (r applyForVerificationResponse) Application() *application {
return r.application
}
func (r *rootResolver) ApplyForVerification(ctx context.Context, args struct{ ApplicationText string }) (applyForVerificationResponse, error) {
memberID := am.GetAuthenticateMember(ctx)
switch memberID {
case nil:
return applyForVerificationResponse{error: errors.New("Unauthenticated")}, nil
default:
applicationEntity, err := r.community.ApplyForVerification(args.ApplicationText, *memberID)
switch err {
case nil:
application, err := newApplicationTypeFromEntity(r.community, applicationEntity)
if err != nil {
return applyForVerificationResponse{}, err
}
return applyForVerificationResponse{application: &application}, nil
default:
switch err.Error() {
case "PendingApplication":
return applyForVerificationResponse{error: err}, nil
case "AlreadyVerified":
return applyForVerificationResponse{error: err}, nil
default:
return applyForVerificationResponse{}, err
}
}
}
}