This commit is contained in:
prafull-opensignlabs
2026-01-07 09:40:36 +00:00
parent bce0e4971e
commit eb8e7b089b
73 changed files with 20018 additions and 2260 deletions
@@ -98,11 +98,6 @@ export default function reportJson(id, currentUserId) {
IsCompleted: true,
IsDeclined: { $ne: true },
IsArchive: { $ne: true },
// CreatedBy: {
// __type: 'Pointer',
// className: '_User',
// objectId: currentUserId,
// },
$or: [
// Condition 1: If `CreatedBy` exists, no need for `Signers` filter
{ CreatedBy: { __type: 'Pointer', className: '_User', objectId: currentUserId } },
@@ -230,3 +225,36 @@ export default function reportJson(id, currentUserId) {
return null;
}
}
// Escape regex special characters. Copied from filterDocs.js
function escapeRegExp(str) {
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
/**
* Applies searchTerm rules; combines existing access $or with search $or using $and.
*/
export function applySearch({ reportId, baseWhere, searchTerm }) {
if (!searchTerm) return baseWhere;
const escaped = escapeRegExp(searchTerm);
const nameMatch = { Name: { $regex: `.*${escaped}.*`, $options: 'i' } };
const emailMatch = { Email: { $regex: `.*${escaped}.*`, $options: 'i' } };
if (reportId === 'contacts') {
return { ...baseWhere, $or: [nameMatch, emailMatch] };
}
const searchOr = [
nameMatch,
{ Signers: { $inQuery: { className: 'contracts_Contactbook', where: emailMatch } } },
];
// If baseWhere already has an access-control $or, combine using $and
if (baseWhere.$or) {
const { $or: accessOr, ...rest } = baseWhere;
return { ...rest, $and: [{ $or: accessOr }, { $or: searchOr }] };
}
return { ...baseWhere, $or: searchOr };
}