AlvaroAsial / JapaneseLearning

1 stars 0 forks source link

refactor variables #10

Closed as-hirose closed 7 months ago

as-hirose commented 7 months ago

https://github.com/AlvaroAsial/JapaneseLearning/blob/b9ec51ef1fb9660f579a72c1da4853e5b072846f/src/Main.js#L71-L72

The order of the elements in the array has a specific meaning, but I think it would be easier to understand if it were divided into three variables.

Also, embedding JS code in SQL is a little bit difficult to read, so it might be better to keep it to just filling in variables. It would also be easier to read if you insert line breaks where appropriate. For example:

                    const table = `charProgression${currentPage.charAt(0).toUpperCase() + currentPage.slice(1)}`;
                    const addLevel = count[0];
                    const character = userResponses[i][0];
                    const pronunciation = userResponses[i][0];
                    const minLevel = count[1];
                    const maxLevel = count[2];
                    await db?.query(`UPDATE ${table}
                                        SET level = level ${addLevel}
                                      WHERE (character = '${character}' OR pronunciation = '${pronunciation}')
                                        AND ${minLevel} < level
                                        AND level < ${maxLevel};`);

Also, it's basically better to use placeholders for SQL execution, to prevent SQL injection.