-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetData.ts
More file actions
47 lines (44 loc) · 960 Bytes
/
getData.ts
File metadata and controls
47 lines (44 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import db, { Prisma, UserGuildData } from "../index.js"
export const getGuildData = async (guildId: string, include: Prisma.GuildInclude = { premiumGuildSlots: true }) => {
if (!guildId) throw new Error("No guild ID provided")
const guildData = await db.guild.upsert({
where: {
id: guildId,
},
update: {},
create: {
id: guildId,
},
include,
})
return guildData
}
export const getUserData = async (userId: string, include: Prisma.UserInclude = { premiumGuildSlots: true }) => {
const userData = await db.user.upsert({
where: {
id: userId,
},
update: {},
create: {
id: userId,
},
include,
})
return userData
}
export const getUserGuildData = async (userId: string, guildId: string): Promise<UserGuildData> => {
const userGuildData = await db.userGuildData.upsert({
where: {
userId_guildId: {
userId,
guildId,
},
},
update: {},
create: {
userId,
guildId,
},
})
return userGuildData
}