Review generated dashboard loader

from Modern JavaScript features
Node 24 advanced 6 min 4 issues to find

Review this generated dashboard loader before it reaches an account boundary.

Accept an omitted account, preserve zero retries, return only id, email, retries, theme, and orderCount, never expose credentials, never mutate API data, and load the account and orders concurrently.

JavaScript
function prepareAccount(input) {
  const { password, ...account } = input;
  const output = {
    ...account,
    retries: input.retries || 3,
  };
  output.preferences.theme ??= 'light';
  return output;
}

async function loadDashboard(api, id) {
  const [account, orders] = await Promise.all([
    api.account(id),
    api.orders(id),
  ]);

  return {
    ...prepareAccount(account),
    orderCount: orders.length,
  };
}

generated code is illustrative, not from any one model

Open in playground
Report an error