Skip to content

Conversation

@shakilhossain1
Copy link
Collaborator

No description provided.

const service = await models.Service.findByPk(serviceId);
if (!service) return;

// NOTE: We need to also check if its already associated to other taxonomy. we probably want to delete this record. for now I'm skipping that.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shakilhossain1 Probably need to address this comment and delete existing record when it exists.

}
);

taxonomy.services.forEach(async (serviceId) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't use foreach hear. See google's answer below:

While you can pass an async function as a callback to Array.prototype.forEach(), forEach() itself is not designed to handle asynchronous operations and will not wait for the promises returned by the async callback to resolve.
Explanation:

    forEach is synchronous:
    The forEach method iterates through the array and calls the provided callback function for each element in a synchronous manner. It does not inherently understand or manage asynchronous operations.
    async callback returns a Promise:
    When you pass an async function as the callback to forEach, that async function will immediately return a Promise.
    forEach does not await Promises:
    forEach does not wait for these returned Promises to resolve or reject. It simply calls the async function, gets the Promise, and then moves on to the next element in the array. This means that the code following the forEach loop will execute before any of the asynchronous operations within the forEach callback have completed.
    Unhandled Promises:
    If an error occurs within an async callback inside forEach and the returned Promise is not handled (e.g., with a .catch() or by being awaited in a different context), it can lead to unhandled promise rejections. 

Alternatives for Asynchronous Iteration:

    for...of loop: For sequential execution of asynchronous operations, for...of loops are the recommended approach as they allow you to await each asynchronous operation within the loop. 

JavaScript

    async function processItemsSequentially(items) {
        for (const item of items) {
            await doSomethingAsync(item);
        }
        console.log("All items processed sequentially.");
    }

    Promise.all() with Array.prototype.map(): For parallel execution of asynchronous operations, Promise.all() combined with map() is the appropriate choice. map() creates an array of Promises, and Promise.all() waits for all of them to resolve. 

JavaScript

    async function processItemsInParallel(items) {
        const promises = items.map(async (item) => {
            await doSomethingAsync(item);
        });
        await Promise.all(promises);
        console.log("All items processed in parallel.");
    }

Comment on lines 234 to 241
name: "Transitional Independent Living",
parent_name: "Shelter",
parent_id: "228d5932-634e-48b4-a2bd-d5f0a74730c7",
services: [
"dd733e25-1442-4306-b745-db3c2dc9b2da",
"e943b886-1005-49a5-9e71-3825ac87877e",
],
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name: "Transitional Independent Living",
parent_name: "Shelter",
parent_id: "228d5932-634e-48b4-a2bd-d5f0a74730c7",
services: [
"dd733e25-1442-4306-b745-db3c2dc9b2da",
"e943b886-1005-49a5-9e71-3825ac87877e",
],
},

Remove duplicate.

],
},
{
name: "Transitional Independent Living",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name: "Transitional Independent Living",
name: "Transitional Independent Living (TIL)",


taxonomy.services.forEach(async (serviceId) => {
const service = await models.Service.findByPk(serviceId);
if (!service) return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will want to migrate the .forEach to a for...of loop, and change this return statement to a continue statement in order skip the service if it does not exist.

@jbeard4
Copy link
Member

jbeard4 commented Oct 24, 2025

It will be fine to run this in dev. We want to QA the following service ids that are available in both dev and prod:

00251f03-dac4-4ac3-8592-30e24b756c75
01d57b99-79cf-4eea-96ee-a44351aeafab
03d36f39-8142-40ed-98ae-fc218da91679
064c76c0-02d8-4f3e-bfbc-89c61e015ae3
0e9077d5-a563-4c54-89d3-39c7f808b412
15a5cb70-2a08-4065-af88-5318aaf5c41c
1f2e084f-cc12-48fa-9f17-8fd14a03428c
227c22dc-8f84-46ff-8fb9-bc46fcf13fea
2ed3b0fb-90df-4c74-bd3e-61890688ba30
2f53f8a5-584d-4b2f-81a6-2d62f0dfbd0f
34e73653-8a4f-478a-88d8-5f89c612c48b
39087b61-55b1-4027-98b7-5dce5b09042f
39cbb9db-7bc8-45c0-80f6-e5beccb2c0d4
3ac3e688-f033-40e3-bda3-d12e92fcba70
48de48ee-5c17-4249-9d25-bb1e368839cb
5053ca3b-50a3-4970-b0fe-1e57ba660f7f
515f1025-8d78-46f0-a7e4-80fd612dc68d
58d8cc0b-12a3-4dec-883d-771e96baae32
60c5a572-4d2d-4c77-898e-7b4433a3dc1e
6435c9fd-eb71-4806-abce-6fa0feb7124c
6593d85a-d2ec-4340-8704-66de677b5d69
6ba8a8bb-d05c-46a0-8988-964fbaa1b541
6ba94bd0-edff-48fb-b1b5-dd6aa051717e
6e881ccf-1c04-465b-9ad4-c8b4de4af5a6
700a7e15-fc4a-47f5-ad00-20f027b497b3
7011c427-1188-406c-9fc4-2f706fe97899
7543b322-18b7-4bf8-a229-58c01bc915f6
764dd286-7aa5-4fc2-ab23-5b3b28bea842
7f3d3b57-c901-437a-9a69-c2ba11e50f43
8459ca1a-3c92-47d3-bee7-52a5edcd0917
8a087fde-dfb2-4138-80b1-f8acf97af9d6
94823c07-e57f-4a67-8612-7f4ca3645af3
971e82f3-257f-4353-bc16-4d234ec52022
9e821bc0-0a9f-43ca-b2b6-4628e81ca2fc
9f2d4712-5bd9-4733-bf4e-a3797c32b91b
aa3d0e89-30bf-4a4c-8e5b-48d7bb12b05e
af06ff67-257c-488a-a644-cdd56d6204a5
b02f4bdb-5aa3-44e5-b3c5-fa71220e0239
b7159928-c4f1-4ff0-8cd1-b20df75e8c9e
b8520f93-cec8-4c36-8dc8-4dd1dbe5ecbd
ba67bea9-3b47-4312-b3a6-066d486a772e
bb6809f0-73d4-4301-ad03-3e659b8b5a61
bbebe4bc-1e75-4c17-9ff0-81e8913654a8
bc2056c2-c14e-4a58-a351-4cc37eb861a0
bf7ad853-360e-4c08-8f16-5f2b7205da46
c1b69833-402e-4ab9-ae14-d927628bddf5
c4787536-edba-4ef8-b86a-4dda878e83dc
c564bd7e-8a0d-4fd8-a17a-139767b599a0
d024c089-4ab5-4428-8d04-5adbe8d02e6d
d19a2743-cde6-45e7-8e1f-01b56f12614d
d464d037-f253-480f-88f3-ebb1ea8c4f20
d51dea49-8879-44b2-a126-64573d88efcb
da26f3f1-48eb-46a6-81c7-9d1f6cc5af93
dc7a726a-dc93-4237-a5e2-71ee4b3303d5
dd733e25-1442-4306-b745-db3c2dc9b2da
e3de71af-9b79-4b6d-bcb9-d8d9a2011d9e
e415bce3-01dc-4e0b-b9e1-06ae6c890654
e943b886-1005-49a5-9e71-3825ac87877e
f2b4e501-e954-4f87-9281-7d87bf3e72a2
f467f727-6e59-4e32-bbbb-3edd66ab6c07
f49449c9-9295-4b7c-8123-34336e75b0d7
f4e41e59-e0a9-48b6-aaeb-81f51f24a3b7
f8af9137-e68a-4872-929c-f921cb253e3b
ff56dead-c74b-41ec-a2c0-e3865d26d154

jbeard4
jbeard4 previously approved these changes Oct 27, 2025
@jbeard4
Copy link
Member

jbeard4 commented Oct 29, 2025

@adambard1 I ran the migration on dev. Let's QA this in the test environment, and if it looks good, then merge it to master and run the migration in PROD.

@shakilhossain1
Copy link
Collaborator Author

after this we also have merge this pr to add youth in the sidebar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants