From c0eb4cbadc718a75e3caf43b7747d043dcc3e470 Mon Sep 17 00:00:00 2001 From: "lluis@protofy.xyz" Date: Thu, 5 Dec 2024 09:28:21 +0100 Subject: [PATCH] bugFix on event deletion --- .../protolib/src/bundles/events/eventsAPI.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/protolib/src/bundles/events/eventsAPI.ts b/packages/protolib/src/bundles/events/eventsAPI.ts index 89e6ab86a..51fdd66d1 100644 --- a/packages/protolib/src/bundles/events/eventsAPI.ts +++ b/packages/protolib/src/bundles/events/eventsAPI.ts @@ -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