Initial push of Plunk Next

This commit is contained in:
Dries Augustyns
2025-12-01 09:56:56 +01:00
parent 07cea20262
commit ff1876d580
566 changed files with 89036 additions and 28423 deletions
+94
View File
@@ -0,0 +1,94 @@
import {Controller, Get, Middleware, Post} from '@overnightjs/core';
import type {Request, Response} from 'express';
import type {AuthResponse} from '../middleware/auth.js';
import {requireAuth} from '../middleware/auth.js';
import {EventService} from '../services/EventService.js';
@Controller('events')
export class Events {
/**
* POST /events/track
* Track a custom event (can trigger workflows)
*/
@Post('track')
@Middleware([requireAuth])
public async track(req: Request, res: Response) {
const auth = res.locals.auth as AuthResponse;
const {name, contactId, emailId, data} = req.body;
if (!name) {
return res.status(400).json({error: 'Event name is required'});
}
const event = await EventService.trackEvent(auth.projectId!, name, contactId, emailId, data);
return res.status(201).json(event);
}
/**
* GET /events
* List events for the project
*/
@Get('')
@Middleware([requireAuth])
public async list(req: Request, res: Response) {
const auth = res.locals.auth as AuthResponse;
const eventName = req.query.eventName as string | undefined;
const limit = parseInt(req.query.limit as string) || 100;
const events = await EventService.getProjectEvents(auth.projectId!, eventName, limit);
return res.status(200).json({events});
}
/**
* GET /events/stats
* Get event statistics
*/
@Get('stats')
@Middleware([requireAuth])
public async stats(req: Request, res: Response) {
const auth = res.locals.auth as AuthResponse;
const startDate = req.query.startDate ? new Date(req.query.startDate as string) : undefined;
const endDate = req.query.endDate ? new Date(req.query.endDate as string) : undefined;
const stats = await EventService.getEventStats(auth.projectId!, startDate, endDate);
return res.status(200).json(stats);
}
/**
* GET /events/contact/:contactId
* Get events for a specific contact
*/
@Get('contact/:contactId')
@Middleware([requireAuth])
public async getContactEvents(req: Request, res: Response) {
const auth = res.locals.auth as AuthResponse;
const contactId = req.params.contactId;
const limit = parseInt(req.query.limit as string) || 50;
if (!contactId) {
return res.status(400).json({error: 'Contact ID is required'});
}
const events = await EventService.getContactEvents(auth.projectId!, contactId, limit);
return res.status(200).json({events});
}
/**
* GET /events/names
* Get unique event names for the project
*/
@Get('names')
@Middleware([requireAuth])
public async getEventNames(req: Request, res: Response) {
const auth = res.locals.auth as AuthResponse;
const eventNames = await EventService.getUniqueEventNames(auth.projectId!);
return res.status(200).json({eventNames});
}
}