well deserved clean up (#1)

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-03-18 21:53:07 +01:00
parent 3a8404f704
commit b7513f24d5
106 changed files with 453 additions and 1275 deletions

View File

@@ -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
);
}