@@ -17,7 +17,7 @@ import internalAuth from '../../middleware/internalAuth.js';
1717import getUser from '../../middleware/user.js' ;
1818import { CertificationModel } from '../../models/certification.js' ;
1919import { ControllerHoursModel } from '../../models/controllerHours.js' ;
20- import { DossierModel } from '../../models/dossier.js' ;
20+ import { ACTION_TYPE , DossierModel } from '../../models/dossier.js' ;
2121import { RoleModel } from '../../models/role.js' ;
2222import { UserModel , type IUser } from '../../models/user.js' ;
2323import status from '../../types/status.js' ;
@@ -204,10 +204,17 @@ router.get('/oi', async (_req: Request, res: Response, next: NextFunction) => {
204204router . get ( '/log' , getUser , isStaff , async ( req : Request , res : Response , next : NextFunction ) => {
205205 const page = + ( req . query [ 'page' ] as string ) || 1 ;
206206 const limit = + ( req . query [ 'limit' ] as string ) || 20 ;
207- const amount = await DossierModel . countDocuments ( ) . cache ( '5 minutes' ) . exec ( ) ;
207+ const action = + ( req . query [ 'action' ] as string ) ;
208+
209+ const actionQuery = { } as any ;
210+ if ( ! isNaN ( action ) && action > 0 ) {
211+ actionQuery . actionType = action ;
212+ }
213+
214+ const amount = await DossierModel . countDocuments ( actionQuery ) . cache ( '5 minutes' ) . exec ( ) ;
208215
209216 try {
210- const dossier = await DossierModel . find ( )
217+ const dossier = await DossierModel . find ( actionQuery )
211218 . sort ( {
212219 createdAt : 'desc' ,
213220 } )
@@ -228,6 +235,67 @@ router.get('/log', getUser, isStaff, async (req: Request, res: Response, next: N
228235 }
229236} ) ;
230237
238+ router . get (
239+ '/log/types' ,
240+ getUser ,
241+ isStaff ,
242+ async ( _req : Request , res : Response , next : NextFunction ) => {
243+ try {
244+ return res
245+ . status ( status . OK )
246+ . json ( [
247+ 'All Actions' ,
248+ 'Created User' ,
249+ 'Updated User' ,
250+ 'Removed User' ,
251+ 'Updated Bio' ,
252+ 'Set Membership' ,
253+ 'Set Visit Status' ,
254+ 'Created LOA' ,
255+ 'Removed LOA' ,
256+ 'Set Rating' ,
257+ 'Approved Visit Application' ,
258+ 'Rejected Visit Application' ,
259+ 'Created Event Signup' ,
260+ 'Deleted Event Signup' ,
261+ 'Created Manual Event Signup' ,
262+ 'Deleted Manual Event Signup' ,
263+ 'Assigned Event Position' ,
264+ 'Unassigned Event Position' ,
265+ 'Created Event' ,
266+ 'Updated Event' ,
267+ 'Deleted Event' ,
268+ 'Sent Notification for Event' ,
269+ 'Approved Staffing Request' ,
270+ 'Rejected Staffing Request' ,
271+ 'Submitted Feedback' ,
272+ 'Approved Feedback' ,
273+ 'Rejected Feedback' ,
274+ 'Created Document' ,
275+ 'Updated Document' ,
276+ 'Deleted Document' ,
277+ 'Created File' ,
278+ 'Updated File' ,
279+ 'Deleted File' ,
280+ 'Created News' ,
281+ 'Updated News' ,
282+ 'Deleted News' ,
283+ 'Issued Solo Endorsement' ,
284+ 'Extended Solo Endorsement' ,
285+ 'Deleted Solo Endorsement' ,
286+ 'Generated IDS Token' ,
287+ 'Connected Discord' ,
288+ 'Disconnect Discord' ,
289+ ] ) ;
290+ } catch ( e ) {
291+ if ( ! ( e as any ) . code ) {
292+ captureException ( e ) ;
293+ }
294+ return next ( e ) ;
295+ }
296+ } ,
297+ ) ;
298+
231299router . get ( '/:cid' , userOrInternal , async ( req : Request , res : Response , next : NextFunction ) => {
232300 try {
233301 if (
@@ -320,6 +388,7 @@ router.patch(
320388 by : - 1 ,
321389 affected : req . params [ 'cid' ] ,
322390 action : `%a was set as Rating ${ req . body . rating } by an external service.` ,
391+ actionType : ACTION_TYPE . SET_RATING ,
323392 } ) ;
324393 }
325394
@@ -509,6 +578,7 @@ router.post('/:cid', internalAuth, async (req: Request, res: Response, next: Nex
509578 by : - 1 ,
510579 affected : req . body . cid ,
511580 action : `%a was created by an external service.` ,
581+ actionType : ACTION_TYPE . CREATE_USER ,
512582 } ) ;
513583
514584 return res . status ( status . CREATED ) . json ( ) ;
@@ -602,6 +672,7 @@ router.patch(
602672 by : - 1 ,
603673 affected : req . params [ 'cid' ] ,
604674 action : `%a was ${ req . body . member ? 'added to' : 'removed from' } the roster by an external service.` ,
675+ actionType : ACTION_TYPE . SET_MEMBERSHIP ,
605676 } ) ;
606677
607678 return res . status ( status . OK ) . json ( ) ;
@@ -667,6 +738,7 @@ router.patch(
667738 by : - 1 ,
668739 affected : req . params [ 'cid' ] ,
669740 action : `%a was set as a ${ req . body . vis ? 'visiting controller' : 'home controller' } by an external service.` ,
741+ actionType : ACTION_TYPE . SET_VISIT_STATUS ,
670742 } ) ;
671743
672744 return res . status ( status . OK ) . json ( ) ;
@@ -766,6 +838,7 @@ router.put(
766838 by : req . user . cid ,
767839 affected : req . params [ 'cid' ] ,
768840 action : `%a was updated by %b.` ,
841+ actionType : ACTION_TYPE . UPDATE_USER ,
769842 } ) ;
770843
771844 return res . status ( status . OK ) . json ( ) ;
@@ -892,6 +965,7 @@ router.delete(
892965 by : req . user . cid ,
893966 affected : req . params [ 'cid' ] ,
894967 action : `%a was removed from the roster by %b, reason: ${ req . body . reason } ` ,
968+ actionType : ACTION_TYPE . DELETE_USER ,
895969 } ) ;
896970
897971 return res . status ( status . NO_CONTENT ) . json ( ) ;
0 commit comments