-
Notifications
You must be signed in to change notification settings - Fork 579
[REF-1245] feat(form): enhance hasFilledForm response to include user interests #2069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,21 @@ export class FormService { | |
| } | ||
| } | ||
|
|
||
| private extractInterestsFromAnswers(answers: string): string | null { | ||
| if (!answers?.trim()) { | ||
| return null; | ||
| } | ||
|
|
||
| try { | ||
| const parsed = JSON.parse(answers) as { interests?: unknown } | null; | ||
| const interests = | ||
| typeof parsed?.interests === 'object' ? JSON.stringify(parsed.interests) : null; | ||
| return interests || null; | ||
| } catch { | ||
| return null; | ||
| } | ||
| } | ||
|
Comment on lines
+28
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Proposed fix private extractInterestsFromAnswers(answers: string): string | null {
if (!answers?.trim()) {
return null;
}
try {
const parsed = JSON.parse(answers) as { interests?: unknown } | null;
- const interests =
- typeof parsed?.interests === 'object' ? JSON.stringify(parsed.interests) : null;
- return interests || null;
+ const raw = parsed?.interests;
+ if (raw == null) {
+ return null;
+ }
+ if (typeof raw === 'string') {
+ return raw.trim() || null;
+ }
+ if (Array.isArray(raw) && raw.every((v) => typeof v === 'string')) {
+ return raw.map((v) => v.trim()).filter(Boolean).join(', ') || null;
+ }
+ return JSON.stringify(raw);
} catch {
return null;
}
}🤖 Prompt for AI Agents |
||
|
|
||
| async getFormDefinition(_uid: string): Promise<FormDefinition | null> { | ||
| const formDefinition = await this.prisma.formDefinition.findFirst(); | ||
| if (!formDefinition) { | ||
|
|
@@ -79,7 +94,9 @@ export class FormService { | |
| } | ||
| } | ||
|
|
||
| async hasFilledForm(uid: string): Promise<{ hasFilledForm: boolean; identity: string | null }> { | ||
| async hasFilledForm( | ||
| uid: string, | ||
| ): Promise<{ hasFilledForm: boolean; identity: string; interests: string }> { | ||
| const user = await this.prisma.user.findUnique({ | ||
| where: { uid }, | ||
| select: { preferences: true }, | ||
|
|
@@ -92,14 +109,17 @@ export class FormService { | |
|
|
||
| const identity = this.extractRoleFromAnswers(answers?.answers); | ||
|
|
||
| const interests = this.extractInterestsFromAnswers(answers?.answers); | ||
|
|
||
| if (!user?.preferences) { | ||
| return { hasFilledForm: false, identity: identity ?? null }; | ||
| return { hasFilledForm: false, identity: identity ?? null, interests: interests ?? null }; | ||
| } | ||
|
|
||
| const preferences = JSON.parse(user.preferences); | ||
| return { | ||
| hasFilledForm: preferences.hasFilledForm ?? true, | ||
| identity: identity ?? null, | ||
| interests: interests ?? null, | ||
| }; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,6 +120,7 @@ export const useGetUserSettings = () => { | |
|
|
||
| // Check if user has been invited to show invitation code modal | ||
| let identity: string | null = null; | ||
| let interests: string | null = null; | ||
| try { | ||
| const invitationResp = await getClient().hasBeenInvited(); | ||
| const hasBeenInvited = invitationResp.data?.data ?? false; | ||
|
|
@@ -131,6 +132,7 @@ export const useGetUserSettings = () => { | |
| const formResp = await getClient().hasFilledForm(); | ||
| const hasFilledForm = formResp.data?.data?.hasFilledForm ?? false; | ||
| identity = formResp.data?.data?.identity ?? null; | ||
| interests = formResp.data?.data?.interests ?? null; | ||
| userStore.setShowOnboardingFormModal(!hasFilledForm); | ||
| } catch (_formError) { | ||
| // If form check fails, don't block user login, default to not showing modal | ||
|
|
@@ -147,7 +149,11 @@ export const useGetUserSettings = () => { | |
| } | ||
|
|
||
| if (userTypeForUserProperties) { | ||
| updateUserProperties({ user_plan: userTypeForUserProperties, user_identity: identity }); | ||
| updateUserProperties({ | ||
| user_plan: userTypeForUserProperties, | ||
| user_identity: identity, | ||
| user_acquisition_source: interests, | ||
| }); | ||
| } | ||
|
Comment on lines
151
to
157
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid sending Proposed fix if (userTypeForUserProperties) {
updateUserProperties({
user_plan: userTypeForUserProperties,
- user_identity: identity,
- user_acquisition_source: interests,
+ user_identity: identity ?? undefined,
+ user_acquisition_source: interests ?? undefined,
});
}🤖 Prompt for AI Agents |
||
|
|
||
| // set tour guide | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: refly-ai/refly
Length of output: 2116
Prevent
interests: nullfrom leaking into the API response.The
FormService.hasFilledForm()method can returninterests: null(see lines 115 and 122 where it returnsinterests: interests ?? null), but the OpenAPI schema definesinterestsastype: string(non-nullable). The controller passes this null value directly through, violating the API contract.Proposed fix
async hasFilledForm(`@LoginedUser`() user: User): Promise<HasFilledFormResponse> { const result = await this.formService.hasFilledForm(user.uid); return buildSuccessResponse({ hasFilledForm: result.hasFilledForm, identity: result.identity, - interests: result.interests, + interests: result.interests ?? undefined, }); }🤖 Prompt for AI Agents