Files
var-monorepo/apps/hub/app/(app)/admin/user/action.ts
PxlLoewe 50f42e99d3 feat: Implement connected user API and integrate chat and report components
- Added API routes for fetching connected users, keywords, missions, and stations.
- Created a new QueryProvider component for managing query states and socket events.
- Introduced connection stores for dispatch and pilot, managing socket connections and states.
- Updated Prisma schema for connected aircraft model.
- Enhanced UI with toast notifications for status updates and chat interactions.
- Implemented query functions for fetching connected users and keywords with error handling.
2025-05-07 00:43:45 -07:00

47 lines
978 B
TypeScript

"use server";
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 array = new Uint8Array(8);
crypto.getRandomValues(array);
const password = Array.from(array, (byte) =>
("0" + (byte % 36).toString(36)).slice(-1),
).join("");
const hashedPassword = await bcrypt.hash(password, 12);
const user = await prisma.user.update({
where: {
id: id,
},
data: {
password: hashedPassword,
},
});
await sendMailByTemplate(user.email, "password-change", {
user: user,
password: password,
});
return { password };
};
export const deleteDispoHistory = async (id: number) => {
return await prisma.connectedDispatcher.delete({
where: {
id: id,
},
});
};