fix(housekeeping): address task 14 review round 2
This commit is contained in:
1 parent
d09eaa33d6
commit
c524b305d7
17 files changed
+614
-130
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import "server-only";
|
||||
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import { eq, type SQL, sql } from "drizzle-orm";
|
||||
import type { ResultSetHeader } from "mysql2";
|
||||
import {
|
||||
db,
|
||||
@@ -443,13 +443,11 @@ async function eventChange(
|
||||
if (action === "create") {
|
||||
const parsed = createEventSchema.safeParse(data);
|
||||
if (!parsed.success) throw validation();
|
||||
const [result] = await connection
|
||||
.insert(WebsiteEvent)
|
||||
.values({
|
||||
...parsed.data,
|
||||
hostUserId: context.capability.actor.id,
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
const [result] = await connection.insert(WebsiteEvent).values({
|
||||
...parsed.data,
|
||||
hostUserId: context.capability.actor.id,
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
const id = insertedId(result);
|
||||
return {
|
||||
before: null,
|
||||
@@ -653,14 +651,12 @@ async function tagChange(
|
||||
const name = text(data.name, 255, true);
|
||||
const backgroundColor = text(data.backgroundColor, 10) || "#888888";
|
||||
const now = new Date();
|
||||
const [result] = (await connection
|
||||
.insert(Tags)
|
||||
.values({
|
||||
name,
|
||||
backgroundColor,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
})) as unknown as [ResultSetHeader];
|
||||
const [result] = (await connection.insert(Tags).values({
|
||||
name,
|
||||
backgroundColor,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
})) as unknown as [ResultSetHeader];
|
||||
const id = insertedId(result);
|
||||
await activity(
|
||||
context,
|
||||
@@ -740,17 +736,35 @@ async function prefixChange(
|
||||
return { before: { id }, after: null };
|
||||
}
|
||||
if (action !== "update") throw validation();
|
||||
const prefixText = text(data.text, 255, true);
|
||||
const color = text(data.color, 32, true);
|
||||
const icon = text(data.icon, 255);
|
||||
const effect = text(data.effect, 255);
|
||||
const active = Math.min(1, nonNegativeInteger(data.active, 1));
|
||||
const values: Record<string, unknown> = {};
|
||||
const assignments: SQL[] = [];
|
||||
if (hasOwn(data, "text")) {
|
||||
values.text = text(data.text, 255, true);
|
||||
assignments.push(sql`text = ${values.text}`);
|
||||
}
|
||||
if (hasOwn(data, "color")) {
|
||||
values.color = text(data.color, 32, true);
|
||||
assignments.push(sql`color = ${values.color}`);
|
||||
}
|
||||
if (hasOwn(data, "icon")) {
|
||||
values.icon = text(data.icon, 255);
|
||||
assignments.push(sql`icon = ${values.icon}`);
|
||||
}
|
||||
if (hasOwn(data, "effect")) {
|
||||
values.effect = text(data.effect, 255);
|
||||
assignments.push(sql`effect = ${values.effect}`);
|
||||
}
|
||||
if (hasOwn(data, "active")) {
|
||||
values.active = booleanValue(data.active) ? 1 : 0;
|
||||
assignments.push(sql`active = ${values.active}`);
|
||||
}
|
||||
requirePatch(values);
|
||||
await connection.execute(
|
||||
sql`UPDATE custom_prefixes SET text = ${prefixText}, color = ${color}, icon = ${icon}, effect = ${effect}, active = ${active} WHERE id = ${id}`,
|
||||
sql`UPDATE custom_prefixes SET ${sql.join(assignments, sql`, `)} WHERE id = ${id}`,
|
||||
);
|
||||
return {
|
||||
before: { id },
|
||||
after: { id, text: prefixText, color, icon, effect, active },
|
||||
after: { id, ...values },
|
||||
output: { id: String(id) },
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user