add event name to properties table

This commit is contained in:
Francis Cao 2024-08-14 12:29:47 -07:00
parent 04de691893
commit aaf9adacc6
5 changed files with 44 additions and 16 deletions

View file

@ -11,6 +11,7 @@ export interface EventDataFieldsRequestQuery {
websiteId: string;
startAt: string;
endAt: string;
eventName?: string;
propertyName?: string;
}
@ -19,6 +20,7 @@ const schema = {
websiteId: yup.string().uuid().required(),
startAt: yup.number().integer().required(),
endAt: yup.number().integer().min(yup.ref('startAt')).required(),
eventName: yup.string(),
propertyName: yup.string(),
}),
};
@ -32,7 +34,7 @@ export default async (
await useValidate(schema, req, res);
if (req.method === 'GET') {
const { websiteId, startAt, endAt, propertyName } = req.query;
const { websiteId, startAt, endAt, eventName, propertyName } = req.query;
if (!(await canViewWebsite(req.auth, websiteId))) {
return unauthorized(res);
@ -41,7 +43,12 @@ export default async (
const startDate = new Date(+startAt);
const endDate = new Date(+endAt);
const data = await getEventDataValues(websiteId, { startDate, endDate, propertyName });
const data = await getEventDataValues(websiteId, {
startDate,
endDate,
eventName,
propertyName,
});
return ok(res, data);
}