.ts
TypeScript
(application/typescript)
// 1st-party
import type { ServiceMethodFactory } from "@ethicdevs/react-monolith";
// generated via script[generate:prisma]
import { User, UserSSHKey } from "@prisma/client";
// app
import type { UsersServiceDeps } from "./types";

const getUserSSHKeys: ServiceMethodFactory<
  UsersServiceDeps,
  [User, ("active" | "revoked" | "all")?],
  Promise<UserSSHKey[]>
> = ({ request }) => {
  return async (user, filter = "active") => {
    const keys = await request.prisma.userSSHKey.findMany({
      where: {
        user: { id: user.id },
        revoked: filter == "revoked",
      },
      orderBy: {
        updatedAt: "desc",
      },
    });

    return keys;
  };
};

export default getUserSSHKeys;