mirror of
https://github.com/pockethost/pockethost.git
synced 2026-03-12 19:48:23 +00:00
add auditing to welcome message
This commit is contained in:
@@ -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')
|
||||
|
||||
3
src/mothership-app/pb_hooks/types/lib.d.ts
vendored
3
src/mothership-app/pb_hooks/types/lib.d.ts
vendored
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user