fix(api): filter events by profileId for export route
This commit is contained in:
@@ -65,6 +65,7 @@ async function getProjectId(
|
|||||||
const eventsScheme = z.object({
|
const eventsScheme = z.object({
|
||||||
project_id: z.string().optional(),
|
project_id: z.string().optional(),
|
||||||
projectId: z.string().optional(),
|
projectId: z.string().optional(),
|
||||||
|
profileId: z.string().optional(),
|
||||||
event: z.union([z.string(), z.array(z.string())]).optional(),
|
event: z.union([z.string(), z.array(z.string())]).optional(),
|
||||||
start: z.coerce.string().optional(),
|
start: z.coerce.string().optional(),
|
||||||
end: z.coerce.string().optional(),
|
end: z.coerce.string().optional(),
|
||||||
@@ -109,6 +110,7 @@ export async function events(
|
|||||||
endDate: query.data.end ? new Date(query.data.end) : undefined,
|
endDate: query.data.end ? new Date(query.data.end) : undefined,
|
||||||
cursor,
|
cursor,
|
||||||
take,
|
take,
|
||||||
|
profileId: query.data.profileId,
|
||||||
select: {
|
select: {
|
||||||
profile: false,
|
profile: false,
|
||||||
meta: false,
|
meta: false,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import type { FastifyPluginCallback, FastifyRequest } from 'fastify';
|
|||||||
const exportRouter: FastifyPluginCallback = async (fastify) => {
|
const exportRouter: FastifyPluginCallback = async (fastify) => {
|
||||||
await activateRateLimiter({
|
await activateRateLimiter({
|
||||||
fastify,
|
fastify,
|
||||||
max: 10,
|
max: 100,
|
||||||
timeWindow: '10 seconds',
|
timeWindow: '10 seconds',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -506,7 +506,7 @@ export async function getEventList({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (profileId) {
|
if (profileId) {
|
||||||
sb.where.deviceId = `(device_id IN (SELECT device_id as did FROM ${TABLE_NAMES.events} WHERE device_id != '' AND profile_id = ${escape(profileId)} group by did) OR profile_id = ${escape(profileId)})`;
|
sb.where.deviceId = `(device_id IN (SELECT device_id as did FROM ${TABLE_NAMES.events} WHERE project_id = ${escape(projectId)} AND device_id != '' AND profile_id = ${escape(profileId)} group by did) OR profile_id = ${escape(profileId)})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startDate && endDate) {
|
if (startDate && endDate) {
|
||||||
@@ -527,10 +527,6 @@ export async function getEventList({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (cursor) {
|
|
||||||
// sb.where.cursor = `created_at <= '${formatClickhouseDate(cursor)}'`;
|
|
||||||
// }
|
|
||||||
|
|
||||||
sb.orderBy.created_at =
|
sb.orderBy.created_at =
|
||||||
'toDate(created_at) DESC, created_at DESC, profile_id DESC, name DESC';
|
'toDate(created_at) DESC, created_at DESC, profile_id DESC, name DESC';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user