Skip to content

Commit

Permalink
bugFix on event deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
lluis-protofy-xyz committed Dec 5, 2024
1 parent f9b943d commit c0eb4cb
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/protolib/src/bundles/events/eventsAPI.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import { EventModel } from ".";
import { AutoAPI, getDBOptions } from 'protonode'
import { AutoAPI, getDBOptions, getServiceToken } from 'protonode'
import { connectDB, getDB } from '@my/config/dist/storageProviders';
import { API } from 'protobase'

export const EventsAPI = async (app, context) => {
const EventAPI = AutoAPI({
modelName: 'events',
modelType: EventModel,
prefix: '/api/core/v1/',
onAfterCreate: async (data, session, req) => {
const result = await API.get('/api/core/v1/events?itemsPerPage=1&orderBy=created&orderDirection=asc&token='+getServiceToken())
// console.log("result", result)
const maxEvents = process.env.MAX_EVENTS || 100000
if(result.data){
if(result.data.total >= maxEvents ){
const element = result.data.items[0]
// console.log("element", element)
const result2 = await API.get(`/api/core/v1/events/${element.id}/delete?token=${getServiceToken()}`)
// console.log("result2", result2)
}
}
return data
},
skipStorage: async(data,session?,req?) => {
if(data.ephemeral){
return true
Expand Down

0 comments on commit c0eb4cb

Please sign in to comment.