| 945 | /* this function checks returns a document with all its sub-documents removed from it. In case of sub-documents |
| 946 | it leaves the basic values like id, tableName and type */ |
| 947 | function _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 | |
| 989 | function _deleteRollback(appId, document, res) { |
| 990 | const deferred = q.defer(); |