@clairejs/server 3.28.5 → 3.28.7

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.
package/README.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## Change Log
2
2
 
3
+ #### 3.28.7
4
+
5
+ - fix update records with hasMany field
6
+
7
+ #### 3.28.6
8
+
9
+ - fix calling stripData in with null / undefined
10
+
3
11
  #### 3.28.5
4
12
 
5
13
  - implement new job scheduler
@@ -49,7 +49,7 @@ let DefaultHttpRequestHandler = class DefaultHttpRequestHandler extends Abstract
49
49
  });
50
50
  const response = await endpoint.controller[endpoint.name](...params);
51
51
  //-- validate response value against response dto
52
- if (endpoint.responseDto) {
52
+ if (endpoint.responseDto && response.value !== null && response.value !== undefined) {
53
53
  response.value = stripData(response.value, endpoint.responseDto);
54
54
  }
55
55
  return response;
@@ -510,7 +510,7 @@ export class ModelRepository extends AbstractRepository {
510
510
  const adapter = this.db.use(model, tx);
511
511
  const allInnerRecords = await adapter.getRecords({ _eq: { [field.hasMany.column]: theRecord.id } }, { limit: field.hasMany?.single ? 1 : undefined });
512
512
  const currentIds = allInnerRecords.map((r) => r.id);
513
- const newIds = innerUpdates.map((r) => r.id).filter((id) => !!id);
513
+ const newIds = innerUpdates.flatMap((r) => (r.id ? [r.id] : []));
514
514
  const tobeRemovedIds = currentIds.filter((id) => !newIds.includes(id));
515
515
  const tobeAdded = innerUpdates
516
516
  .filter((r) => !r.id)
@@ -537,7 +537,10 @@ export class ModelRepository extends AbstractRepository {
537
537
  //-- return the new inners records
538
538
  const finalInnerRecords = tobeAdded
539
539
  .map((toAdd, index) => ({ ...toAdd, ...added.records[index] }))
540
- .concat(updatedToBeKept.map((r) => r.modified[0]));
540
+ .concat(tobeKept.map((tbk) => {
541
+ const matched = updatedToBeKept.find((utbk) => utbk.modified[0].id === tbk.id);
542
+ return { ...tbk, ...matched };
543
+ }));
541
544
  theRecord[field.name] = (field.hasMany?.single ? finalInnerRecords[0] : finalInnerRecords);
542
545
  }
543
546
  //-- ok clean up
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clairejs/server",
3
- "version": "3.28.5",
3
+ "version": "3.28.7",
4
4
  "description": "Claire server NodeJs framework written in Typescript.",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",