added users admin page + publicId

This commit is contained in:
PxlLoewe
2025-02-16 12:23:31 +01:00
parent 56a695c090
commit 586a747486
8 changed files with 77 additions and 3 deletions

View File

@@ -5,11 +5,26 @@ import bcrypt from 'bcryptjs';
export const register = async ({
password,
...user
}: Prisma.UserCreateInput) => {
}: Omit<Prisma.UserCreateInput, 'publicId'>) => {
const hashedPassword = await bcrypt.hash(password, 15);
const lastUserPublicId = await prisma.user.findFirst({
select: {
publicId: true,
},
orderBy: {
publicId: 'desc',
},
});
let varPublicId = 'VAR0000';
if (lastUserPublicId) {
const lastUserInt = parseInt(lastUserPublicId.publicId.replace('VAR', ''));
varPublicId = `VAR${(lastUserInt + 1).toString().padStart(4, '0')}`;
}
const newUser = prisma.user.create({
data: {
...user,
publicId: varPublicId,
password: hashedPassword,
},
});