36 lines
766 B
TypeScript
36 lines
766 B
TypeScript
"use server";
|
|
import { PrismaClient } from "@prisma/client";
|
|
import { prisma, Prisma } from "@repo/db";
|
|
import bcrypt from "bcryptjs";
|
|
import { sendMailByTemplate } from "../../../../helper/mail";
|
|
|
|
export const editUser = async (id: string, data: Prisma.UserUpdateInput) => {
|
|
return await prisma.user.update({
|
|
where: {
|
|
id: id,
|
|
},
|
|
data,
|
|
});
|
|
};
|
|
|
|
export const resetPassword = async (id: string) => {
|
|
const password = Math.random().toString(36).slice(-8);
|
|
const hashedPassword = await bcrypt.hash(password, 15);
|
|
|
|
const user = await prisma.user.update({
|
|
where: {
|
|
id: id,
|
|
},
|
|
data: {
|
|
password: hashedPassword,
|
|
},
|
|
});
|
|
|
|
await sendMailByTemplate(user.email, "password-change", {
|
|
user: user,
|
|
password: password,
|
|
});
|
|
|
|
return { password };
|
|
};
|