* fix: how we fetch profiles in the buffer * perf: optimize event buffer * remove unused file * fix * wip * wip: try groupmq 2 * try simplified event buffer with duration calculation on the fly instead
38 lines
802 B
TypeScript
38 lines
802 B
TypeScript
import { cacheable } from '@openpanel/redis';
|
|
import type { Client, Prisma } from '../prisma-client';
|
|
import { db } from '../prisma-client';
|
|
|
|
export type IServiceClient = Client;
|
|
export type IServiceClientWithProject = Prisma.ClientGetPayload<{
|
|
include: {
|
|
project: true;
|
|
};
|
|
}>;
|
|
|
|
export async function getClientsByOrganizationId(organizationId: string) {
|
|
return db.client.findMany({
|
|
where: {
|
|
organizationId,
|
|
},
|
|
include: {
|
|
project: true,
|
|
},
|
|
orderBy: {
|
|
createdAt: 'asc',
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function getClientById(
|
|
id: string,
|
|
): Promise<IServiceClientWithProject | null> {
|
|
return db.client.findUnique({
|
|
where: { id },
|
|
include: {
|
|
project: true,
|
|
},
|
|
});
|
|
}
|
|
|
|
export const getClientByIdCached = cacheable(getClientById, 60 * 5);
|