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

Function _stripChildDocs

services/cloudObjects.js:947–987  ·  view source on GitHub ↗
(document)

Source from the content-addressed store, hash-verified

945/* this function checks returns a document with all its sub-documents removed from it. In case of sub-documents
946it leaves the basic values like id, tableName and type */
947function _stripChildDocs(document) {
948 try {
949 const doc = {};
950 for (const key in document) {
951 if (document[key] !== null && document[key].constructor === Array && document[key].length > 0) {
952 if (document[key][0]._type && document[key][0]._tableName) {
953 var subDoc = [];
954 for (let i = 0; i < document[key].length; i++) {
955 const temp = {};
956 temp._type = document[key][i]._type;
957 temp._tableName = document[key][i]._tableName;
958 temp._id = document[key][i]._id;
959 subDoc.push(temp);
960 }
961 doc[key] = subDoc;
962 } else {
963 doc[key] = document[key];
964 }
965 } else if (document[key] !== null && document[key].constructor === Object) {
966 if (document[key]._type && document[key]._tableName) {
967 var subDoc = {};
968 subDoc._type = document[key]._type;
969 subDoc._tableName = document[key]._tableName;
970 subDoc._id = document[key]._id;
971 doc[key] = subDoc;
972 } else {
973 doc[key] = document[key];
974 }
975 } else {
976 doc[key] = document[key];
977 }
978 }
979 return doc;
980 } catch (err) {
981 winston.log('error', {
982 error: String(err),
983 stack: new Error().stack,
984 });
985 return null;
986 }
987}
988
989function _deleteRollback(appId, document, res) {
990 const deferred = q.defer();

Callers 1

_getModifiedDocsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected