@@ -2,7 +2,7 @@ import config from 'config';
22import { v4 as uuidv4 } from 'uuid' ;
33
44import { findPriorityPermitTracking } from './peach.ts' ;
5- import { PermitStage } from '../db/utils/codeEnums .ts' ;
5+ import { PermitStage } from '../db/codes/enums .ts' ;
66import { transactionWrapper } from '../db/utils/transactionWrapper.ts' ;
77import { generateCreateStamps , generateUpdateStamps } from '../db/utils/utils.ts' ;
88import { summarizePeachRecord } from '../parsers/peach.ts' ;
@@ -44,6 +44,20 @@ import type {
4444 SearchPermitsOptions ,
4545 SourceSystemKind
4646} from '../types/index.ts' ;
47+ import { codeTable } from '../db/codes/cache.ts' ;
48+
49+ function checkIfPeachIntegratedAuthType ( sourceSystem : string , sourceSystemKinds : SourceSystemKind [ ] ) : boolean {
50+ const sourceSystemKind = sourceSystemKinds . find ( ( ssk ) => ssk . integrated && ssk . sourceSystem === sourceSystem ) ;
51+ return ! ! sourceSystemKind ;
52+ }
53+
54+ const snapshotPermitStatus = ( p : Partial < Permit > ) => ( {
55+ state : p . state ,
56+ stage : p . stage ,
57+ decisionDate : p . decisionDate ,
58+ submittedDate : p . submittedDate ,
59+ statusLastChanged : p . statusLastChanged
60+ } ) ;
4761
4862export const deletePermitController = async ( req : Request < { permitId : string } > , res : Response ) => {
4963 await transactionWrapper < void > ( async ( tx : PrismaTransactionClient ) => {
@@ -187,18 +201,26 @@ export const sendPermitUpdateNotifications = async (
187201 } ) ;
188202 }
189203
204+ const stateDisplay = codeTable . PermitState . displays [ permit . state ] ;
205+ const stageDisplay = codeTable . PermitStage . displays [ permit . stage ] ;
206+
207+ if ( ! stateDisplay || ! stageDisplay ) {
208+ throw new Error ( `Invalid permit.state: ${ permit . state } or permit.stage: ${ permit . stage } ` ) ;
209+ }
210+
190211 // Create update note for status change
191212 const permitNote = await createPermitNote ( tx , {
192213 permitNoteId : uuidv4 ( ) ,
193214 permitId : permit . permitId ,
194215 note :
195- note ?? `This application is ${ permit . state . toLocaleLowerCase ( ) } in the ${ permit . stage . toLocaleLowerCase ( ) } .` ,
216+ note ?? `This application is ${ stateDisplay . toLocaleLowerCase ( ) } in the ${ stageDisplay . toLocaleLowerCase ( ) } .` ,
196217 ...generateCreateStamps ( undefined ) ,
197218 updatedBy : null ,
198219 updatedAt : null ,
199220 deletedBy : null ,
200221 deletedAt : null
201222 } ) ;
223+
202224 // Add proponent update email to email jobs
203225 const primaryContact = project ?. activity ?. activityContact ?. find (
204226 ( ac ) => ac . role === ActivityContactRole . PRIMARY
@@ -210,7 +232,7 @@ export const sendPermitUpdateNotifications = async (
210232 const isOnlyTemplate = permitNote . note . trim ( ) === peachUpdateNotePlaceholder ;
211233 const isFirstNote = ! permit ?. permitNote ?. length ;
212234
213- const usePeachTemplate = isOnlyTemplate && isFirstNote && state . features . peach ;
235+ const useInitialPeachTemplate = isOnlyTemplate && isFirstNote && state . features . peach ;
214236
215237 if (
216238 project . projectId &&
@@ -223,7 +245,7 @@ export const sendPermitUpdateNotifications = async (
223245 dearName : primaryContact ?. firstName ?? '' ,
224246 projectId : project . projectId ,
225247 toEmails : [ primaryContact . email ] ,
226- emailTemplate : usePeachTemplate ? initialPeachPermitUpdateTemplate : permitNoteUpdateTemplate
248+ emailTemplate : useInitialPeachTemplate ? initialPeachPermitUpdateTemplate : permitNoteUpdateTemplate
227249 } ) ;
228250 }
229251 } ;
@@ -240,19 +262,6 @@ export const sendPermitUpdateNotifications = async (
240262 }
241263} ;
242264
243- function checkIfPeachIntegratedAuthType ( sourceSystem : string , sourceSystemKinds : SourceSystemKind [ ] ) : boolean {
244- const sourceSystemKind = sourceSystemKinds . find ( ( ssk ) => ssk . integrated && ssk . sourceSystem === sourceSystem ) ;
245- return ! ! sourceSystemKind ;
246- }
247-
248- const snapshotPermitStatus = ( p : Partial < Permit > ) => ( {
249- state : p . state ,
250- stage : p . stage ,
251- decisionDate : p . decisionDate ,
252- submittedDate : p . submittedDate ,
253- statusLastChanged : p . statusLastChanged
254- } ) ;
255-
256265export const upsertPermitController = async ( req : Request < never , never , Permit > , res : Response ) => {
257266 const response = await transactionWrapper < Permit > ( async ( tx : PrismaTransactionClient ) => {
258267 const createStamps = generateCreateStamps ( req . currentContext ) ;
0 commit comments