mirror of
https://github.com/hanzoai/captable.git
synced 2026-10-16 14:21:29 +00:00
chore: revert
This commit is contained in:
@@ -1,51 +1,56 @@
|
||||
import { withMemberAuth } from "@/server/api/auth";
|
||||
import { ErrorResponses } from "@/server/api/error";
|
||||
import { withCompanyAuth } from "@/server/api/auth";
|
||||
import { ApiError, ErrorResponses } from "@/server/api/error";
|
||||
import type { PublicAPI } from "@/server/api/hono";
|
||||
import { ApiCompanySchema } from "@/server/api/schema/company";
|
||||
import { db } from "@/server/db";
|
||||
import { createRoute, z } from "@hono/zod-openapi";
|
||||
import type { Company } from "@prisma/client";
|
||||
import type { Context } from "hono";
|
||||
|
||||
export const RequestSchema = z.object({
|
||||
id: z
|
||||
.string()
|
||||
.cuid()
|
||||
.openapi({
|
||||
description: "Company ID",
|
||||
param: {
|
||||
name: "id",
|
||||
in: "path",
|
||||
},
|
||||
|
||||
example: "clxwbok580000i7nge8nm1ry0",
|
||||
}),
|
||||
});
|
||||
|
||||
const route = createRoute({
|
||||
method: "get",
|
||||
path: "/v1/companies",
|
||||
path: "/v1/companies/:id",
|
||||
request: { params: RequestSchema },
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.array(ApiCompanySchema).openapi({
|
||||
description: "List of companies",
|
||||
}),
|
||||
schema: ApiCompanySchema,
|
||||
},
|
||||
},
|
||||
description: "List companies",
|
||||
description: "Get a company by ID",
|
||||
},
|
||||
|
||||
...ErrorResponses,
|
||||
},
|
||||
});
|
||||
const getMany = (app: PublicAPI) => {
|
||||
const getOne = (app: PublicAPI) => {
|
||||
app.openapi(route, async (c: Context) => {
|
||||
const { membership } = await withMemberAuth(c);
|
||||
const companyIds = membership.map((m) => m.companyId);
|
||||
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
||||
const { company } = (await withCompanyAuth(c)) as { company: any };
|
||||
|
||||
const companies = (await db.company.findMany({
|
||||
where: {
|
||||
id: {
|
||||
in: companyIds,
|
||||
},
|
||||
},
|
||||
})) as Company[];
|
||||
if (!company) {
|
||||
throw new ApiError({
|
||||
code: "NOT_FOUND",
|
||||
message: "Company not found",
|
||||
});
|
||||
}
|
||||
|
||||
const response = companies.map((company) => ({
|
||||
...company,
|
||||
logo: company.logo ?? undefined,
|
||||
website: company.website ?? undefined,
|
||||
}));
|
||||
|
||||
return c.json(response, 200);
|
||||
return c.json(company, 200);
|
||||
});
|
||||
};
|
||||
|
||||
export default getMany;
|
||||
export default getOne;
|
||||
|
||||
Reference in New Issue
Block a user