Phase 3.7: paid pairing flow + returning chat + extension flip
- Backend: payment_sessions + pairing_failures tables; payment.service.js and pairing-failure.service.js (new); rewritten pairing.service.js (payment-gated blast + targeted "Curhat lagi" + cancel + fallback); rewritten extension.service.js (data-driven auto-approve with offline safeguard, charge-at-approval); pricing.service.js (extension tiers without free trial); mitra-status.service.js (countAvailableMitras cached path); 60s sweeper for stale payment sessions - Backend routes: client.payment.routes, client.mitra-availability.routes, internal/failed-pairings.routes; client.chat.routes rewritten for payment-gated start + /returning + /cancel + /fallback-to-blast; internal/config.routes adds 4 new keys with Valkey invalidate publish - client_app: mitra-availability poll, payment screen + notifier, pairing notifier rewrite (PairingTargetedWaiting + PairingFailed states), targeted-waiting overlay + bestie-unavailable dialog, "Curhat lagi" CTA, failed-pairing terminal, extension via payment-session - mitra_app: PairingRequestType enum, returning-chat 20s countdown auto-dismiss, extension card "otomatis disetujui" copy - control_center: 4 new config rows in Settings, Failed Pairings page (filter + paginate + action menu), sidebar + route registered - Test infrastructure: Vitest backend (7/7 pass), Playwright CC (4/4 pass), Maestro mobile scaffold (CLI install pending) - Bugs found via Playwright + fixed: LoginPage labels not associated with inputs (a11y); backend internal CORS missing PATCH/PUT/DELETE in allow-methods (silent settings breakage in browsers since Stage 4) - Docs: phase3.7.md PRD, phase3.7-plan.md, phase3.7-questions.md (Q&A), phase3.7-testing.md (E2E checklist), phase3.7-test-run-2026-05-03.md (today's run results) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
69
backend/src/routes/internal/failed-pairings.routes.js
Normal file
69
backend/src/routes/internal/failed-pairings.routes.js
Normal file
@@ -0,0 +1,69 @@
|
||||
import { authenticate, requirePermission } from '../../plugins/auth.js'
|
||||
import { getCcUserById } from '../../services/cc-user.service.js'
|
||||
import { listFailures, setOperatorAction } from '../../services/pairing-failure.service.js'
|
||||
import { UserType, PairingFailureCause, PairingFailureOperatorAction } from '../../constants.js'
|
||||
|
||||
const attachCcUser = async (request, reply) => {
|
||||
if (request.auth?.userType !== UserType.CC_USER) {
|
||||
return reply.code(403).send({ success: false, error: { code: 'FORBIDDEN', message: 'Not a control center user' } })
|
||||
}
|
||||
const user = await getCcUserById(request.auth.userId)
|
||||
if (!user) return reply.code(403).send({ success: false, error: { code: 'FORBIDDEN', message: 'Not a control center user' } })
|
||||
request.ccUser = user
|
||||
}
|
||||
|
||||
const VALID_CAUSE_TAGS = new Set(Object.values(PairingFailureCause))
|
||||
const VALID_ACTIONS = new Set(Object.values(PairingFailureOperatorAction))
|
||||
|
||||
/**
|
||||
* Control-center "Failed Pairings" review screen backend.
|
||||
*
|
||||
* GET /internal/failed-pairings
|
||||
* POST /internal/failed-pairings/:id/action
|
||||
*/
|
||||
export const failedPairingsRoutes = async (app) => {
|
||||
app.get('/', {
|
||||
preHandler: [authenticate, attachCcUser, requirePermission('config', 'read')],
|
||||
}, async (request, reply) => {
|
||||
const { cause_tags, date_from, date_to, limit = 50, offset = 0 } = request.query ?? {}
|
||||
|
||||
// cause_tags can arrive as a single string (?cause_tags=foo) or an array
|
||||
// (?cause_tags=foo&cause_tags=bar). Normalize and validate.
|
||||
let causeTagsArr = null
|
||||
if (cause_tags !== undefined) {
|
||||
causeTagsArr = Array.isArray(cause_tags) ? cause_tags : [cause_tags]
|
||||
for (const tag of causeTagsArr) {
|
||||
if (!VALID_CAUSE_TAGS.has(tag)) {
|
||||
return reply.code(422).send({
|
||||
success: false,
|
||||
error: { code: 'VALIDATION_ERROR', message: `Unknown cause_tag: ${tag}` },
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const result = await listFailures({
|
||||
causeTags: causeTagsArr,
|
||||
dateFrom: date_from || null,
|
||||
dateTo: date_to || null,
|
||||
limit: Number(limit) || 50,
|
||||
offset: Number(offset) || 0,
|
||||
})
|
||||
|
||||
return reply.send({ success: true, data: result })
|
||||
})
|
||||
|
||||
app.post('/:id/action', {
|
||||
preHandler: [authenticate, attachCcUser, requirePermission('config', 'update')],
|
||||
}, async (request, reply) => {
|
||||
const { action } = request.body ?? {}
|
||||
if (!VALID_ACTIONS.has(action)) {
|
||||
return reply.code(422).send({
|
||||
success: false,
|
||||
error: { code: 'VALIDATION_ERROR', message: `action must be one of: ${[...VALID_ACTIONS].join(', ')}` },
|
||||
})
|
||||
}
|
||||
const updated = await setOperatorAction(request.params.id, request.ccUser.id, action)
|
||||
return reply.send({ success: true, data: updated })
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user