mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-12-21 20:08:51 +01:00
feat(database): add fun logging to database
This commit is contained in:
91
src/utils/database/fun.ts
Normal file
91
src/utils/database/fun.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import { container } from '@sapphire/framework';
|
||||
import type { Snowflake } from 'discord.js';
|
||||
|
||||
// Balance
|
||||
|
||||
export async function countTotal(
|
||||
senderId: Snowflake,
|
||||
type: string,
|
||||
receiverId: Snowflake | undefined = undefined,
|
||||
) {
|
||||
const result = await container.database.funLog.count({
|
||||
where: {
|
||||
sendUserId: senderId,
|
||||
receiveUserId: receiverId,
|
||||
type: {
|
||||
name: type,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function addFunLog(
|
||||
senderId: Snowflake,
|
||||
type: string,
|
||||
receiverId: Snowflake | undefined = undefined,
|
||||
) {
|
||||
if (receiverId === undefined) {
|
||||
await container.database.funLog.create({
|
||||
data: {
|
||||
sendUser: {
|
||||
connectOrCreate: {
|
||||
where: {
|
||||
id: senderId,
|
||||
},
|
||||
create: {
|
||||
id: senderId,
|
||||
},
|
||||
},
|
||||
},
|
||||
type: {
|
||||
connectOrCreate: {
|
||||
where: {
|
||||
name: type,
|
||||
},
|
||||
create: {
|
||||
name: type,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await container.database.funLog.create({
|
||||
data: {
|
||||
sendUser: {
|
||||
connectOrCreate: {
|
||||
where: {
|
||||
id: senderId,
|
||||
},
|
||||
create: {
|
||||
id: senderId,
|
||||
},
|
||||
},
|
||||
},
|
||||
receiveUser: {
|
||||
connectOrCreate: {
|
||||
where: {
|
||||
id: receiverId,
|
||||
},
|
||||
create: {
|
||||
id: receiverId,
|
||||
},
|
||||
},
|
||||
},
|
||||
type: {
|
||||
connectOrCreate: {
|
||||
where: {
|
||||
name: type,
|
||||
},
|
||||
create: {
|
||||
name: type,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user