.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],
  Promise<UserSSHKey[]>
> = ({ request }) => {
  return async (user) => {
    const keys = await request.prisma.userSSHKey.findMany({
      where: {
        user: { id: user.id },
      },
      orderBy: {
        updatedAt: "desc",
      },
    });

    return keys;
  };
};

export default getUserSSHKeys;