Automated event creation for submitted event requests#12
Conversation
dokicaaa
commented
May 8, 2026
- When a user submits a form it creates both an event request and event as a draft.
- Sets default status value to "pending"
- Links them together via ID
- If event gets published -> hook changes status to "approved" -> sends email to user that the event has been approved -> adds event to collection.
|
|
||
| import { factories } from '@strapi/strapi'; | ||
|
|
||
| export default factories.createCoreRouter('api::event-request.event-request'); |
There was a problem hiding this comment.
With this line removed, you are removing all of the default routes (find, findOne, update,..etc) from strapi for event-request. This means that you are overriding the default routes and only adding one route for the event-request content type.
Inside the cms folder, run npm run strapi routes:list and you will see :)
|
|
||
| const FIREBASE_FCM_CREDENTIALS_PATH = './base42-mobile-app-fcm-firebase-adminsdk.json'; | ||
|
|
||
| const eventRequestApprovalMiddleware = () => { |
There was a problem hiding this comment.
Export this middleware to a new file, the same way event-notifications is handled
| documentId: id, | ||
| populate: ['event' as any], | ||
| }); | ||
|
|
There was a problem hiding this comment.
We should also verify if the user is authorized for an additional check.
| if (!user) { | |
| return ctx.unauthorized(); | |
| } |
|
|
||
| const request: any = await strapi.documents('api::event-request.event-request').findOne({ | ||
| documentId: id, | ||
| populate: ['event' as any], |
There was a problem hiding this comment.
Is any needed here?
I think populate: ['event'] is enough
| async approve(ctx) { | ||
| const { id } = ctx.params; | ||
|
|
||
| const request: any = await strapi.documents('api::event-request.event-request').findOne({ |
There was a problem hiding this comment.
Try not to use any a lot, maybe define a type for the request. (& everywhere that can be changed)