| 782 | } |
| 783 | |
| 784 | function _generateId(document, reqType) { |
| 785 | try { |
| 786 | if (document._type) { |
| 787 | if (!document._id) { |
| 788 | let id; |
| 789 | if (document._hash) { |
| 790 | id = document._hash; |
| 791 | delete document._hash; |
| 792 | } else id = util.getId(); |
| 793 | document._id = id; |
| 794 | reqType.save.push(id); |
| 795 | } else { |
| 796 | reqType.update.push(document._id); |
| 797 | } |
| 798 | } |
| 799 | for (const key in document) { |
| 800 | if (document[key]) { |
| 801 | if (document[key].constructor === Array && document[key].length) { |
| 802 | for (let i = 0; i < document[key].length; i++) { |
| 803 | if (document[key][i]._tableName) { |
| 804 | _generateId(document[key][i], reqType); |
| 805 | } |
| 806 | } |
| 807 | } |
| 808 | if (typeof document[key] === 'object' && document[key] != null) { |
| 809 | if (document[key]._type) { |
| 810 | _generateId(document[key], reqType); |
| 811 | } |
| 812 | } |
| 813 | } |
| 814 | } |
| 815 | return document; |
| 816 | } catch (err) { |
| 817 | winston.log('error', { |
| 818 | error: String(err), |
| 819 | stack: new Error().stack, |
| 820 | }); |
| 821 | return null; |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | function _getModifiedDocs(document, unModDoc) { |
| 826 | try { |