well deserved clean up (#1)
This commit is contained in:
@@ -1,14 +1,22 @@
|
||||
import type { Client } from '../prisma-client';
|
||||
import { db } from '../prisma-client';
|
||||
import { transformProject } from './project.service';
|
||||
import type { IServiceProject } from './project.service';
|
||||
|
||||
export type IServiceClient = Client;
|
||||
export type IServiceClientWithProject = Client & {
|
||||
export type IServiceClient = ReturnType<typeof transformClient>;
|
||||
export type IServiceClientWithProject = IServiceClient & {
|
||||
project: Exclude<IServiceProject, null>;
|
||||
};
|
||||
|
||||
export function getClientsByOrganizationId(organizationId: string) {
|
||||
return db.client.findMany({
|
||||
export function transformClient({ organization_slug, ...client }: Client) {
|
||||
return {
|
||||
...client,
|
||||
organizationSlug: organization_slug,
|
||||
};
|
||||
}
|
||||
|
||||
export async function getClientsByOrganizationId(organizationId: string) {
|
||||
const clients = await db.client.findMany({
|
||||
where: {
|
||||
organization_slug: organizationId,
|
||||
},
|
||||
@@ -16,4 +24,15 @@ export function getClientsByOrganizationId(organizationId: string) {
|
||||
project: true,
|
||||
},
|
||||
});
|
||||
|
||||
return clients
|
||||
.map((client) => {
|
||||
return {
|
||||
...transformClient(client),
|
||||
project: transformProject(client.project),
|
||||
};
|
||||
})
|
||||
.filter(
|
||||
(client): client is IServiceClientWithProject => client.project !== null
|
||||
);
|
||||
}
|
||||
|
||||
@@ -23,22 +23,6 @@ export async function getDashboardById(id: string, projectId: string) {
|
||||
return dashboard;
|
||||
}
|
||||
|
||||
export async function getDashboardsByOrganization(organizationSlug: string) {
|
||||
return db.dashboard.findMany({
|
||||
where: {
|
||||
organization_slug: organizationSlug,
|
||||
},
|
||||
include: {
|
||||
project: true,
|
||||
},
|
||||
orderBy: {
|
||||
reports: {
|
||||
_count: 'desc',
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function getDashboardsByProjectId(projectId: string) {
|
||||
return db.dashboard.findMany({
|
||||
where: {
|
||||
|
||||
@@ -12,7 +12,7 @@ export type IServiceOrganization = Awaited<
|
||||
|
||||
export type IServiceInvites = Awaited<ReturnType<typeof getInvites>>;
|
||||
|
||||
function transformOrganization(org: Organization) {
|
||||
export function transformOrganization(org: Organization) {
|
||||
return {
|
||||
id: org.id,
|
||||
name: org.name,
|
||||
|
||||
@@ -129,7 +129,7 @@ export async function getProfilesByExternalId(
|
||||
|
||||
export type IServiceProfile = Omit<
|
||||
IClickhouseProfile,
|
||||
'max_created_at' | 'properties'
|
||||
'max_created_at' | 'properties' | 'first_name' | 'last_name'
|
||||
> & {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
@@ -169,12 +169,14 @@ export interface IServiceUpsertProfile {
|
||||
|
||||
function transformProfile({
|
||||
max_created_at,
|
||||
first_name,
|
||||
last_name,
|
||||
...profile
|
||||
}: IClickhouseProfile): IServiceProfile {
|
||||
return {
|
||||
...profile,
|
||||
firstName: profile.first_name,
|
||||
lastName: profile.last_name,
|
||||
firstName: first_name,
|
||||
lastName: last_name,
|
||||
properties: toObject(profile.properties),
|
||||
createdAt: new Date(max_created_at),
|
||||
};
|
||||
@@ -216,3 +218,8 @@ export async function upsertProfile({
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
export function getProfileName(profile: IServiceProfile | undefined | null) {
|
||||
if (!profile) return 'No name';
|
||||
return [profile.firstName, profile.lastName].filter(Boolean).join(' ');
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { Project } from '../prisma-client';
|
||||
import { db } from '../prisma-client';
|
||||
|
||||
export type IServiceProject = ReturnType<typeof transform>;
|
||||
export type IServiceProject = ReturnType<typeof transformProject>;
|
||||
|
||||
function transform({ organization_slug, ...project }: Project) {
|
||||
export function transformProject({ organization_slug, ...project }: Project) {
|
||||
return {
|
||||
organizationSlug: organization_slug,
|
||||
...project,
|
||||
@@ -21,7 +21,7 @@ export async function getProjectById(id: string) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return transform(res);
|
||||
return transformProject(res);
|
||||
}
|
||||
|
||||
export async function getProjectsByOrganizationSlug(slug: string) {
|
||||
@@ -31,5 +31,5 @@ export async function getProjectsByOrganizationSlug(slug: string) {
|
||||
},
|
||||
});
|
||||
|
||||
return res.map(transform);
|
||||
return res.map(transformProject);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import type { Prisma, Reference } from '../prisma-client';
|
||||
import { db } from '../prisma-client';
|
||||
|
||||
// import type { Report as DbReport } from '../prisma-client';
|
||||
|
||||
export type IServiceReference = Omit<Reference, 'project_id'> & {
|
||||
projectId: string;
|
||||
};
|
||||
|
||||
export function transform({
|
||||
export function transformReference({
|
||||
project_id,
|
||||
...item
|
||||
}: Reference): IServiceReference {
|
||||
@@ -28,7 +26,7 @@ export async function getReferenceById(id: string) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return transform(reference);
|
||||
return transformReference(reference);
|
||||
}
|
||||
|
||||
export async function getReferences({
|
||||
@@ -46,5 +44,5 @@ export async function getReferences({
|
||||
skip,
|
||||
});
|
||||
|
||||
return references.map(transform);
|
||||
return references.map(transformReference);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user