.ts
TypeScript
(application/typescript)
// 1st-party
import type { ServiceMethodFactory } from "@ethicdevs/react-monolith";
// app
import type { AuthServiceDeps } from "./types";

const makeIsExistingUsername: ServiceMethodFactory<
  AuthServiceDeps,
  [string],
  Promise<boolean>
> = ({ request }) => {
  return async (username) => {
    const matchingUser = await request.prisma.user.findUnique({
      select: {
        id: true,
      },
      where: {
        username,
      },
    });
    return matchingUser != null;
  };
};

export default makeIsExistingUsername;