feat: update

This commit is contained in:
Ivan Rezchikov
2026-06-18 22:59:29 +03:00
parent dfc3dd2065
commit dc8a41087c
3 changed files with 26 additions and 10 deletions
+17 -9
View File
@@ -1,5 +1,6 @@
import { prisma } from "@/lib/prisma";
import { v4 as uuidv4 } from "uuid";
import type { UserData } from "./types";
export async function findUserByKotosoftId(kotosoftId: string) {
return prisma.user.findUnique({ where: { kotosoftId } });
@@ -9,18 +10,25 @@ export async function findUserById(id: string) {
return prisma.user.findUnique({ where: { id } });
}
export async function findOrCreateUser(data: {
kotosoftId: string;
email: string;
firstName: string;
secondName: string;
sex: string;
birthDate: string;
}) {
export async function findOrCreateUser(data: UserData) {
const existing = await findUserByKotosoftId(data.kotosoftId);
if (existing) return existing;
return prisma.user.create({
data: { id: uuidv4(), ...data },
data: {
id: uuidv4(),
...data,
birthDate: new Date(data.birthDate),
},
});
}
export async function updateUser(id: string, data: Partial<Omit<UserData, "kotosoftId">>) {
return prisma.user.update({
where: { id },
data: {
...data,
...(data.birthDate ? { birthDate: new Date(data.birthDate) } : {}),
},
});
}