28 lines
1,000 B
TypeScript
28 lines
1,000 B
TypeScript
import { eq } from "drizzle-orm";
|
|
import type { ExternalCsvConfigurationReader } from "../../domain/ports/external-csv-configuration.reader.js";
|
|
import type { AppDatabase } from "../database-context.js";
|
|
import { externalCsvConfigurations } from "../schema/external-csv-configurations.js";
|
|
import { projects } from "../schema/projects.js";
|
|
|
|
export class ExternalCsvConfigurationRepository
|
|
implements ExternalCsvConfigurationReader
|
|
{
|
|
constructor(private readonly database: AppDatabase) {}
|
|
|
|
getByProject(projectId: string) {
|
|
const project = this.database
|
|
.select({ id: projects.id })
|
|
.from(projects)
|
|
.where(eq(projects.id, projectId))
|
|
.get();
|
|
if (!project) {
|
|
return { projectExists: false, configuration: null };
|
|
}
|
|
const configuration = this.database
|
|
.select()
|
|
.from(externalCsvConfigurations)
|
|
.where(eq(externalCsvConfigurations.projectId, projectId))
|
|
.get() ?? null;
|
|
return { projectExists: true, configuration };
|
|
}
|
|
}
|