Skip to content

Commit

Permalink
feat(guildSettings): util function to update a prop in guild settings
Browse files Browse the repository at this point in the history
  • Loading branch information
JPBM135 committed Jan 11, 2023
1 parent 2cb6685 commit 20006bc
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions apps/yuudachi/src/functions/settings/updateGuildSetting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { kSQL } from "@yuudachi/framework";
import type { Snowflake } from "discord.js";
import type { SerializableParameter, Sql } from "postgres";
import { container } from "tsyringe";
import type { SettingsKeys, ReportStatusTagTuple, ReportTypeTagTuple } from "./getGuildSetting.js";

export async function updateGuildSetting<T = string>(
guildId: Snowflake,
prop: SettingsKeys,
newValue: T,
table = "guild_settings",
) {
const sql = container.resolve<Sql<{}>>(kSQL);

const [data] = await sql.unsafe<[{ value: ReportStatusTagTuple | ReportTypeTagTuple | boolean | string | null }?]>(
`update ${table} set ${prop} = $2
where guild_id = $1`,
[guildId, newValue] as SerializableParameter[],
);

return (data?.value ?? null) as unknown as T;
}

0 comments on commit 20006bc

Please sign in to comment.