@memberjunction/server 2.2.1 → 2.3.1

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.
@@ -559,9 +559,7 @@ export class ResolverBase {
559
559
  }); // grab all the props except for the OldValues property
560
560
 
561
561
  if (entityInfo.TrackRecordChanges || !input.OldValues___) {
562
- // the entity tracks record changes, so we need to load the old values from the DB to make sure they are not inconsistent
563
- // with the old values from the input.OldValues property. If they are different, but on different fields, we allow it
564
- // but if they are different on fields that the current UpdateRecord call is trying to update, we throw an error.
562
+ // We get here because EITHER the entity tracks record changes OR the client did not provide OldValues, so we need to load the old values from the DB
565
563
  const cKey = new CompositeKey(
566
564
  entityInfo.PrimaryKeys.map((pk) => {
567
565
  return {
@@ -572,13 +570,14 @@ export class ResolverBase {
572
570
  );
573
571
 
574
572
  if (await entityObject.InnerLoad(cKey)) {
575
- // load worked, now, if we HAVE OldValues, we need to check them against the values in the DB we just loaded.
576
- if (!input.OldValues___) {
577
- // no OldValues, so we can just set the new values from input
578
- entityObject.SetMany(input);
579
- } else {
573
+ // load worked, now, only IF we have OldValues, we need to check them against the values in the DB we just loaded.
574
+ if (input.OldValues___) {
580
575
  // we DO have OldValues, so we need to do a more in depth analysis
581
576
  this.TestAndSetClientOldValuesToDBValues(input, clientNewValues, entityObject);
577
+ }
578
+ else {
579
+ // no OldValues, so we can just set the new values from input
580
+ entityObject.SetMany(input);
582
581
  }
583
582
  } else {
584
583
  // save failed, return null
@@ -586,8 +585,9 @@ export class ResolverBase {
586
585
  extensions: { code: 'LOAD_ENTITY_ERROR', entityName },
587
586
  });
588
587
  }
589
- } else {
590
- // not tracking changes and we DO have OldValues, so we can load from them
588
+ }
589
+ else {
590
+ // we get here if we are NOT tracking changes and we DO have OldValues, so we can load from them
591
591
  const oldValues = {};
592
592
  // for each item in the oldValues array, add it to the oldValues object
593
593
  input.OldValues___?.forEach((item) => (oldValues[item.Key] = item.Value));