Repository: freeCodeCamp/freeCodeCamp
File: api/src/routes/protected/user.ts (TypeScript)

Code before:
        where: { userId: req.user.id }
      });
      await fastify.prisma.survey.deleteMany({
        where: { userId: req.user.id }
      });
      try {
        await fastify.prisma.user.delete({
          where: { id: req.user.id }
        });
      } catch (err) {
        if (
          err instanceof PrismaClientKnownRequestError &&
          err.code === 'P2025'
        ) {
          logger.warn(
            err,
            `User with id ${req.user?.id} not found for deletion.`
          );
        } else {
          logger.error(err, 'Error deleting user account');
          throw err;
        }
      }
      reply.clearOurCookies();

      return {};
    }
  );

  fastify.post(
    '/account/reset-progress',
    {
      schema: schemas.resetMyProgress
    },
    async (req, reply) => {
      const logger = fastify.log.child({ req, res: reply });
      logger.info(`User ${req.user?.id} requested progress reset`);
      await fastify.prisma.userToken.deleteMany({
        where: { userId: req.user!.id }
      });
      await fastify.prisma.msUsername.deleteMany({
        where: { userId: req.user!.id }
      });
      await fastify.prisma.survey.deleteMany({
        where: { userId: req.user!.id }
      });
      await fastify.prisma.user.update({
        where: { id: req.user!.id },
        data: createResetProperties()
      });


Review comment (suggestion):
It is common for `DELETE`s to return no body with a status of `204`:
> https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/DELETE#successfully_deleting_a_resource

```suggestion
      return reply.code(204);
```

Code after:
        });
        await fastify.prisma.msUsername.deleteMany({
          where: { userId: req.user.id }
        });
        await fastify.prisma.survey.deleteMany({
          where: { userId: req.user.id }
        });
        await fastify.prisma.user.delete({
          where: { id: req.user.id }
        });
      } catch (err) {
        // Whilst this is behind auth, this should never happen
        if (
          err instanceof PrismaClientKnownRequestError &&
          err.code === 'P2025'
        ) {
          logger.warn(
            err,
            `User with id ${req.user?.id} not found for deletion.`
          );
          return reply.code(404).send({ type: 'error', message: 'not found' });
        } else {
          logger.error(err, 'Error deleting user account');
          throw err;
        }
      }
      reply.clearOurCookies();

      return reply.code(204).send();
    }
  );

  fastify.post(
    '/account/reset-progress',
    {
      schema: schemas.resetMyProgress
    },
    async (req, reply) => {
      const logger = fastify.log.child({ req, res: reply });
      logger.info(`User ${req.user?.id} requested progress reset`);
      await fastify.prisma.userToken.deleteMany({
        where: { userId: req.user!.id }
      });
      await fastify.prisma.msUsername.deleteMany({
        where: { userId: req.user!.id }
      });
      await fastify.prisma.survey.deleteMany({
        where: { userId: req.user!.id }
      });
      await fastify.prisma.user.update({
        where: { id: req.user!.id },