spine-framework-portal 0.2.11 → 0.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHandler } from './_shared/middleware'
|
|
2
|
-
import {
|
|
2
|
+
import { adminDb } from './_shared/db'
|
|
3
|
+
import { resolveTypeId } from './_shared/resolve-ids'
|
|
3
4
|
|
|
4
5
|
export const handler = createHandler(async (ctx, body) => {
|
|
5
6
|
const {
|
|
@@ -26,7 +27,21 @@ export const handler = createHandler(async (ctx, body) => {
|
|
|
26
27
|
throw err
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
// Get the funnel_signal type_id
|
|
31
|
+
const { data: typeId } = await adminDb
|
|
32
|
+
.from('types')
|
|
33
|
+
.select('id')
|
|
34
|
+
.eq('kind', 'item')
|
|
35
|
+
.eq('slug', 'funnel_signal')
|
|
36
|
+
.single()
|
|
37
|
+
|
|
38
|
+
if (!typeId) {
|
|
39
|
+
const err: any = new Error('funnel_signal type not found')
|
|
40
|
+
err.statusCode = 500
|
|
41
|
+
throw err
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const signalData = {
|
|
30
45
|
account_id: ctx.accountId,
|
|
31
46
|
person_id: ctx.principal.id,
|
|
32
47
|
session_id: session_id || `portal_${ctx.principal.id}_${Date.now()}`,
|
|
@@ -43,13 +58,23 @@ export const handler = createHandler(async (ctx, body) => {
|
|
|
43
58
|
occurred_at: new Date().toISOString()
|
|
44
59
|
}
|
|
45
60
|
|
|
46
|
-
|
|
61
|
+
// Create the signal item directly using admin-data pattern
|
|
62
|
+
const { data: signal, error } = await adminDb
|
|
63
|
+
.from('items')
|
|
64
|
+
.insert({
|
|
65
|
+
type_id: typeId.id,
|
|
66
|
+
title: `${action_type} - ${action_value}`,
|
|
67
|
+
account_id: ctx.accountId,
|
|
68
|
+
data: signalData
|
|
69
|
+
})
|
|
70
|
+
.select('id')
|
|
71
|
+
.single()
|
|
47
72
|
|
|
48
|
-
if (
|
|
49
|
-
const err: any = new Error(
|
|
50
|
-
err.statusCode =
|
|
73
|
+
if (error || !signal) {
|
|
74
|
+
const err: any = new Error(`Failed to create signal: ${error?.message || 'Unknown error'}`)
|
|
75
|
+
err.statusCode = 500
|
|
51
76
|
throw err
|
|
52
77
|
}
|
|
53
78
|
|
|
54
|
-
return { status: 'ok', signal_id:
|
|
79
|
+
return { status: 'ok', signal_id: signal.id }
|
|
55
80
|
})
|