Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+1
-1
@@ -2,7 +2,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const createUniqueTenantIpAddressRecord = vi.fn();
|
||||
|
||||
vi.mock("@toolctrl/db/auth-boundary.server", () => ({
|
||||
vi.mock("@hivegrid/db/auth-boundary.server", () => ({
|
||||
createUniqueTenantIpAddressRecord,
|
||||
}));
|
||||
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
import { createUniqueTenantIpAddressRecord } from "@toolctrl/db/auth-boundary.server";
|
||||
import { ApiKey, Tenant, TenantIpAddress } from "@toolctrl/db/prisma-browser";
|
||||
import { createUniqueTenantIpAddressRecord } from "@hivegrid/db/auth-boundary.server";
|
||||
import { ApiKey, Tenant, TenantIpAddress } from "@hivegrid/db/prisma-browser";
|
||||
import { db } from "~/utils/db.server";
|
||||
import { UserSimple } from "../users.db.server";
|
||||
import UserModelHelper from "~/utils/helpers/models/UserModelHelper";
|
||||
|
||||
+55
-26
@@ -1,5 +1,6 @@
|
||||
import { Prisma, SubscriptionProduct, TenantType } from "@toolctrl/db/prisma-browser";
|
||||
import { Prisma, SubscriptionProduct, TenantType } from "@hivegrid/db/prisma-browser";
|
||||
import { db } from "~/utils/db.server";
|
||||
import { cachified, clearCacheKey } from "~/utils/cache.server";
|
||||
|
||||
export type TenantTypeWithDetails = TenantType & {
|
||||
subscriptionProducts: SubscriptionProduct[];
|
||||
@@ -9,15 +10,28 @@ const includeDetails = {
|
||||
subscriptionProducts: true,
|
||||
_count: { select: { tenants: true } },
|
||||
};
|
||||
|
||||
// TenantTypes are a quasi-static, non-tenant-scoped table read on every authenticated app pageview
|
||||
// (loadAppData). The cache is invalidated on every tenant-type mutation below. NOTE: the embedded
|
||||
// `_count.tenants` also changes when tenants are created/deleted (outside this module's scope), so a
|
||||
// short TTL is used to keep that count from drifting more than a few minutes on the app overview.
|
||||
const TENANT_TYPES_CACHE_KEY = "tenantTypes:all";
|
||||
const TENANT_TYPES_CACHE_TTL = 1000 * 60 * 5; // 5min — bounded staleness for the embedded tenant count
|
||||
|
||||
export async function getAllTenantTypes(): Promise<TenantTypeWithDetails[]> {
|
||||
return await db.tenantType.findMany({
|
||||
include: {
|
||||
subscriptionProducts: true,
|
||||
_count: { select: { tenants: true } },
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "asc",
|
||||
},
|
||||
return await cachified({
|
||||
key: TENANT_TYPES_CACHE_KEY,
|
||||
ttl: TENANT_TYPES_CACHE_TTL,
|
||||
getFreshValue: () =>
|
||||
db.tenantType.findMany({
|
||||
include: {
|
||||
subscriptionProducts: true,
|
||||
_count: { select: { tenants: true } },
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "asc",
|
||||
},
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -63,17 +77,22 @@ export async function createTenantType(data: {
|
||||
isDefault?: boolean;
|
||||
subscriptionProducts: string[];
|
||||
}) {
|
||||
return await db.tenantType.create({
|
||||
data: {
|
||||
title: data.title,
|
||||
titlePlural: data.titlePlural,
|
||||
description: data.description,
|
||||
isDefault: data.isDefault,
|
||||
subscriptionProducts: {
|
||||
connect: data.subscriptionProducts.map((id) => ({ id })),
|
||||
return await db.tenantType
|
||||
.create({
|
||||
data: {
|
||||
title: data.title,
|
||||
titlePlural: data.titlePlural,
|
||||
description: data.description,
|
||||
isDefault: data.isDefault,
|
||||
subscriptionProducts: {
|
||||
connect: data.subscriptionProducts.map((id) => ({ id })),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((item) => {
|
||||
clearCacheKey(TENANT_TYPES_CACHE_KEY);
|
||||
return item;
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateTenantType(
|
||||
@@ -97,14 +116,24 @@ export async function updateTenantType(
|
||||
set: data.subscriptionProducts.map((id) => ({ id })),
|
||||
};
|
||||
}
|
||||
return await db.tenantType.update({
|
||||
where: { id: id },
|
||||
data: update,
|
||||
});
|
||||
return await db.tenantType
|
||||
.update({
|
||||
where: { id: id },
|
||||
data: update,
|
||||
})
|
||||
.then((item) => {
|
||||
clearCacheKey(TENANT_TYPES_CACHE_KEY);
|
||||
return item;
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteTenantType(id: string) {
|
||||
return await db.tenantType.delete({
|
||||
where: { id: id },
|
||||
});
|
||||
return await db.tenantType
|
||||
.delete({
|
||||
where: { id: id },
|
||||
})
|
||||
.then((item) => {
|
||||
clearCacheKey(TENANT_TYPES_CACHE_KEY);
|
||||
return item;
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user