first commit
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import crypto from "node:crypto";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../client.js";
|
||||
import { consumers } from "../schema/consumers.js";
|
||||
import type { CreateConsumerInput } from "../../shared/validation/consumer.schemas.js";
|
||||
|
||||
export class ConsumerRepository {
|
||||
async listByProject(projectId: string) {
|
||||
return db.select().from(consumers).where(eq(consumers.projectId, projectId));
|
||||
}
|
||||
|
||||
async create(input: CreateConsumerInput) {
|
||||
const id = crypto.randomUUID();
|
||||
await db.insert(consumers).values({
|
||||
id,
|
||||
projectId: input.projectId,
|
||||
distributionBoardId: input.distributionBoardId ?? null,
|
||||
name: input.name,
|
||||
category: input.category ?? null,
|
||||
quantity: input.quantity,
|
||||
installedPowerPerUnitKw: input.installedPowerPerUnitKw,
|
||||
demandFactor: input.demandFactor,
|
||||
voltageV: input.voltageV ?? null,
|
||||
phaseCount: input.phaseCount ?? null,
|
||||
powerFactor: input.powerFactor ?? null,
|
||||
note: input.note ?? null,
|
||||
});
|
||||
return { id, ...input };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user