@@ -82,9 +82,9 @@ const OpportunityStageChange: Hook = {
8282/**
8383 * Handle Closed Won automation
8484 */
85- async function handleClosedWon ( ctx : any ) : Promise < void > {
85+ async function handleClosedWon ( ctx : HookContext ) : Promise < void > {
8686 console . log ( '✅ Processing Closed Won automation...' ) ;
87- const opportunity = ctx . result ;
87+ const opportunity = ctx . result as Record < string , any > ;
8888
8989 if ( ! opportunity . AccountId ) {
9090 console . error ( '❌ Cannot process: Opportunity has no AccountId' ) ;
@@ -96,7 +96,7 @@ async function handleClosedWon(ctx: any): Promise<void> {
9696 // 1. Create Contract
9797 let contractId ;
9898 try {
99- const contract = await ctx . ql . doc . create ( 'contract' , {
99+ const contract = await ( ctx . ql as any ) . doc . create ( 'contract' , {
100100 AccountId : opportunity . AccountId ,
101101 OpportunityId : opportunity . Id ,
102102 Status : 'draft' ,
@@ -118,7 +118,7 @@ async function handleClosedWon(ctx: any): Promise<void> {
118118
119119 // 2. Update Account Status
120120 try {
121- await ctx . ql . doc . update ( 'account' , opportunity . AccountId , {
121+ await ( ctx . ql as any ) . doc . update ( 'account' , opportunity . AccountId , {
122122 CustomerStatus : 'active_customer'
123123 } ) ;
124124 console . log ( '✅ Account status updated to Active Customer' ) ;
@@ -129,7 +129,7 @@ async function handleClosedWon(ctx: any): Promise<void> {
129129
130130 // 3. Log activity
131131 try {
132- await ctx . ql . doc . create ( 'activity' , {
132+ await ( ctx . ql as any ) . doc . create ( 'activity' , {
133133 Subject : `Deal Won: ${ opportunity . Name } ` ,
134134 Type : 'Milestone' ,
135135 Status : 'completed' ,
@@ -160,17 +160,17 @@ async function handleClosedWon(ctx: any): Promise<void> {
160160 }
161161}
162162
163- async function handleClosedLost ( ctx : any ) : Promise < void > {
163+ async function handleClosedLost ( ctx : HookContext ) : Promise < void > {
164164 console . log ( '❌ Processing Closed Lost automation...' ) ;
165- const opportunity = ctx . result ;
165+ const opportunity = ctx . result as Record < string , any > ;
166166
167167 if ( ! opportunity . AccountId ) {
168168 return ;
169169 }
170170
171171 // Log activity for lost opportunity
172172 try {
173- await ctx . ql . doc . create ( 'activity' , {
173+ await ( ctx . ql as any ) . doc . create ( 'activity' , {
174174 Subject : `Deal Lost: ${ opportunity . Name } ` ,
175175 Type : 'Milestone' ,
176176 Status : 'completed' ,
@@ -192,20 +192,20 @@ async function handleClosedLost(ctx: any): Promise<void> {
192192/**
193193 * Log activity when stage changes
194194 */
195- async function logStageChange ( ctx : any ) : Promise < void > {
195+ async function logStageChange ( ctx : HookContext ) : Promise < void > {
196196 try {
197- const opportunity = ctx . result ;
198- const oldStage = ctx . previous ?. Stage || 'unknown' ;
199- await ctx . ql . doc . create ( 'activity' , {
200- Subject : `Opportunity Stage Change: ${ oldStage } → ${ ctx . result . Stage } ` ,
197+ const opportunity = ctx . result as Record < string , any > ;
198+ const oldStage = ( ctx . previous as Record < string , any > ) ?. Stage || 'unknown' ;
199+ await ( ctx . ql as any ) . doc . create ( 'activity' , {
200+ Subject : `Opportunity Stage Change: ${ oldStage } → ${ ( ctx . result as Record < string , any > ) . Stage } ` ,
201201 Type : 'Stage Change' ,
202202 Status : 'completed' ,
203203 Priority : 'normal' ,
204204 AccountId : opportunity . AccountId ,
205205 WhatId : opportunity . Id ,
206206 OwnerId : ctx . user . id ,
207207 ActivityDate : new Date ( ) . toISOString ( ) . split ( 'T' ) [ 0 ] ,
208- Description : `Opportunity stage changed from "${ oldStage } " to "${ ctx . result . Stage } "`
208+ Description : `Opportunity stage changed from "${ oldStage } " to "${ ( ctx . result as Record < string , any > ) . Stage } "`
209209 } ) ;
210210 } catch ( error ) {
211211 console . error ( '❌ Failed to log stage change activity:' , error ) ;
@@ -215,8 +215,8 @@ async function logStageChange(ctx: any): Promise<void> {
215215/**
216216 * Validate required fields for advanced stages
217217 */
218- async function validateStageRequirements ( ctx : any ) : Promise < void > {
219- const opportunity = ctx . result ;
218+ async function validateStageRequirements ( ctx : HookContext ) : Promise < void > {
219+ const opportunity = ctx . result as Record < string , any > ;
220220 const stage = opportunity . Stage ;
221221 const warnings : string [ ] = [ ] ;
222222
@@ -252,13 +252,13 @@ async function validateStageRequirements(ctx: any): Promise<void> {
252252/**
253253 * Helper: Count related quotes
254254 */
255- async function countRelatedQuotes ( ctx : any , opportunityId : string ) : Promise < number > {
255+ async function countRelatedQuotes ( ctx : HookContext , opportunityId : string ) : Promise < number > {
256256 // Check if quote object exists first (it's in products package)
257257 try {
258258 // In a real monorepo with strict boundaries, we might use a decoupled service.
259259 // Here we assume the broker can find 'quote' across packages.
260260 // Mocking for now since we don't have the full runtime
261- const quotes = await ctx . ql . find ( 'quote' , {
261+ const quotes = await ( ctx . ql as any ) . find ( 'quote' , {
262262 filters : [ [ 'opportunity' , '=' , opportunityId ] ]
263263 } ) ;
264264 return quotes . length ;
0 commit comments