mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-22 12:56:37 +00:00
Add override for limits
This commit is contained in:
@@ -140,6 +140,7 @@ export const limits = pgTable("limits", {
|
|||||||
})
|
})
|
||||||
.notNull(),
|
.notNull(),
|
||||||
value: real("value"),
|
value: real("value"),
|
||||||
|
override: boolean("override").default(false),
|
||||||
description: text("description")
|
description: text("description")
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -129,6 +129,7 @@ export const limits = sqliteTable("limits", {
|
|||||||
})
|
})
|
||||||
.notNull(),
|
.notNull(),
|
||||||
value: real("value"),
|
value: real("value"),
|
||||||
|
override: integer("override", { mode: "boolean" }).default(false),
|
||||||
description: text("description")
|
description: text("description")
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { db, limits } from "@server/db";
|
|||||||
import { and, eq } from "drizzle-orm";
|
import { and, eq } from "drizzle-orm";
|
||||||
import { LimitSet } from "./limitSet";
|
import { LimitSet } from "./limitSet";
|
||||||
import { FeatureId } from "./features";
|
import { FeatureId } from "./features";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
|
||||||
class LimitService {
|
class LimitService {
|
||||||
async applyLimitSetToOrg(orgId: string, limitSet: LimitSet): Promise<void> {
|
async applyLimitSetToOrg(orgId: string, limitSet: LimitSet): Promise<void> {
|
||||||
@@ -13,6 +14,36 @@ class LimitService {
|
|||||||
for (const [featureId, entry] of limitEntries) {
|
for (const [featureId, entry] of limitEntries) {
|
||||||
const limitId = `${orgId}-${featureId}`;
|
const limitId = `${orgId}-${featureId}`;
|
||||||
const { value, description } = entry;
|
const { value, description } = entry;
|
||||||
|
// get the limit first
|
||||||
|
const [limit] = await trx
|
||||||
|
.select()
|
||||||
|
.from(limits)
|
||||||
|
.where(eq(limits.limitId, limitId))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (!limit) {
|
||||||
|
logger.warn(
|
||||||
|
`Limit with ID ${limitId} not found for org ${orgId}...`
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if its overriden
|
||||||
|
if (limit.override) {
|
||||||
|
logger.debug(
|
||||||
|
`Skipping limit ${limitId} for org ${orgId} since it is overridden...`
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// dont write if the value is the same
|
||||||
|
if (limit.value === value) {
|
||||||
|
logger.debug(
|
||||||
|
`Skipping limit ${limitId} for org ${orgId} since the value is the same (${value})...`
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
await trx
|
await trx
|
||||||
.insert(limits)
|
.insert(limits)
|
||||||
.values({ limitId, orgId, featureId, value, description });
|
.values({ limitId, orgId, featureId, value, description });
|
||||||
|
|||||||
Reference in New Issue
Block a user