User data functions

This commit is contained in:
Hri7566 2023-09-07 19:14:01 -04:00
parent 973f20e72f
commit cc3a7a7b43
2 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,3 @@
import { PrismaClient } from "@prisma/client";
export const prisma = new PrismaClient();

52
src/data/user.ts Normal file
View File

@ -0,0 +1,52 @@
import { User } from "@prisma/client";
import { prisma } from "./prisma";
export interface UserFlags {
freeze_name: number;
"no chat rate limit": number;
chat_curse_1: number;
chat_curse_2: number;
override_id: string;
}
export async function createUser(
_id: string,
name?: string,
color?: string,
flags?: UserFlags
) {
return await prisma.user.create({
data: { id: _id, name, color, flags: JSON.stringify(flags) }
});
}
export async function deleteUser(_id: string) {
return await prisma.user.delete({
where: { id: _id }
});
}
export async function readUser(_id: string) {
const data = await prisma.user.findUnique({
where: { id: _id }
});
if (!data) return null;
return {
_id: data.id,
name: data.name,
color: data.color,
flags: data.flags
};
}
export async function updateUser(
_id: string,
data: Omit<User, "id"> & { _id: string }
) {
return await prisma.user.update({
where: { id: _id },
data
});
}