@dynamatix/cat-shared 0.0.140 → 0.0.149

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.
@@ -316,8 +316,23 @@ function applyAuditMiddleware(schema, collectionName) {
316
316
  // --- Add pound prefix if needed ---
317
317
  const dataType = fieldTypeMap[field];
318
318
  if (dataType === 'pound') {
319
- if (displayOldValue != null && displayOldValue !== '') displayOldValue = `£${displayOldValue}`;
320
- if (displayNewValue != null && displayNewValue !== '') displayNewValue = `£${displayNewValue}`;
319
+ const formatPoundValue = (rawValue) => {
320
+ if (rawValue == null || rawValue === '') return rawValue;
321
+ const stringValue = typeof rawValue === 'string' ? rawValue.trim() : String(rawValue);
322
+ if (stringValue === '') return rawValue;
323
+ const valueSansSymbol = stringValue.startsWith('£') ? stringValue.slice(1) : stringValue;
324
+ const numericString = valueSansSymbol.replace(/,/g, '');
325
+ const numericValue = Number(numericString);
326
+ if (!Number.isFinite(numericValue)) return `£${valueSansSymbol}`;
327
+ const decimalPart = numericString.split('.')[1];
328
+ const formatted = numericValue.toLocaleString('en-GB', {
329
+ minimumFractionDigits: decimalPart ? decimalPart.length : 0,
330
+ maximumFractionDigits: decimalPart ? decimalPart.length : 20
331
+ });
332
+ return `£${formatted}`;
333
+ };
334
+ displayOldValue = formatPoundValue(displayOldValue);
335
+ displayNewValue = formatPoundValue(displayNewValue);
321
336
  }
322
337
  if (displayOldValue !== displayNewValue) {
323
338
  const fieldDescription = await resolveDescription(field, result);
@@ -411,12 +426,21 @@ function applyAuditMiddleware(schema, collectionName) {
411
426
  async function updateContextAuditCount(contextId, count) {
412
427
  count = Number(count);
413
428
  if (!contextId || isNaN(count)) return;
414
- const model = mongoose.models['Application'];
415
- await model.findByIdAndUpdate(
416
- { _id: contextId },
417
- { $inc: { newAuditRecordsCount: count } },
418
- { new: true, upsert: true }
419
- );
429
+
430
+ try {
431
+ const model = mongoose.models['Application'];
432
+
433
+ // Use direct collection access to bypass all Mongoose middleware
434
+ // This prevents workflow triggers from firing for audit count updates
435
+ await model.collection.updateOne(
436
+ { _id: new mongoose.Types.ObjectId(contextId) },
437
+ { $inc: { newAuditRecordsCount: count } },
438
+ { upsert: false }
439
+ );
440
+ } catch (error) {
441
+ console.error('Error updating audit count:', error);
442
+ // Don't throw - audit count update failure shouldn't break the main operation
443
+ }
420
444
  }
421
445
 
422
446
  export function registerAuditHook(callback) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamatix/cat-shared",
3
- "version": "0.0.140",
3
+ "version": "0.0.149",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",