mirror of
https://github.com/fosrl/pangolin.git
synced 2026-05-12 07:14:14 +00:00
♻️ merge header auth & extended compability to one table
This commit is contained in:
@@ -524,25 +524,6 @@ export const resourceHeaderAuthExtendedCompatibility = pgTable(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
export const resourcePolicyHeaderAuthExtendedCompatibility = pgTable(
|
|
||||||
"resourcePolicyHeaderAuthExtendedCompatibility",
|
|
||||||
{
|
|
||||||
headerAuthExtendedCompatibilityId: serial(
|
|
||||||
"headerAuthExtendedCompatibilityId"
|
|
||||||
).primaryKey(),
|
|
||||||
resourcePolicyId: integer("resourcePolicyId")
|
|
||||||
.notNull()
|
|
||||||
.references(() => resourcePolicies.resourcePolicyId, {
|
|
||||||
onDelete: "cascade"
|
|
||||||
}),
|
|
||||||
extendedCompatibilityIsActivated: boolean(
|
|
||||||
"extendedCompatibilityIsActivated"
|
|
||||||
)
|
|
||||||
.notNull()
|
|
||||||
.default(true)
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export const resourcePolicyPincode = pgTable("resourcePolicyPincode", {
|
export const resourcePolicyPincode = pgTable("resourcePolicyPincode", {
|
||||||
pincodeId: serial("pincodeId").primaryKey(),
|
pincodeId: serial("pincodeId").primaryKey(),
|
||||||
pincodeHash: varchar("pincodeHash").notNull(),
|
pincodeHash: varchar("pincodeHash").notNull(),
|
||||||
@@ -567,6 +548,9 @@ export const resourcePolicyPassword = pgTable("resourcePolicyPassword", {
|
|||||||
export const resourcePolicyHeaderAuth = pgTable("resourcePolicyHeaderAuth", {
|
export const resourcePolicyHeaderAuth = pgTable("resourcePolicyHeaderAuth", {
|
||||||
headerAuthId: serial("headerAuthId").primaryKey(),
|
headerAuthId: serial("headerAuthId").primaryKey(),
|
||||||
headerAuthHash: varchar("headerAuthHash").notNull(),
|
headerAuthHash: varchar("headerAuthHash").notNull(),
|
||||||
|
extendedCompatibility: boolean("extendedCompatibility")
|
||||||
|
.notNull()
|
||||||
|
.default(true),
|
||||||
resourcePolicyId: integer("resourcePolicyId")
|
resourcePolicyId: integer("resourcePolicyId")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => resourcePolicies.resourcePolicyId, {
|
.references(() => resourcePolicies.resourcePolicyId, {
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
import { Request, Response, NextFunction } from "express";
|
import { Request, Response, NextFunction } from "express";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import {
|
import { db, resourcePolicyHeaderAuth } from "@server/db";
|
||||||
db,
|
|
||||||
resourcePolicyHeaderAuth,
|
|
||||||
resourcePolicyHeaderAuthExtendedCompatibility
|
|
||||||
} from "@server/db";
|
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import HttpCode from "@server/types/HttpCode";
|
import HttpCode from "@server/types/HttpCode";
|
||||||
import createHttpError from "http-errors";
|
import createHttpError from "http-errors";
|
||||||
@@ -85,32 +81,17 @@ export async function setResourcePolicyHeaderAuth(
|
|||||||
resourcePolicyId
|
resourcePolicyId
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
await trx
|
|
||||||
.delete(resourcePolicyHeaderAuthExtendedCompatibility)
|
|
||||||
.where(
|
|
||||||
eq(
|
|
||||||
resourcePolicyHeaderAuthExtendedCompatibility.resourcePolicyId,
|
|
||||||
resourcePolicyId
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (user && password && extendedCompatibility !== null) {
|
if (user && password && extendedCompatibility !== null) {
|
||||||
const headerAuthHash = await hashPassword(
|
const headerAuthHash = await hashPassword(
|
||||||
Buffer.from(`${user}:${password}`).toString("base64")
|
Buffer.from(`${user}:${password}`).toString("base64")
|
||||||
);
|
);
|
||||||
|
|
||||||
await Promise.all([
|
await trx.insert(resourcePolicyHeaderAuth).values({
|
||||||
trx
|
resourcePolicyId,
|
||||||
.insert(resourcePolicyHeaderAuth)
|
headerAuthHash,
|
||||||
.values({ resourcePolicyId, headerAuthHash }),
|
extendedCompatibility: extendedCompatibility
|
||||||
trx
|
});
|
||||||
.insert(resourcePolicyHeaderAuthExtendedCompatibility)
|
|
||||||
.values({
|
|
||||||
resourcePolicyId,
|
|
||||||
extendedCompatibilityIsActivated:
|
|
||||||
extendedCompatibility
|
|
||||||
})
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user