| 1028 | } |
| 1029 | |
| 1030 | async getById({ |
| 1031 | projectId, |
| 1032 | id, |
| 1033 | createdAt, |
| 1034 | }: { |
| 1035 | projectId: string; |
| 1036 | id: string; |
| 1037 | createdAt?: Date; |
| 1038 | }) { |
| 1039 | const [event, metas] = await Promise.all([ |
| 1040 | clix(this.client) |
| 1041 | .select<IClickhouseEvent>(['*']) |
| 1042 | .from('events') |
| 1043 | .where('project_id', '=', projectId) |
| 1044 | .when(!!createdAt, (q) => { |
| 1045 | if (createdAt) { |
| 1046 | q.where('created_at', 'BETWEEN', [ |
| 1047 | new Date(createdAt.getTime() - 1000), |
| 1048 | new Date(createdAt.getTime() + 1000), |
| 1049 | ]); |
| 1050 | } |
| 1051 | }) |
| 1052 | .where('id', '=', id) |
| 1053 | .limit(1) |
| 1054 | .execute() |
| 1055 | .then((res) => { |
| 1056 | if (!res[0]) { |
| 1057 | return null; |
| 1058 | } |
| 1059 | |
| 1060 | return transformEvent(res[0]); |
| 1061 | }), |
| 1062 | getEventMetasCached(projectId), |
| 1063 | ]); |
| 1064 | |
| 1065 | if (event?.profileId) { |
| 1066 | const profile = await getProfileById(event?.profileId, projectId); |
| 1067 | if (profile) { |
| 1068 | event.profile = profile; |
| 1069 | } |
| 1070 | } |
| 1071 | |
| 1072 | if (event) { |
| 1073 | event.meta = metas.find((meta) => meta.name === event.name); |
| 1074 | } |
| 1075 | |
| 1076 | return event; |
| 1077 | } |
| 1078 | |
| 1079 | async getList({ |
| 1080 | projectId, |