feat: allow admin to assign multiple counties to users
This commit is contained in:
@@ -108,6 +108,7 @@ export async function getPermit(permitId: string, user: AuthenticatedUser) {
|
||||
.populate({ path: "assignedTo", select: "pid name avatar" })
|
||||
.populate({ path: "createdBy", select: "pid name avatar" });
|
||||
|
||||
// Don't return the record if the user doesn't have access to the org
|
||||
if (
|
||||
permit &&
|
||||
user.role == "client" &&
|
||||
@@ -115,6 +116,15 @@ export async function getPermit(permitId: string, user: AuthenticatedUser) {
|
||||
)
|
||||
return null;
|
||||
|
||||
// Don't return the record if the user doesn't have access to the org
|
||||
if (
|
||||
permit &&
|
||||
user.counties &&
|
||||
user.counties.length > 0 &&
|
||||
!user.counties.includes(permit.county.id.toString())
|
||||
)
|
||||
return null;
|
||||
|
||||
return permit;
|
||||
}
|
||||
|
||||
@@ -135,6 +145,14 @@ export async function listPermits(
|
||||
});
|
||||
}
|
||||
|
||||
if (user.counties && user.counties.length > 0) {
|
||||
filterObj.push({
|
||||
"county.id": {
|
||||
$in: user.counties.map((item) => new mongoose.Types.ObjectId(item)),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
let { taggedFilter, taggedUserFilterIndex } = getTaggedUsersFilter(
|
||||
filterObj,
|
||||
sortObj
|
||||
@@ -410,6 +428,14 @@ export async function searchPermit(
|
||||
});
|
||||
}
|
||||
|
||||
if (user.counties && user.counties.length > 0) {
|
||||
filterObj.push({
|
||||
"county.id": {
|
||||
$in: user.counties.map((item) => new mongoose.Types.ObjectId(item)),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (!params.searchToken)
|
||||
return { permits: [], metadata: { count: 0, page, pageSize } };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user