add helper to upsert a guild member
This commit is contained in:
parent
99fc49daa8
commit
ef76cf01f6
1 changed files with 38 additions and 0 deletions
38
src/helpers/upsertGuildMember/index.ts
Normal file
38
src/helpers/upsertGuildMember/index.ts
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import { GuildMember } from "discord.js";
|
||||||
|
import db from "../../handlers/database";
|
||||||
|
|
||||||
|
export default async (guildMember: GuildMember) => {
|
||||||
|
const { guild, user } = guildMember;
|
||||||
|
|
||||||
|
return await db.guildMember.upsert({
|
||||||
|
where: {
|
||||||
|
userId_guildId: {
|
||||||
|
userId: user.id,
|
||||||
|
guildId: guild.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
update: {},
|
||||||
|
create: {
|
||||||
|
user: {
|
||||||
|
connectOrCreate: {
|
||||||
|
create: {
|
||||||
|
id: user.id,
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
id: user.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
guild: {
|
||||||
|
connectOrCreate: {
|
||||||
|
create: {
|
||||||
|
id: guild.id,
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
id: guild.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
Loading…
Add table
Reference in a new issue