@@ -12,7 +12,7 @@ export async function syncRetryableToNotion(
1212 ChildTx,
1313 ParentTx,
1414 createdAt,
15- status = 'Untriaged' ,
15+ status,
1616 priority = 'Unset' ,
1717 metadata,
1818 } = input
@@ -31,32 +31,21 @@ export async function syncRetryableToNotion(
3131 const isRetryableFoundInNotion = search . results . length > 0
3232
3333 const rawCreatedAt = metadata ?. createdAt ?? createdAt
34+ const createdAtMs =
35+ rawCreatedAt > 1e14
36+ ? Math . floor ( rawCreatedAt / 1000 )
37+ : rawCreatedAt > 1e12
38+ ? rawCreatedAt
39+ : rawCreatedAt > 1e10
40+ ? rawCreatedAt
41+ : rawCreatedAt * 1000
3442
35- // Normalize to milliseconds (ms) — only if needed
36- let createdAtMs : number
37-
38- if ( rawCreatedAt > 1e14 ) {
39- // Too big: microseconds → convert to ms
40- createdAtMs = Math . floor ( rawCreatedAt / 1000 )
41- } else if ( rawCreatedAt > 1e12 ) {
42- // Still too big: milliseconds → use as-is
43- createdAtMs = rawCreatedAt
44- } else if ( rawCreatedAt > 1e10 ) {
45-
46- createdAtMs = rawCreatedAt
47- } else {
48- // Normal seconds → convert to ms
49- createdAtMs = rawCreatedAt * 1000
50- }
5143 const notionProps : Record < string , any > = {
5244 ParentTx : { rich_text : [ { text : { content : ParentTx } } ] } ,
53- CreatedAt : {
54- date : {
55- start : new Date ( createdAtMs ) . toISOString ( ) ,
56- } ,
57- } ,
45+ CreatedAt : { date : { start : new Date ( createdAtMs ) . toISOString ( ) } } ,
5846 Priority : { select : { name : priority } } ,
5947 }
48+
6049 if ( input . timeout ) {
6150 notionProps [ 'timeoutTimestamp' ] = {
6251 date : { start : new Date ( input . timeout ) . toISOString ( ) } ,
@@ -68,9 +57,7 @@ export async function syncRetryableToNotion(
6857 rich_text : [ { text : { content : metadata . gasPriceProvided } } ] ,
6958 }
7059 notionProps [ 'GasPriceAtCreation' ] = {
71- rich_text : [
72- { text : { content : metadata . gasPriceAtCreation ?? 'N/A' } } ,
73- ] ,
60+ rich_text : [ { text : { content : metadata . gasPriceAtCreation ?? 'N/A' } } ] ,
7461 }
7562 notionProps [ 'GasPriceNow' ] = {
7663 rich_text : [ { text : { content : metadata . gasPriceNow } } ] ,
@@ -97,38 +84,50 @@ export async function syncRetryableToNotion(
9784
9885 const props = ( page as PageObjectResponse ) . properties
9986 const statusProp = props ?. Status
100-
101- let currentStatus : string | undefined = undefined
102- if ( statusProp && statusProp . type === 'select' && statusProp . select ) {
103- currentStatus = statusProp . select . name
104- }
105-
106- if ( status === 'Resolved' ) {
107- const resolvedProps : Record < string , any > = {
108- Status : { select : { name : 'Resolved' } } ,
87+ const decisionProp = props ?. Decision
88+
89+ const currentStatus =
90+ statusProp ?. type === 'select' && statusProp . select
91+ ? statusProp . select . name
92+ : undefined
93+ const currentDecision =
94+ decisionProp ?. type === 'select' && decisionProp . select
95+ ? decisionProp . select . name
96+ : undefined
97+
98+ // ✅ Handle Executed updates
99+ if ( status === 'Executed' ) {
100+ const executedProps : Record < string , any > = {
101+ Status : { select : { name : 'Executed' } } ,
109102 }
110103
111104 if ( input . timeout ) {
112- resolvedProps [ 'timeoutTimestamp' ] = {
105+ executedProps [ 'timeoutTimestamp' ] = {
113106 date : { start : new Date ( input . timeout ) . toISOString ( ) } ,
114107 }
115108 }
116109
117- return await notionClient . pages
118- . update ( {
119- page_id : page . id ,
120- properties : resolvedProps ,
121- } )
122- . then ( ( ) => ( {
123- id : page . id ,
124- status : 'Resolved' ,
125- isNew : false ,
126- } ) )
110+ if ( ! currentDecision && metadata ?. decision ) {
111+ executedProps [ 'Decision' ] = {
112+ select : { name : metadata . decision } ,
113+ }
114+ }
115+
116+ await notionClient . pages . update ( {
117+ page_id : page . id ,
118+ properties : executedProps ,
119+ } )
120+
121+ return { id : page . id , status : 'Executed' , isNew : false }
127122 }
128123
129- // Only overwrite status if still Untriaged or missing
130- if ( currentStatus === 'Untriaged' || ! currentStatus ) {
131- notionProps [ 'Status' ] = { select : { name : status } }
124+ notionProps [ 'Status' ] = { select : { name : status } }
125+
126+ // Only set Decision if it's missing
127+ if ( ! currentDecision && metadata ?. decision ) {
128+ notionProps [ 'Decision' ] = {
129+ select : { name : metadata . decision } ,
130+ }
132131 }
133132
134133 await notionClient . pages . update ( {
@@ -139,17 +138,17 @@ export async function syncRetryableToNotion(
139138 return { id : page . id , status : currentStatus ?? status , isNew : false }
140139 }
141140
142- if ( ! isRetryableFoundInNotion && status === 'Resolved' ) {
143- // Resolved but not found—skip
141+ // If not found and Executed, skip creation
142+ if ( ! isRetryableFoundInNotion && status === 'Executed' ) {
144143 return undefined
145144 }
146145
147- // Retryable is new and unresolved—create full entry
148146 const created = await notionClient . pages . create ( {
149147 parent : { database_id : databaseId } ,
150148 properties : {
151149 ChildTx : { title : [ { text : { content : ChildTx } } ] } ,
152150 Status : { select : { name : status } } ,
151+ ...( metadata ?. decision ? { Decision : { select : { name : metadata . decision } } } : { } ) ,
153152 ...notionProps ,
154153 } ,
155154 } )
0 commit comments