MCPcopy Create free account
hub / github.com/CloudBoost/cloudboost / _getModifiedDocs

Function _getModifiedDocs

services/cloudObjects.js:825–943  ·  view source on GitHub ↗
(document, unModDoc)

Source from the content-addressed store, hash-verified

823}
824
825function _getModifiedDocs(document, unModDoc) {
826 try {
827 let modifiedDocument = [];
828 /* check for isModified with id so as to ensure that if document is modified or it is created
829 as a newly created document will have isModified as false */
830 let doc = {};
831 if (document._isModified) {
832 const modifiedColumns = document._modifiedColumns;
833
834 if (!document.createdAt) {
835 document.createdAt = new Date();
836 if (modifiedColumns.indexOf('createdAt') === -1) modifiedColumns.push('createdAt');
837 }
838 if (!document.expires) {
839 document.expires = null;
840 if (modifiedColumns.indexOf('expires') === -1) modifiedColumns.push('expires');
841 }
842 document.updatedAt = new Date();
843 if (modifiedColumns.indexOf('updatedAt') === -1) {
844 modifiedColumns.push('updatedAt');
845 }
846 modifiedColumns.push('_version');
847
848 doc = {};
849
850 for (var key in document) {
851 // Push in the basic fields as they are not there in Modified Array
852 if (key === '_id' || key === '_type' || key === '_tableName' || key === '_isModified' || key === '_modifiedColumns') {
853 doc[key] = document[key];
854 // Check if it is a List of Relation's if yes then just have the basic parameter's not all
855 } else if (modifiedColumns.indexOf(key) >= 0) {
856 if (document[key] !== null && document[key].constructor === Array && document[key].length > 0) {
857 if (document[key][0]._type && document[key][0]._tableName) {
858 var subDoc = [];
859
860 // get the unique objects
861 document[key] = _getUniqueObjects(document[key]);
862
863 for (var i = 0; i < document[key].length; i++) {
864 var temp = {};
865 temp._type = document[key][i]._type;
866 temp._tableName = document[key][i]._tableName;
867 temp._id = document[key][i]._id;
868 subDoc.push(temp);
869 }
870 doc[key] = subDoc;
871 } else if (document[key][0]._type && document[key][0]._type === 'file') {
872 var subDoc = [];
873 for (var i = 0; i < document[key].length; i++) {
874 var temp = {};
875 temp._type = document[key][i]._type;
876 temp._id = document[key][i]._id;
877 subDoc.push(temp);
878 }
879 doc[key] = subDoc;
880 } else {
881 doc[key] = document[key];
882 }

Callers 1

_saveFunction · 0.85

Calls 2

_getUniqueObjectsFunction · 0.85
_stripChildDocsFunction · 0.85

Tested by

no test coverage detected