Added power sum per distributionboard
This commit is contained in:
@@ -2,7 +2,10 @@ 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";
|
||||
import type {
|
||||
CreateConsumerInput,
|
||||
UpdateConsumerInput,
|
||||
} from "../../shared/validation/consumer.schemas.js";
|
||||
|
||||
export class ConsumerRepository {
|
||||
async listByProject(projectId: string) {
|
||||
@@ -27,5 +30,32 @@ export class ConsumerRepository {
|
||||
});
|
||||
return { id, ...input };
|
||||
}
|
||||
}
|
||||
|
||||
async update(consumerId: string, input: UpdateConsumerInput) {
|
||||
await db
|
||||
.update(consumers)
|
||||
.set({
|
||||
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,
|
||||
})
|
||||
.where(eq(consumers.id, consumerId));
|
||||
}
|
||||
|
||||
async findById(consumerId: string) {
|
||||
const [row] = await db.select().from(consumers).where(eq(consumers.id, consumerId)).limit(1);
|
||||
return row ?? null;
|
||||
}
|
||||
|
||||
async delete(consumerId: string) {
|
||||
await db.delete(consumers).where(eq(consumers.id, consumerId));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user