refactor(routes/api/recovery_codes): use .map instead of .forEach

it doesn't make sense to use a forEach here, when all we do is push values into an array => just use .map directly as it returns an array
This commit is contained in:
Panagiotis Papadopoulos 2025-04-09 09:24:28 +02:00
parent 05917fd815
commit 68ea84a2cb

View File

@ -43,12 +43,10 @@ function getUsedRecoveryCodes() {
const dateRegex = RegExp(/^\d{4}\/\d{2}\/\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/gm);
const recoveryCodes = recovery_codes.getRecoveryCodes();
const usedStatus: string[] = [];
recoveryCodes.forEach((recoveryKey: string) => {
if (dateRegex.test(recoveryKey)) usedStatus.push(recoveryKey);
else usedStatus.push(String(recoveryCodes.indexOf(recoveryKey)));
});
const usedStatus = recoveryCodes.map(recoveryKey => {
return (dateRegex.test(recoveryKey)) ? recoveryKey : String(recoveryCodes.indexOf(recoveryKey))
})
return {
success: true,