@kipicore/dbcore 1.1.139 → 1.1.141

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.
@@ -552,11 +552,49 @@ function chunkArray(array, size) {
552
552
  }
553
553
  return chunks;
554
554
  }
555
- /**
556
- * Safely gets a nested value from an object using a dot-separated path.
557
- */
558
- function getNestedValue(obj, path) {
559
- return path.split('.').reduce((acc, part) => (acc && acc[part] !== undefined ? acc[part] : '-'), obj);
555
+ function formatDateIfNeeded(value) {
556
+ if (!value)
557
+ return value;
558
+ let date = null;
559
+ // Case 1: Date object
560
+ if (value instanceof Date) {
561
+ date = value;
562
+ }
563
+ // Case 2: ISO string
564
+ else if (typeof value === 'string') {
565
+ const parsed = new Date(value);
566
+ if (!isNaN(parsed.getTime())) {
567
+ date = parsed;
568
+ }
569
+ }
570
+ if (!date)
571
+ return value;
572
+ return date.toLocaleDateString('en-GB');
573
+ }
574
+ function resolvePath(value, parts) {
575
+ if (value === undefined || value === null)
576
+ return undefined;
577
+ // If array → resolve for each item (DO NOT join yet)
578
+ if (Array.isArray(value)) {
579
+ return value
580
+ .map(item => resolvePath(item, parts))
581
+ .flat()
582
+ .filter(v => v !== undefined);
583
+ }
584
+ // If no more path → format & return value
585
+ if (parts.length === 0) {
586
+ return formatDateIfNeeded(value);
587
+ }
588
+ const [current, ...rest] = parts;
589
+ return resolvePath(value[current], rest);
590
+ }
591
+ function getNestedValueForArray(obj, path) {
592
+ const parts = path.split('.');
593
+ const result = resolvePath(obj, parts);
594
+ if (Array.isArray(result)) {
595
+ return result.length ? result.join(', ') : '-';
596
+ }
597
+ return result !== undefined ? result : '-';
560
598
  }
561
599
  /**
562
600
  * Prepares userdata for EJS template based on dynamic columns config.
@@ -569,7 +607,7 @@ function extractFromObject(data, config) {
569
607
  const userdata = data.map(item => {
570
608
  const row = {};
571
609
  config.columns.forEach(col => {
572
- row[col.title] = getNestedValue(item, col.field);
610
+ row[col.title] = getNestedValueForArray(item, col.field);
573
611
  });
574
612
  return row;
575
613
  });
@@ -17,4 +17,5 @@ export interface IPollCreateAttributes extends IDefaultAttributes, Document {
17
17
  entityId: string[];
18
18
  academicCalendarId: string;
19
19
  instituteId: string;
20
+ expireAt: Date;
20
21
  }
@@ -7,5 +7,4 @@ export interface IPollSelectionAttributes extends IDefaultAttributes, Document {
7
7
  optionId: string;
8
8
  academicCalendarId: string;
9
9
  instituteId: string;
10
- expireAt: Date;
11
10
  }
@@ -87,6 +87,10 @@ const PollCreateSchema = new mongoose_1.Schema({
87
87
  type: String,
88
88
  required: true,
89
89
  },
90
+ expireAt: {
91
+ type: Date,
92
+ required: true,
93
+ },
90
94
  createdBy: {
91
95
  type: String,
92
96
  },
@@ -47,10 +47,6 @@ const PollSelectionSchema = new mongoose_1.Schema({
47
47
  type: String,
48
48
  required: true,
49
49
  },
50
- expireAt: {
51
- type: Date,
52
- required: true,
53
- },
54
50
  academicCalendarId: {
55
51
  type: String,
56
52
  required: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kipicore/dbcore",
3
- "version": "1.1.139",
3
+ "version": "1.1.141",
4
4
  "description": "Reusable DB core package with Postgres, MongoDB, models, services, interfaces, and types",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",