Skip to content

Commit

Permalink
chore: minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
dahal committed Aug 11, 2024
1 parent 1341e07 commit 4925057
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 88 deletions.
7 changes: 6 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ model BankAccount {
companyId String
company Company @relation(fields: [companyId], references: [id], onDelete: Cascade)
safes Safe[]
@@unique([companyId, accountNumber])
@@unique([companyId, primary], name: "unique_primary_account")
Expand Down Expand Up @@ -829,7 +830,7 @@ enum SafeTemplateEnum {

model Safe {
id String @id @default(cuid())
publicId String // eg. SAFE-01
publicId String? // eg. SAFE-01
type SafeTypeEnum @default(POST_MONEY)
status SafeStatusEnum @default(DRAFT)
capital Float // Amount of money invested
Expand All @@ -850,6 +851,9 @@ model Safe {
companyId String
company Company @relation(fields: [companyId], references: [id], onDelete: Cascade)
bankAccountId String
bankAccount BankAccount @relation(fields: [bankAccountId], references: [id], onDelete: Cascade)
issueDate DateTime
boardApprovalDate DateTime?
createdAt DateTime @default(now())
Expand All @@ -858,6 +862,7 @@ model Safe {
@@unique([publicId, companyId])
@@index([companyId])
@@index([stakeholderId])
@@index([bankAccountId])
}

enum ConvertibleStatusEnum {
Expand Down
1 change: 1 addition & 0 deletions src/components/common/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const sizes = {
"3xl": "max-w-3xl",
"4xl": "max-w-4xl",
screen: "max-w-[96vw]",
"5xl": "max-w-5xl",
};

export type ModalSizeType = keyof typeof sizes;
Expand Down
6 changes: 4 additions & 2 deletions src/server/api/routes/company/getMany.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export const getMany = withAuthApiV1
200: {
content: {
"application/json": {
schema: z.array(CompanySchema),
schema: z.object({
data: z.array(CompanySchema),
}),
},
},
description: "A list of companies with their details.",
Expand All @@ -36,5 +38,5 @@ export const getMany = withAuthApiV1
},
});

return c.json(companies, 200);
return c.json({ data: companies }, 200);
});
8 changes: 4 additions & 4 deletions src/server/api/routes/safe/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ const ParamsSchema = z.object({
export const create = withAuthApiV1
.createRoute({
method: "post",
path: "/v1/{companyId}/stakeholders",
summary: "Create stakeholders",
description: "Add one or more stakeholder accounts to a company.",
tags: ["Stakeholder"],
path: "/v1/{companyId}/safes",
summary: "Create SAFEs",
description: "Add one or more SAFEs to a company.",
tags: ["SAFEs"],
middleware: [authMiddleware()],
request: {
params: ParamsSchema,
Expand Down
6 changes: 3 additions & 3 deletions src/server/api/routes/safe/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ const ResponseSchema = z.object({

export const _delete = withAuthApiV1
.createRoute({
summary: "Delete a safe",
description: "Remove a safe from a company by ID.",
tags: ["Safe"],
summary: "Delete a SAFE",
description: "Remove a SAFE from a company by ID.",
tags: ["SAFEs"],
method: "delete",
path: "/v1/{companyId}/safes/{id}",
middleware: [authMiddleware()],
Expand Down
6 changes: 3 additions & 3 deletions src/server/api/routes/safe/getMany.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ const ResponseSchema = z.object({

export const getMany = withAuthApiV1
.createRoute({
summary: "List safes",
description: "List all safes in the company",
tags: ["Safe"],
summary: "List SAFEs",
description: "List all SAFEs in the company",
tags: ["SAFEs"],
method: "get",
path: "/v1/{companyId}/safes",
middleware: [authMiddleware()],
Expand Down
8 changes: 4 additions & 4 deletions src/server/api/routes/safe/getOne.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ const ResponseSchema = z.object({

export const getOne = withAuthApiV1
.createRoute({
summary: "Get a safe",
description: "Get a safe by ID",
tags: ["Safe"],
summary: "Get a SAFE",
description: "Get a SAFE by ID",
tags: ["SAFEs"],
method: "get",
path: "/v1/{companyId}/safes/{id}",
middleware: [authMiddleware()],
Expand Down Expand Up @@ -68,7 +68,7 @@ export const getOne = withAuthApiV1
if (!safe) {
throw new ApiError({
code: "NOT_FOUND",
message: "No safe with the provided Id",
message: `SAFE with id ${id} could not be found`,
});
}

Expand Down
6 changes: 3 additions & 3 deletions src/server/api/routes/safe/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { update } from "./update";

export const registerSafeRoutes = (api: PublicAPI) => {
api.openapi(getOne.route, getOne.handler);
api.openapi(update.route, update.handler);
api.openapi(_delete.route, _delete.handler);
api.openapi(create.route, create.handler);
// api.openapi(update.route, update.handler);
// api.openapi(_delete.route, _delete.handler);
// api.openapi(create.route, create.handler);
api.openapi(getMany.route, getMany.handler);
};
2 changes: 1 addition & 1 deletion src/server/api/routes/safe/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const update = withAuthApiV1
.createRoute({
summary: "Update a stakeholder",
description: "Modify the details of a stakeholder by their ID.",
tags: ["Stakeholder"],
tags: ["SAFEs"],
method: "patch",
path: "/v1/{companyId}/stakeholders/{id}",
middleware: [authMiddleware()],
Expand Down
140 changes: 73 additions & 67 deletions src/server/api/schema/safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,79 @@ import { SafeStatusEnum, SafeTypeEnum } from "@prisma/client";
const types = z.nativeEnum(SafeTypeEnum);
const statuses = z.nativeEnum(SafeStatusEnum);

export const ApiSafeSchema = z.object({
id: z.string().cuid().openapi({
description: "SAFE ID",
example: "cly402ncj0000i7ng9l0v04qr",
}),
externalId: z.string().optional().openapi({
description: "External ID of the safe",
example: "1234567890",
}),
type: types.openapi({
description: "Type of the safe",
example: "POST_MONEY",
}),
status: statuses.openapi({
description: "Status of the safe",
example: "ACTIVE",
}),
capital: z.number().openapi({
description: "SAFE investment capital",
example: 10000,
}),
valuationCap: z.number().optional().openapi({
description: "Valuation cap of the safe",
example: 100000000,
}),
discountRate: z.number().optional().openapi({
description: "Discount rate in percentage",
example: 5,
}),
mfn: z.boolean().optional().openapi({
description: "Most favoured nation",
example: true,
}),
proRata: z.boolean().optional().openapi({
description: "Pro rata rights",
example: true,
}),
stakeholderId: z.string().cuid().openapi({
description: "Stakeholder / Investor ID",
example: "clzkv7w5c0000f1ngf3yq2s45",
}),
documents: z
.array(z.string().url())
.optional()
.openapi({
description: "Secure links to SAFE documents",
example: [
"https://docs.captable.inc/document1.pdf",
"https://docs.captable.inc/document2.pdf",
],
export const ApiSafeSchema = z
.object({
id: z.string().cuid().openapi({
description: "SAFE ID",
example: "cly402ncj0000i7ng9l0v04qr",
}),
companyId: z.string().cuid().openapi({
description: "Company ID",
example: "clzkvdnhj0000f1ngf3fxakwu",
}),
issueDate: z.date().optional().openapi({
description: "Date of issue",
example: "2021-01-01",
}),
boardApprovalDate: z.date().optional().openapi({
description: "Date of board approval",
example: "2021-01-01",
}),
createdAt: z.date().openapi({
description: "Created at timestamp",
example: "2021-01-01",
}),
});
publicId: z.string().optional().openapi({
description: "External ID of the safe",
example: "1234567890",
}),
type: types.openapi({
description: "Type of the safe",
example: "POST_MONEY",
}),
status: statuses.openapi({
description: "Status of the safe",
example: "ACTIVE",
}),
capital: z.number().openapi({
description: "SAFE investment capital",
example: 10000,
}),
valuationCap: z.number().optional().openapi({
description: "Valuation cap of the safe",
example: 100000000,
}),
discountRate: z.number().optional().openapi({
description: "Discount rate in percentage",
example: 5,
}),
mfn: z.boolean().optional().openapi({
description: "Most favoured nation",
example: true,
}),
proRata: z.boolean().optional().openapi({
description: "Pro rata rights",
example: true,
}),
stakeholderId: z.string().cuid().openapi({
description: "Stakeholder / Investor ID",
example: "clzkv7w5c0000f1ngf3yq2s45",
}),
documents: z
.array(z.string().url())
.optional()
.openapi({
description: "Secure links to SAFE documents",
example: [
"https://docs.captable.inc/document1.pdf",
"https://docs.captable.inc/document2.pdf",
],
}),
companyId: z.string().cuid().openapi({
description: "Company ID",
example: "clzkvdnhj0000f1ngf3fxakwu",
}),
bankAccountId: z.string().cuid().optional().openapi({
description: "Bank account ID to receive funds",
example: "clzkv7w5c0000f1ngf3yq2s45",
}),
issueDate: z.date().optional().openapi({
description: "Date of issue",
example: "2021-01-01",
}),
boardApprovalDate: z.date().optional().openapi({
description: "Date of board approval",
example: "2021-01-01",
}),
createdAt: z.date().openapi({
description: "Created at timestamp",
example: "2021-01-01",
}),
})
.openapi("SAFE");

export type ApiSafeType = z.infer<typeof ApiSafeSchema>;

0 comments on commit 4925057

Please sign in to comment.