mirror of
https://github.com/hanzoai/chat.git
synced 2026-09-30 20:51:17 +00:00
librechat-data-provider → @hanzochat/data-provider @librechat/data-schemas → @hanzochat/data-schemas @librechat/client → @hanzochat/client (@hanzochat/api already forked; external @librechat/agents fork follows) All imports, package.json names/deps, tsconfig path aliases, jest moduleNameMapper, and rollup/vite build aliases updated. The data-provider react-query subpath resolves via the exports map. Lockfiles regenerated in a follow-on once the canonical package manager is confirmed.
61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
import { connectDb } from '@hanzochat/backend/db/connect';
|
|
import {
|
|
findUser,
|
|
deleteConvos,
|
|
deleteMessages,
|
|
deleteAllUserSessions,
|
|
} from '@hanzochat/backend/models';
|
|
import { User, Balance, Transaction, AclEntry, Token, Group } from '@hanzochat/backend/db/models';
|
|
|
|
type TUser = { email: string; password: string };
|
|
|
|
export default async function cleanupUser(user: TUser) {
|
|
const { email } = user;
|
|
try {
|
|
console.log('🤖: global teardown has been started');
|
|
const db = await connectDb();
|
|
console.log('🤖: ✅ Connected to Database');
|
|
|
|
const foundUser = await findUser({ email });
|
|
if (!foundUser) {
|
|
console.log('🤖: ⚠️ User not found in Database');
|
|
return;
|
|
}
|
|
|
|
const userId = foundUser._id;
|
|
console.log('🤖: ✅ Found user in Database');
|
|
|
|
// Delete all conversations & associated messages
|
|
const { deletedCount, messages } = await deleteConvos(userId, {});
|
|
|
|
if (messages.deletedCount > 0 || deletedCount > 0) {
|
|
console.log(`🤖: ✅ Deleted ${deletedCount} convos & ${messages.deletedCount} messages`);
|
|
}
|
|
|
|
// Ensure all user messages are deleted
|
|
const { deletedCount: deletedMessages } = await deleteMessages({ user: userId });
|
|
if (deletedMessages > 0) {
|
|
console.log(`🤖: ✅ Deleted ${deletedMessages} remaining message(s)`);
|
|
}
|
|
|
|
// Delete all user sessions
|
|
await deleteAllUserSessions(userId.toString());
|
|
|
|
// Delete user, balance, transactions, tokens, ACL entries, and remove from groups
|
|
await Balance.deleteMany({ user: userId });
|
|
await Transaction.deleteMany({ user: userId });
|
|
await Token.deleteMany({ userId: userId });
|
|
await AclEntry.deleteMany({ principalId: userId });
|
|
await Group.updateMany({ memberIds: userId }, { $pull: { memberIds: userId } });
|
|
await User.deleteMany({ _id: userId });
|
|
|
|
console.log('🤖: ✅ Deleted user from Database');
|
|
|
|
await db.connection.close();
|
|
} catch (error) {
|
|
console.error('Error:', error);
|
|
}
|
|
}
|
|
|
|
process.on('uncaughtException', (err) => console.error('Uncaught Exception:', err));
|