Repository: freeCodeCamp/freeCodeCamp
File: api/src/routes/public/email-subscription.ts (TypeScript)

Code before:
        });

        if (!unsubUsers.length) {
          log.warn('No users found for unsubscribe request');
          void reply.code(302);
          return reply.redirectWithMessage(origin, {
            type: 'info',
            content: 'We could not find an account to unsubscribe.'
          });
        }

        log.info(`Found ${unsubUsers.length} user(s) to unsubscribe`);
        const userUpdatePromises = unsubUsers.map(user =>
          fastify.prisma.user.updateMany({
            where: { email: user.email },
            data: {
              sendQuincyEmail: false
            }
          })
        );

        await Promise.all(userUpdatePromises);
        log.info(
          `Successfully unsubscribed users from email: ${unsubUsers.map(user => user.email).join(', ')}`
        );

        return reply.redirectWithMessage(
          `${origin}/unsubscribed/${unsubscribeId}`,
          {
            type: 'success',
            content: "We've successfully updated your email preferences."
          }
        );
      } catch (error) {
        fastify.log.error(error, 'Failed to unsubscribe user from email');
        fastify.Sentry.captureException(error);
        void reply.code(302);
        return reply.redirectWithMessage(origin, {
          type: 'danger',
          content: `Failed to unsubscribe user, please contact support at support@freecodecamp.org`
        });
      }
    }
  );

  fastify.get(
    '/resubscribe/:unsubscribeId',
    {
      schema: schemas.resubscribe,
      errorHandler(error, request, reply) {
        if (error.validation) {

Review comment (suggestion):
This is a nit, but I think majority of the logs look nicer is the dynamic data is logged as such:

```suggestion
        log.info({ emails: unsubUsers.map(u => u.email) }, 'Successfully unsubscribed users from email.');
```

I would not nit the same about `Found ${unsubUsers.length} users ...`, because that is simple/small enough to not make enough of a difference.

_Again, up to you_

Code after:
        });

        if (!unsubUsers.length) {
          log.warn('No users found for unsubscribe request');
          void reply.code(302);
          return reply.redirectWithMessage(origin, {
            type: 'info',
            content: 'We could not find an account to unsubscribe.'
          });
        }

        log.info(`Found ${unsubUsers.length} user(s) to unsubscribe`);
        const userUpdatePromises = unsubUsers.map(user =>
          fastify.prisma.user.updateMany({
            where: { email: user.email },
            data: {
              sendQuincyEmail: false
            }
          })
        );

        await Promise.all(userUpdatePromises);
        log.info(
          { emails: unsubUsers.map(u => u.email) },
          'Successfully unsubscribed users from email.'
        );

        return reply.redirectWithMessage(
          `${origin}/unsubscribed/${unsubscribeId}`,
          {
            type: 'success',
            content: "We've successfully updated your email preferences."
          }
        );
      } catch (error) {
        fastify.log.error(error, 'Failed to unsubscribe user from email');
        fastify.Sentry.captureException(error);
        void reply.code(302);
        return reply.redirectWithMessage(origin, {
          type: 'danger',
          content: `Failed to unsubscribe user, please contact support at support@freecodecamp.org`
        });
      }
    }
  );

  fastify.get(
    '/resubscribe/:unsubscribeId',
    {
      schema: schemas.resubscribe,
      errorHandler(error, request, reply) {