@@ -30,6 +30,8 @@ import {
3030 deleteCacheCounter ,
3131 getCacheCounter ,
3232} from "api/functions/cache.js" ;
33+ import { createAuditLogEntry } from "api/functions/auditLog.js" ;
34+ import { Modules } from "common/modules.js" ;
3335
3436const repeatOptions = [ "weekly" , "biweekly" ] as const ;
3537export const CLIENT_HTTP_CACHE_POLICY = `public, max-age=${ EVENT_CACHED_DURATION } , stale-while-revalidate=420, stale-if-error=3600` ;
@@ -266,6 +268,10 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
266268 }
267269 originalEvent = unmarshall ( originalEvent ) ;
268270 }
271+ let verb = "created" ;
272+ if ( userProvidedId && userProvidedId === entryUUID ) {
273+ verb = "modified" ;
274+ }
269275 const entry = {
270276 ...request . body ,
271277 id : entryUUID ,
@@ -281,10 +287,6 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
281287 Item : marshall ( entry ) ,
282288 } ) ,
283289 ) ;
284- let verb = "created" ;
285- if ( userProvidedId && userProvidedId === entryUUID ) {
286- verb = "modified" ;
287- }
288290 try {
289291 if ( request . body . featured && ! request . body . repeats ) {
290292 await updateDiscord (
@@ -332,19 +334,20 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
332334 1 ,
333335 false ,
334336 ) ;
337+ await createAuditLogEntry ( {
338+ dynamoClient : fastify . dynamoClient ,
339+ entry : {
340+ module : Modules . EVENTS ,
341+ actor : request . username ,
342+ target : entryUUID ,
343+ message : `${ verb } event "${ entryUUID } "` ,
344+ requestId : request . id ,
345+ } ,
346+ } ) ;
335347 reply . status ( 201 ) . send ( {
336348 id : entryUUID ,
337349 resource : `/api/v1/events/${ entryUUID } ` ,
338350 } ) ;
339- request . log . info (
340- {
341- type : "audit" ,
342- module : "events" ,
343- actor : request . username ,
344- target : entryUUID ,
345- } ,
346- `${ verb } event "${ entryUUID } "` ,
347- ) ;
348351 } catch ( e : unknown ) {
349352 if ( e instanceof Error ) {
350353 request . log . error ( "Failed to insert to DynamoDB: " + e . toString ( ) ) ;
@@ -391,6 +394,16 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
391394 id,
392395 resource : `/api/v1/events/${ id } ` ,
393396 } ) ;
397+ await createAuditLogEntry ( {
398+ dynamoClient : fastify . dynamoClient ,
399+ entry : {
400+ module : Modules . EVENTS ,
401+ actor : request . username ,
402+ target : id ,
403+ message : `Deleted event "${ id } "` ,
404+ requestId : request . id ,
405+ } ,
406+ } ) ;
394407 } catch ( e : unknown ) {
395408 if ( e instanceof Error ) {
396409 request . log . error ( "Failed to delete from DynamoDB: " + e . toString ( ) ) ;
@@ -406,15 +419,6 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
406419 1 ,
407420 false ,
408421 ) ;
409- request . log . info (
410- {
411- type : "audit" ,
412- module : "events" ,
413- actor : request . username ,
414- target : id ,
415- } ,
416- `deleted event "${ id } "` ,
417- ) ;
418422 } ,
419423 ) ;
420424 fastify . get < EventGetRequest > (
0 commit comments