diff --git a/src/mothership-app/pb_hooks/src/user-welcome-msg.pb.js b/src/mothership-app/pb_hooks/src/user-welcome-msg.pb.js index 14421f5c..47b86de2 100644 --- a/src/mothership-app/pb_hooks/src/user-welcome-msg.pb.js +++ b/src/mothership-app/pb_hooks/src/user-welcome-msg.pb.js @@ -4,22 +4,28 @@ onModelBeforeUpdate((e) => { const newModel = /** @type {models.Record} */ (e.model) const oldModel = newModel.originalCopy() - const { mkLog, enqueueNotification } = /** @type {Lib} */ ( + const { audit, mkLog, enqueueNotification } = /** @type {Lib} */ ( require(`${__hooks}/lib.js`) ) const log = mkLog(`user-welcome-msg`) + try { + log({ newModel, oldModel }) - // Bail out if we aren't verified - const isVerified = newModel.getBool('verified') - if (!isVerified) return + // Bail out if we aren't verified + const isVerified = newModel.getBool('verified') + if (!isVerified) return - // Bail out if the verified mode flag has not changed - if (isVerified === oldModel.getBool(`verified`)) return + // Bail out if the verified mode flag has not changed + if (isVerified === oldModel.getBool(`verified`)) return - log(`user just became verified`) - const uid = newModel.getId() + log(`user just became verified`) + const uid = newModel.getId() - enqueueNotification(`email`, `welcome`, uid) - newModel.set(`welcome`, new DateTime()) + enqueueNotification(`email`, `welcome`, uid) + newModel.set(`welcome`, new DateTime()) + } catch (e) { + audit(`ERROR`, `${e}`) + throw e + } }, 'users') diff --git a/src/mothership-app/pb_hooks/types/lib.d.ts b/src/mothership-app/pb_hooks/types/lib.d.ts index f00c7bf0..d27330bc 100644 --- a/src/mothership-app/pb_hooks/types/lib.d.ts +++ b/src/mothership-app/pb_hooks/types/lib.d.ts @@ -3,6 +3,7 @@ type Logger = (...args: any[]) => void type StringKvLookup = { [_: string]: string } type AuditEvents = + | 'ERROR' | 'NOTIFICATION_ERR' | 'LS' | 'LS_ERR' @@ -17,7 +18,7 @@ interface Lib { mkLog: (namespace: string) => Logger processNotification: ( notificationRec: models.Record, - context: { log: Logger; test: boolean }, + context: { log: Logger; test?: boolean }, ) => void enqueueNotification: ( channel: 'email' | 'lemonbot',