-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use posthog in onboarding survey and update custom attributes #4343
ref DEV-1367
- Loading branch information
Showing
15 changed files
with
359 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package graphql | ||
|
||
import ( | ||
"github.com/graphql-go/graphql" | ||
|
||
"github.com/authgear/authgear-server/pkg/portal/model" | ||
"github.com/authgear/authgear-server/pkg/portal/session" | ||
) | ||
|
||
var saveOnboardingSurveyInput = graphql.NewInputObject(graphql.InputObjectConfig{ | ||
Name: "SaveOnboardingSurveyInput", | ||
Fields: graphql.InputObjectConfigFieldMap{ | ||
"surveyJSON": &graphql.InputObjectFieldConfig{ | ||
Type: graphql.NewNonNull(graphql.String), | ||
Description: "Onboarding survey result JSON.", | ||
}, | ||
}, | ||
}) | ||
|
||
var _ = registerMutationField( | ||
"saveOnboardingSurvey", | ||
&graphql.Field{ | ||
Description: "Updates the current user's custom attribute with 'survey' key", | ||
Type: graphql.Boolean, | ||
Args: graphql.FieldConfigArgument{ | ||
"input": &graphql.ArgumentConfig{ | ||
Type: graphql.NewNonNull(saveOnboardingSurveyInput), | ||
}, | ||
}, | ||
Resolve: func(p graphql.ResolveParams) (interface{}, error) { | ||
input := p.Args["input"].(map[string]interface{}) | ||
surveyJSON := input["surveyJSON"].(string) | ||
gqlCtx := GQLContext(p.Context) | ||
|
||
// Access Control: authenicated user. | ||
sessionInfo := session.GetValidSessionInfo(p.Context) | ||
if sessionInfo == nil { | ||
return nil, Unauthenticated.New("only authenticated users can fill onboarding survey") | ||
} | ||
actorID := sessionInfo.UserID | ||
|
||
entry := model.OnboardEntry{ | ||
SurveyJSON: surveyJSON, | ||
} | ||
err := gqlCtx.OnboardService.SubmitOnboardEntry( | ||
entry, | ||
actorID, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return nil, nil | ||
}, | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package model | ||
|
||
type OnboardEntry struct { | ||
PhoneNumber string `json:"onboarding_survey_phone_number"` | ||
SurveyJSON string `json:"onboarding_survey_json"` | ||
} |
Oops, something went wrong.