-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8d4230
commit f5d9efa
Showing
5 changed files
with
61 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { GuildMember, Snowflake } from "discord.js"; | ||
|
||
import type { Stempel } from "./model.js"; | ||
import db from "./kysely.js"; | ||
|
||
/** | ||
* @returns true/false depending if the invitedMember is already in the database | ||
*/ | ||
export async function insertStempel( | ||
invitator: GuildMember, | ||
invitedMember: GuildMember, | ||
ctx = db(), | ||
): Promise<boolean> { | ||
const now = new Date().toISOString(); | ||
|
||
const res = await ctx | ||
.insertInto("stempels") | ||
.values({ | ||
id: crypto.randomUUID(), | ||
invitator: invitator.id, | ||
invitedMember: invitedMember.id, | ||
createdAt: now, | ||
updatedAt: now, | ||
}) | ||
.returning("id") | ||
.executeTakeFirst(); | ||
|
||
return typeof res?.id === "string"; | ||
} | ||
|
||
export function getStempelByInvitator( | ||
invitator: GuildMember, | ||
ctx = db(), | ||
): Promise<Stempel[]> { | ||
return ctx | ||
.selectFrom("stempels") | ||
.where("invitator", "=", invitator.id) | ||
.selectAll() | ||
.execute(); | ||
} |