Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
20a48cc
feat: add convertible note schema
G3root Aug 12, 2024
e51b1fb
feat: add register
G3root Aug 12, 2024
f18f246
feat: add create convertible note
G3root Aug 12, 2024
09ba976
feat: add basic modal
G3root Aug 12, 2024
1c47e68
chore: fix schema
G3root Aug 12, 2024
d426ee7
chore: fix formatting
G3root Aug 12, 2024
fba122b
feat: add basic fields
G3root Aug 12, 2024
9d93350
feat: add basic form
G3root Aug 13, 2024
bf85928
feat: add hooks
G3root Aug 13, 2024
7d87a02
feat: add file uploader component
G3root Aug 13, 2024
7c00b32
feat: add document step
G3root Aug 13, 2024
280048b
feat: add api client
G3root Aug 13, 2024
860a5c7
feat: add document step
G3root Aug 13, 2024
ebd8f34
fix: api client
G3root Aug 14, 2024
243996b
feat: make header optional
G3root Aug 14, 2024
793ab83
fix: schema
G3root Aug 14, 2024
4875829
fix: auth
G3root Aug 14, 2024
c63d8f8
chore: add ky
G3root Aug 14, 2024
e6d5cd5
feat: add api client
G3root Aug 14, 2024
1b49d96
feat: add api client
G3root Aug 14, 2024
597f5ab
feat: add handler utility
G3root Aug 14, 2024
b55c22e
fix: schema
G3root Aug 14, 2024
72c0159
chore: remove modal
G3root Aug 14, 2024
ae4af43
feat: update modal
G3root Aug 14, 2024
6f75f9e
fix: formatting
G3root Aug 14, 2024
37b5198
fix: client
G3root Aug 15, 2024
72b8e8f
feat: add get many route and handler
G3root Aug 15, 2024
8654bbe
feat: add no store option
G3root Aug 15, 2024
c1b5dcb
feat: add limit
G3root Aug 15, 2024
aa5c090
chore: remove ky
G3root Aug 15, 2024
485a60c
feat: add delete step
G3root Aug 15, 2024
0806365
feat: add refresh
G3root Aug 15, 2024
df381fd
chore: add notes
G3root Aug 15, 2024
9cf947e
feat: add upload
G3root Aug 15, 2024
784fd51
feat: add session
G3root Aug 15, 2024
582821c
feat: add handler
G3root Aug 15, 2024
d413da5
Merge branch 'main' into convertible-notes
G3root Aug 15, 2024
6f7d7ea
chore: upgrade packages
G3root Aug 15, 2024
7c5f3fc
feat: close
G3root Aug 15, 2024
d513408
fix: combobox
G3root Aug 15, 2024
1096aef
feat: add dialog provider
G3root Aug 15, 2024
72efb92
fix: prop
G3root Aug 15, 2024
6fa68ee
feat: fix logic
G3root Aug 15, 2024
9ea3519
fix: type
G3root Aug 15, 2024
d1b698b
fix: logic handling
G3root Aug 15, 2024
2fd9f69
fix: type
G3root Aug 15, 2024
a03bafb
feat: revert
G3root Aug 16, 2024
88ed9cf
feat: improve
G3root Aug 16, 2024
65a3ae8
feat: add loading state
G3root Aug 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add get many route and handler
  • Loading branch information
G3root committed Aug 15, 2024
commit 72b8e8f1e6e59e1187ce9c66d33501ca82a8b42b
18 changes: 18 additions & 0 deletions src/server/api/client-handlers/convertible-note.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type APIClientParams, createClient } from "../api-client";
import type { create } from "../routes/convertible-note/create";
import type { getMany } from "../routes/convertible-note/getMany";

type CreateRoute = typeof create.route;

Expand All @@ -15,3 +16,20 @@ export type TCreateConvertibleNoteParams = APIClientParams<CreateRoute>;
export type TCreateConvertibleNoteRes = Awaited<
ReturnType<typeof createConvertibleNote>
>;

type GetManyRoute = typeof getMany.route;

export const getManyConvertibleNote = (
params: TGetManyConvertibleNoteParams,
) => {
return createClient<GetManyRoute>(
"get",
"/v1/{companyId}/convertible-notes",
params,
);
};

export type TGetManyConvertibleNoteParams = APIClientParams<GetManyRoute>;
export type TGetManyConvertibleNoteRes = Awaited<
ReturnType<typeof getManyConvertibleNote>
>;
84 changes: 84 additions & 0 deletions src/server/api/routes/convertible-note/getMany.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { z } from "@hono/zod-openapi";
import { ConvertibleNoteSchemaWithStakeHolder } from "../../schema/convertible-note";
import {
PaginationQuerySchema,
PaginationResponseSchema,
} from "../../schema/pagination";
import { authMiddleware, withAuthApiV1 } from "../../utils/endpoint-creator";

const ResponseSchema = z.object({
data: z.array(ConvertibleNoteSchemaWithStakeHolder),
meta: PaginationResponseSchema,
});

const ParamsSchema = z.object({
companyId: z.string().openapi({
param: {
name: "companyId",
in: "path",
},
description: "Company ID",
type: "string",
example: "clxwbok580000i7nge8nm1ry0",
}),
});

export const getMany = withAuthApiV1
.createRoute({
summary: "List convertible notes",
description:
"Retrieve a paginated list of all convertible notes in the company.",
tags: ["Convertible Notes"],
method: "get",
path: "/v1/{companyId}/convertible-notes",
middleware: [authMiddleware()],
request: {
query: PaginationQuerySchema,
params: ParamsSchema,
},
responses: {
200: {
content: {
"application/json": {
schema: ResponseSchema,
},
},
description:
"A list of convertible notes in a company with their details.",
},
},
})
.handler(async (c) => {
const { membership } = c.get("session");
const { db } = c.get("services");
const query = c.req.valid("query");

const [data, meta] = await db.convertibleNote
.paginate({
where: { companyId: membership.companyId },
include: { stakeholder: { select: { name: true } } },
})
.withCursor({
limit: query.limit,
after: query.cursor,
getCursor({ id }) {
return id;
},
parseCursor(cursor) {
return { id: cursor };
},
});

const response: z.infer<typeof ResponseSchema> = {
data: data.map((note) => ({
...note,
createdAt: note.createdAt.toISOString(),
updatedAt: note.updatedAt.toISOString(),
issueDate: note.issueDate.toISOString(),
boardApprovalDate: note.boardApprovalDate.toISOString(),
})),
meta,
};

return c.json(response, 200);
});
5 changes: 4 additions & 1 deletion src/server/api/routes/convertible-note/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { OpenAPIHono } from "@hono/zod-openapi";
import { create } from "./create";
import { getMany } from "./getMany";

export const registerConvertibleNotesRoutes = (api: OpenAPIHono) =>
api.openapi(create.route, create.handler);
api
.openapi(create.route, create.handler)
.openapi(getMany.route, getMany.handler);
8 changes: 8 additions & 0 deletions src/server/api/schema/convertible-note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ export const CreateConvertibleNotesSchema = ConvertibleNoteSchema.omit({
export type TCreateConvertibleNotesSchema = z.infer<
typeof CreateConvertibleNotesSchema
>;

export const ConvertibleNoteSchemaWithStakeHolder = z
.object({
stakeholder: z.object({
name: z.string(),
}),
})
.merge(ConvertibleNoteSchema);