rename all db columns

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-04-08 21:25:32 +02:00
parent 95b93b5f3a
commit 097ea18320
30 changed files with 303 additions and 232 deletions

View File

@@ -1,38 +1,20 @@
import type { Client } from '../prisma-client';
import type { Client, Prisma } from '../prisma-client';
import { db } from '../prisma-client';
import { transformProject } from './project.service';
import type { IServiceProject } from './project.service';
export type IServiceClient = ReturnType<typeof transformClient>;
export type IServiceClientWithProject = IServiceClient & {
project: Exclude<IServiceProject, null>;
};
export function transformClient({ organization_slug, ...client }: Client) {
return {
...client,
organizationSlug: organization_slug,
export type IServiceClient = Client;
export type IServiceClientWithProject = Prisma.ClientGetPayload<{
include: {
project: true;
};
}
}>;
export async function getClientsByOrganizationId(organizationId: string) {
const clients = await db.client.findMany({
return db.client.findMany({
where: {
organization_slug: organizationId,
organizationSlug: organizationId,
},
include: {
project: true,
},
});
return clients
.map((client) => {
return {
...transformClient(client),
project: transformProject(client.project),
};
})
.filter(
(client): client is IServiceClientWithProject => client.project !== null
);
}