add organization access to clients
This commit is contained in:
@@ -80,7 +80,7 @@ export async function updateUserHandler(
|
||||
const { userId } = req.params as { userId: string };
|
||||
|
||||
try {
|
||||
const updatedUser = await updateUser(userId, input);
|
||||
const updatedUser = await updateUser(userId, input, req.user);
|
||||
if (!updateUser) return res.code(404).send({ error: "resource not found" });
|
||||
|
||||
return res.code(200).send(updatedUser);
|
||||
|
||||
@@ -13,7 +13,10 @@ export async function createUser(
|
||||
input: CreateUserInput,
|
||||
user: AuthenticatedUser
|
||||
) {
|
||||
if (input.role == "admin" && user.role != "superAdmin") {
|
||||
if (
|
||||
input.role === "superAdmin" ||
|
||||
(input.role == "admin" && user.role != "superAdmin")
|
||||
) {
|
||||
throw ErrOpNotValid;
|
||||
}
|
||||
|
||||
@@ -82,7 +85,30 @@ export async function listUsers(tenantId: string) {
|
||||
);
|
||||
}
|
||||
|
||||
export async function updateUser(userId: string, input: UpdateUserInput) {
|
||||
export async function updateUser(
|
||||
userId: string,
|
||||
input: UpdateUserInput,
|
||||
user: AuthenticatedUser
|
||||
) {
|
||||
if (
|
||||
input.role === "superAdmin" ||
|
||||
(input.role == "admin" && user.role != "superAdmin")
|
||||
) {
|
||||
throw ErrOpNotValid;
|
||||
}
|
||||
return await userModel
|
||||
.findOneAndUpdate({ pid: userId }, input, {
|
||||
new: true,
|
||||
})
|
||||
.select(
|
||||
"_id pid orgId firstName lastName name email role avatar status createdAt createdBy lastLogin"
|
||||
);
|
||||
}
|
||||
|
||||
export async function updateUserInternal(
|
||||
userId: string,
|
||||
input: UpdateUserInput
|
||||
) {
|
||||
return await userModel
|
||||
.findOneAndUpdate({ pid: userId }, input, {
|
||||
new: true,
|
||||
|
||||
Reference in New Issue
Block a user