@comasoft/nestjs 0.2.29 → 0.2.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
function validateAndParseDate(e){if(!/^\d{8}T\d{6}Z$/.test(e))throw new Error("Invalid date format. Use YYYYMMDDTHHMMSSZ (e.g., 20250122T150000Z)");const n=e.substring(0,4),t=e.substring(4,6),r=e.substring(6,8),i=e.substring(9,11),
|
|
1
|
+
function validateAndParseDate(e){if(!/^\d{8}T\d{6}Z$/.test(e))throw new Error("Invalid date format. Use YYYYMMDDTHHMMSSZ (e.g., 20250122T150000Z)");const n=e.substring(0,4),t=e.substring(4,6),r=e.substring(6,8),i=e.substring(9,11),s=e.substring(11,13),a=e.substring(13,15),l=new Date(`${n}-${t}-${r}T${i}:${s}:${a}Z`);if(isNaN(l.getTime()))throw new Error("Invalid date");return l}Object.defineProperty(exports,"__esModule",{value:!0}),exports.applyFiltersAndSorting=function applyFiltersAndSorting(n,t){const{_keyword:r,_group:i,_sort:s,aliasName:a="a",keywordFields:l=["name"],groupFields:$=[]}=t;return function applyKeywordFilter(e,n,t,r){if(n){const i=[],s={};r.length>0&&(r.forEach((e,r)=>{if(e.endsWith("*")){const a=e.slice(0,-1),l=a.includes(".")?a:`${t}.${a}`;i.push(`${l} = :keyword${r}`),s[`keyword${r}`]=n}else{const a=e.includes(".")?e:`${t}.${e}`;i.push(`${a} ILIKE :keyword${r}`),s[`keyword${r}`]=`%${n}%`}}),e.andWhere(`(${i.join(" OR ")})`,s))}}(n,r,a,l),function applyGroupFilter(n,t,r,i){if(!t)return;if(0===i.length)return;const s=t.split("|");if(s.some(e=>{const[n]=e.split("-");return!i.includes(n)}))throw new Error("Invalid field detected in group filter");const a=[],l={};s.forEach((n,t)=>{const[i,s]=n.split(/-(.+)/),$=i.includes(".")?i:`${r}.${i}`;let o;o=s.includes("__")?i.includes("_at")||i.includes("_date")?e.handleDateRange($,s,t):e.handleNumberRange($,s,t):e.handleEquals($,s,t),o.condition&&(a.push(o.condition),Object.assign(l,o.parameters))}),a.length>0&&n.andWhere(`(${a.join(" AND ")})`,l)}(n,i,a,$),function applySorting(e,n,t){if(n){n.split("|").forEach((n,r)=>{const[i,s]=n.split("-"),a=s.toUpperCase();if("ASC"!==a&&"DESC"!==a)throw new Error(`Invalid sort order: ${s}`);0===r?e.orderBy(`${t}.${i}`,a):e.addOrderBy(`${t}.${i}`,a)})}else{Object.keys(e.expressionMap.orderBys).length>0||e.orderBy(`${t}.id`,"DESC")}}(n,s,a),n};const e={handleEquals(e,n,t){if(n.includes(",")){const r=n.split(",").map(e=>e.trim()).filter(e=>e);return{condition:`${e} IN (:...${e}${t})`,parameters:{[`${e}${t}`]:r}}}return{condition:`${e} = :${e}${t}`,parameters:{[`${e}${t}`]:n}}},handleNumberRange(e,n,t){const[r,i]=n.split("__").map(e=>""===e?null:Number(e)),s=[],a={};return null!==r&&null!==i?(s.push(`${e} BETWEEN :${e}Min${t} AND :${e}Max${t}`),a[`${e}Min${t}`]=r,a[`${e}Max${t}`]=i):null!==r?(s.push(`${e} >= :${e}Min${t}`),a[`${e}Min${t}`]=r):null!==i&&(s.push(`${e} <= :${e}Max${t}`),a[`${e}Max${t}`]=i),{condition:s.join(" AND "),parameters:a}},handleDateRange(e,n,t){const[r,i]=n.split("__").map(e=>""===e?null:e),s=[],a={};return null!==r&&null!==i?(s.push(`${e} BETWEEN :${e}Min${t} AND :${e}Max${t}`),a[`${e}Min${t}`]=validateAndParseDate(r),a[`${e}Max${t}`]=validateAndParseDate(i)):null!==r?(s.push(`${e} >= :${e}Min${t}`),a[`${e}Min${t}`]=validateAndParseDate(r)):null!==i&&(s.push(`${e} <= :${e}Max${t}`),a[`${e}Max${t}`]=validateAndParseDate(i)),{condition:s.join(" AND "),parameters:a}}};
|