Track HiveGrid Cloud planning reference

This commit is contained in:
david committed 2026-06-26 20:48:01 +02:00
1 parent b3d5ea6764
commit e341c5938a
5784 files changed
+1104929 -3

No files matched your search

@@ -0,0 +1,70 @@
import { db } from "~/utils/db.server";
export async function getEntityTemplates(entityId: string, { tenantId }: { tenantId: string | null }) {
return await db.entityTemplate.findMany({
where: { entityId, tenantId },
orderBy: { entity: { order: "asc" } },
});
}
type EntityTemplateScope = {
id: string;
tenantId: string | null;
entityId: string;
};
export async function getEntityTemplate(id: string, { tenantId, entityId }: { tenantId: string | null; entityId?: string }) {
return await db.entityTemplate
.findFirstOrThrow({
where: { id, tenantId, ...(entityId ? { entityId } : {}) },
})
.catch(() => {
return null;
});
}
export async function createEntityTemplate(data: { tenantId: string | null; entityId: string; title: string; config: string }) {
return await db.entityTemplate.create({
data: {
tenantId: data.tenantId,
entityId: data.entityId,
title: data.title,
config: data.config,
},
});
}
export async function updateEntityTemplate(id: string, data: { title: string; config: string }) {
return await db.entityTemplate.update({
where: {
id,
},
data,
});
}
export async function updateScopedEntityTemplate(scope: EntityTemplateScope, data: { title: string; config: string }) {
const result = await db.entityTemplate.updateMany({
where: scope,
data,
});
if (result.count !== 1) {
throw Error("Entity template not found");
}
return await getEntityTemplate(scope.id, { tenantId: scope.tenantId, entityId: scope.entityId });
}
export async function deleteEntityTemplate(id: string) {
return await db.entityTemplate.delete({
where: { id },
});
}
export async function deleteScopedEntityTemplate(scope: EntityTemplateScope) {
const result = await db.entityTemplate.deleteMany({
where: scope,
});
if (result.count !== 1) {
throw Error("Entity template not found");
}
}