MEK 등록시 로그를 남기도록 변경

This commit is contained in:
static
2025-01-12 19:22:21 +09:00
parent f8115f4f2e
commit 004e41b0cf
2 changed files with 28 additions and 7 deletions

View File

@@ -2,7 +2,7 @@ import { SqliteError } from "better-sqlite3";
import { and, or, eq } from "drizzle-orm";
import db from "./drizzle";
import { IntegrityError } from "./error";
import { mek, clientMek } from "./schema";
import { mek, mekLog, clientMek } from "./schema";
export const registerInitialMek = async (
userId: number,
@@ -16,8 +16,6 @@ export const registerInitialMek = async (
await tx.insert(mek).values({
userId,
version: 1,
createdBy,
createdAt: new Date(),
state: "active",
});
await tx.insert(clientMek).values({
@@ -27,6 +25,13 @@ export const registerInitialMek = async (
encMek,
encMekSig,
});
await tx.insert(mekLog).values({
userId,
mekVersion: 1,
timestamp: new Date(),
action: "create",
actionBy: createdBy,
});
} catch (e) {
if (e instanceof SqliteError && e.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
throw new IntegrityError("MEK already registered");