()
| 539 | }; |
| 540 | |
| 541 | const addUsersCountAndCreatedAt = async () => { |
| 542 | const taskRequestsSnapshots = (await taskRequestsCollection.get()).docs; |
| 543 | |
| 544 | const bulkWriter = firestore.bulkWriter(); |
| 545 | let documentsModified = 0; |
| 546 | const totalDocuments = taskRequestsSnapshots.length; |
| 547 | taskRequestsSnapshots.forEach((taskRequestsSnapshot) => { |
| 548 | const taskRequestData = taskRequestsSnapshot.data(); |
| 549 | let isDocumentModified = false; |
| 550 | if (!taskRequestData.usersCount) { |
| 551 | taskRequestData.usersCount = taskRequestData.users.length; |
| 552 | isDocumentModified = true; |
| 553 | } |
| 554 | if (!taskRequestData.createdAt) { |
| 555 | taskRequestData.createdAt = taskRequestsSnapshot.createTime.toMillis(); |
| 556 | isDocumentModified = true; |
| 557 | } |
| 558 | |
| 559 | if (isDocumentModified) { |
| 560 | bulkWriter.update(taskRequestsCollection.doc(taskRequestsSnapshot.id), taskRequestData); |
| 561 | documentsModified++; |
| 562 | } |
| 563 | }); |
| 564 | |
| 565 | await bulkWriter.close(); |
| 566 | return { documentsModified, totalDocuments }; |
| 567 | }; |
| 568 | const removeOldField = async () => { |
| 569 | const taskRequestsSnapshots = (await taskRequestsCollection.get()).docs; |
| 570 |
no test coverage detected