-
Notifications
You must be signed in to change notification settings - Fork 0
feat(customers): Dr Green approval status on tenant-admin pages + pull refresh #271
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
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 |
|---|---|---|
|
|
@@ -143,19 +143,33 @@ export const POST = withAuth(async (req, { user }) => { | |
| config, | ||
| ); | ||
|
|
||
| // Update user with additional info | ||
| await prisma.users.update({ | ||
| where: { id: dbUser.id }, | ||
| data: { | ||
| name: `${personal.firstName} ${personal.lastName}`, | ||
| firstName: personal.firstName, | ||
| lastName: personal.lastName, | ||
| // Phone was collected + validated above but previously only sent to | ||
| // Dr Green — persist it locally so Customers detail/export show it. | ||
| phone: `${phoneCode} ${contactNumber}`.trim(), | ||
| updatedAt: new Date(), | ||
| }, | ||
| }); | ||
| // Update user with additional info. The Dr Green client already exists at | ||
| // this point — a local persistence failure must NOT fail the registration | ||
| // (log and continue; the status-refresh sweep self-heals the client id). | ||
| try { | ||
| await prisma.users.update({ | ||
| where: { id: dbUser.id }, | ||
| data: { | ||
| name: `${personal.firstName} ${personal.lastName}`, | ||
| firstName: personal.firstName, | ||
| lastName: personal.lastName, | ||
| // Phone was collected + validated above but previously only sent to | ||
| // Dr Green — persist it locally so Customers detail/export show it. | ||
| phone: `${phoneCode} ${contactNumber}`.trim(), | ||
| // The Dr Green client id was previously returned to the browser but | ||
| // never persisted, leaving these customers unreachable by webhooks | ||
| // and status sync — permanently "pending" on every admin surface. | ||
| ...(result.clientId ? { drGreenClientId: result.clientId } : {}), | ||
| ...(tenant?.id && !dbUser.tenantId ? { tenantId: tenant.id } : {}), | ||
|
Comment on lines
+162
to
+163
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. 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -n -C 8 \
'drGreenClientId|consultation_questionnaires|shop/register|handleClientApproved' \
nextjs_space/app \
nextjs_space/libRepository: AutomatosAI/budstack-saas Length of output: 50382 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- register route ---'
sed -n '1,230p' nextjs_space/app/api/shop/register/route.ts
printf '%s\n' '--- webhook approval handler ---'
sed -n '205,255p' nextjs_space/lib/drgreen/status-event-handlers.ts
printf '%s\n' '--- status sweep matching and self-heal ---'
sed -n '131,185p' nextjs_space/lib/drgreen/client-status-sweep.ts
sed -n '110,170p' nextjs_space/app/tenant-admin/customers/refresh-status-action.ts
printf '%s\n' '--- questionnaire creation and register callers ---'
rg -n -C 5 'consultation_questionnaires\.(create|createMany|upsert)|/api/shop/register|createClient\(' nextjs_space/app nextjs_space/libRepository: AutomatosAI/budstack-saas Length of output: 23235 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- consultation questionnaire persistence ---'
sed -n '280,350p' nextjs_space/app/api/consultation/submit/route.ts
printf '%s\n' '--- register endpoint callers ---'
rg -n -C 10 'api/shop/register|shop/register' nextjs_space --glob '!**/node_modules/**'
printf '%s\n' '--- webhook handler remainder ---'
sed -n '230,275p' nextjs_space/lib/drgreen/status-event-handlers.ts
printf '%s\n' '--- sweep invocation ---'
rg -n -C 8 'refreshCustomerStatuses|client-status-sweep|planStatusUpdates' nextjs_space/app nextjs_space/libRepository: AutomatosAI/budstack-saas Length of output: 30278 Keep the registration mirror aligned with the webhook mirror.
🤖 Prompt for AI Agents |
||
| updatedAt: new Date(), | ||
| }, | ||
| }); | ||
| } catch (persistError) { | ||
| console.error( | ||
| "[shop/register] Dr Green client created but local persistence failed", | ||
| persistError instanceof Error ? persistError.message : persistError, | ||
| ); | ||
| } | ||
|
Comment on lines
+149
to
+172
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. 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -n -C 8 'createClient|idempot|clientId' \
nextjs_space/lib/drgreen \
nextjs_space/app/api/shop/registerRepository: AutomatosAI/budstack-saas Length of output: 50381 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- registration route ---'
sed -n '1,190p' nextjs_space/app/api/shop/register/route.ts
printf '%s\n' '--- createClient and request contract ---'
sed -n '590,685p' nextjs_space/lib/drgreen/doctor-green-api.ts
rg -n -C 12 'async function doctorGreenRequest|function doctorGreenRequest|idempot|Idempot|Idempotency|clientData' \
nextjs_space/lib/drgreen/doctor-green-api.ts \
nextjs_space/lib/drgreenRepository: AutomatosAI/budstack-saas Length of output: 23186 Make external client creation recoverable before returning success. If 🤖 Prompt for AI Agents |
||
|
|
||
| return NextResponse.json({ | ||
| success: true, | ||
|
|
||
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.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Bind the Dr Green client to the authenticated identity.
The route finds
dbUserusinguser.emailat Line [21], but creates the Dr Green client withpersonal.emailat Lines [118-120]. The new code stores that client ID ondbUser. A request with a differentpersonal.emailcan mislink the external client to the authenticated user's local record and misroute later status emails. Reject an email mismatch, or resolve the local record by the same verified email and tenant.🤖 Prompt for AI Agents