rename IServiceCreateEventPayload

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-07-21 23:42:30 +02:00
committed by Carl-Gerhard Lindesvärd
parent 1b613538cc
commit 0fea45c9f7
13 changed files with 53 additions and 69 deletions

View File

@@ -8,7 +8,7 @@ import { ch, TABLE_NAMES } from '../clickhouse-client';
import { transformEvent } from '../services/event.service';
import type {
IClickhouseEvent,
IServiceCreateEventPayload,
IServiceEvent,
} from '../services/event.service';
import type {
Find,
@@ -187,22 +187,19 @@ export class EventBuffer extends RedisBuffer<IClickhouseEvent> {
];
};
public findMany: FindMany<IClickhouseEvent, IServiceCreateEventPayload> =
async (callback) => {
return this.getQueue(-1)
.then((queue) => {
return queue
.filter(callback)
.map((item) => transformEvent(item.event));
})
.catch(() => {
return [];
});
};
public find: Find<IClickhouseEvent, IServiceCreateEventPayload> = async (
public findMany: FindMany<IClickhouseEvent, IServiceEvent> = async (
callback
) => {
return this.getQueue(-1)
.then((queue) => {
return queue.filter(callback).map((item) => transformEvent(item.event));
})
.catch(() => {
return [];
});
};
public find: Find<IClickhouseEvent, IServiceEvent> = async (callback) => {
return this.getQueue(-1)
.then((queue) => {
const match = queue.find(callback);

View File

@@ -62,9 +62,7 @@ export interface IClickhouseEvent {
meta?: EventMeta;
}
export function transformEvent(
event: IClickhouseEvent
): IServiceCreateEventPayload {
export function transformEvent(event: IClickhouseEvent): IServiceEvent {
return {
id: event.id,
name: event.name,
@@ -98,7 +96,12 @@ export function transformEvent(
};
}
export interface IServiceCreateEventPayload {
export type IServiceCreateEventPayload = Omit<
IServiceEvent,
'id' | 'importedAt' | 'profile' | 'meta'
>;
export interface IServiceEvent {
id: string;
name: string;
deviceId: string;
@@ -169,7 +172,7 @@ function maskString(str: string, mask = '*') {
}
export function transformMinimalEvent(
event: IServiceCreateEventPayload
event: IServiceEvent
): IServiceEventMinimal {
return {
id: event.id,
@@ -201,7 +204,7 @@ export async function getLiveVisitors(projectId: string) {
export async function getEvents(
sql: string,
options: GetEventsOptions = {}
): Promise<IServiceCreateEventPayload[]> {
): Promise<IServiceEvent[]> {
const events = await chQuery<IClickhouseEvent>(sql);
if (options.profile) {
const ids = events.map((e) => e.profile_id);
@@ -230,12 +233,7 @@ export async function getEvents(
return events.map(transformEvent);
}
export async function createEvent(
payload: Omit<
IServiceCreateEventPayload,
'id' | 'importedAt' | 'profile' | 'meta'
>
) {
export async function createEvent(payload: IServiceCreateEventPayload) {
if (!payload.profileId) {
payload.profileId = payload.deviceId;
}