Add session management

This commit is contained in:
2025-01-03 12:32:43 +05:30
parent 83786e2994
commit 14c9b0210c
12 changed files with 341 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
import { generateId } from "../utils/id";
import { CreateUserInput, userModel } from "./user.schema";
import { CreateUserInput, UpdateUserInput, userModel } from "./user.schema";
export async function createUser(input: CreateUserInput, tenantId: string) {
const user = await userModel.create({
@@ -13,9 +13,17 @@ export async function createUser(input: CreateUserInput, tenantId: string) {
return user;
}
export async function getUser(userId: string, tenantId: string) {
export async function getUser(userId: string) {
const user = await userModel.findOne({
$and: [{ tenantId: tenantId }, { pid: userId }],
$and: [{ pid: userId }],
});
return user;
}
export async function getUserByEmail(email: string) {
return await userModel.findOne({ email: email });
}
export async function updateUser(userId: string, input: UpdateUserInput) {
return await userModel.findOneAndUpdate({ pid: userId }, input);
}