Skip to content

Commit a5158db

Browse files
committed
chore: unknown type for hono response
1 parent c544f18 commit a5158db

File tree

4 files changed

+23
-24
lines changed

4 files changed

+23
-24
lines changed

src/server/api/routes/company/stock-option/create.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import {
55
ErrorResponses,
66
} from "@/server/api/error";
77
import type { PublicAPI } from "@/server/api/hono";
8-
import { OptionSchema, type TCreateOptionSchema } from "../../../schema/option";
9-
import type { TOptionSchema } from "./../../../schema/option";
10-
118
import { CreateOptionSchema } from "@/server/api/schema/option";
9+
import {
10+
OptionSchema,
11+
type TCreateOptionSchema,
12+
} from "@/server/api/schema/option";
1213
import { getHonoUserAgent, getIp } from "@/server/api/utils";
1314
import { addOption } from "@/server/services/stock-option/add-option";
1415
import { createRoute, z } from "@hono/zod-openapi";
@@ -37,7 +38,7 @@ const ResponseSchema = z.object({
3738
const route = createRoute({
3839
method: "post",
3940
path: "/v1/companies/{id}/options",
40-
summary: "Issue option",
41+
summary: "Issue a new stock option",
4142
description: "Issue stock option to a stakeholder in a company.",
4243
tags: ["Options"],
4344
request: {
@@ -69,7 +70,7 @@ const create = (app: PublicAPI) => {
6970
const body = await c.req.json();
7071

7172
const { success, message, data, code } = await addOption({
72-
requestIP: getIp(c.req),
73+
requestIp: getIp(c.req),
7374
userAgent: getHonoUserAgent(c.req),
7475
data: body as TCreateOptionSchema,
7576
companyId: company.id,
@@ -80,7 +81,7 @@ const create = (app: PublicAPI) => {
8081
},
8182
});
8283

83-
if (!success) {
84+
if (!success || !data) {
8485
throw new ApiError({
8586
code: code as ErrorCodeType,
8687
message,
@@ -89,8 +90,8 @@ const create = (app: PublicAPI) => {
8990

9091
return c.json(
9192
{
92-
message: "Stock option added successfully.",
93-
data: data as unknown as TOptionSchema,
93+
message,
94+
data,
9495
},
9596
200,
9697
);

src/server/api/routes/company/stock-option/delete.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ const ResponseSchema = z
2222
const route = createRoute({
2323
method: "delete",
2424
path: "/v1/companies/{id}/options/{optionId}",
25-
summary: "Delete issued options",
26-
description: "Delete a Option by ID",
25+
summary: "Delete an option by ID",
26+
description: "Delete an Option by ID",
2727
tags: ["Options"],
2828
request: {
2929
params: RequestParamsSchema,

src/server/api/routes/company/stock-option/getOne.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,19 @@ const getOne = (app: PublicAPI) => {
6767
app.openapi(route, async (c: Context) => {
6868
const { company } = await withCompanyAuth(c);
6969

70-
// id destructured to companyId and optionId destructured to id
7170
const { optionId: id } = c.req.param();
7271

73-
const option = (await db.option.findUnique({
72+
const option = await db.option.findUnique({
7473
where: {
7574
id,
7675
companyId: company.id,
7776
},
78-
})) as unknown as TOptionSchema;
77+
});
7978

8079
if (!option) {
8180
throw new ApiError({
8281
code: "NOT_FOUND",
83-
message: "Option not found",
82+
message: "Required option not found",
8483
});
8584
}
8685

src/server/api/routes/company/stock-option/update.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import type { PublicAPI } from "@/server/api/hono";
88

99
import {
1010
OptionSchema,
11-
type TOptionSchema,
1211
type TUpdateOptionSchema,
1312
UpdateOptionSchema,
1413
} from "@/server/api/schema/option";
@@ -45,7 +44,7 @@ export const RequestParamsSchema = z
4544
}),
4645
})
4746
.openapi({
48-
description: "Update a Option by ID",
47+
description: "Update an option by ID",
4948
});
5049

5150
const ResponseSchema = z
@@ -54,14 +53,14 @@ const ResponseSchema = z
5453
data: OptionSchema,
5554
})
5655
.openapi({
57-
description: "Update a Option by ID",
56+
description: "Update an option by ID",
5857
});
5958

6059
const route = createRoute({
6160
method: "put",
6261
path: "/v1/companies/{id}/options/{optionId}",
63-
summary: "Update issued options by ID",
64-
description: "Update issued options by option ID",
62+
summary: "Update an issued option by ID",
63+
description: "Update issued option by option ID",
6564
tags: ["Options"],
6665
request: {
6766
params: RequestParamsSchema,
@@ -86,7 +85,7 @@ const route = createRoute({
8685
},
8786
});
8887

89-
const getOne = (app: PublicAPI) => {
88+
const update = (app: PublicAPI) => {
9089
app.openapi(route, async (c: Context) => {
9190
const { company, user } = await withCompanyAuth(c);
9291
const { optionId } = c.req.param();
@@ -106,7 +105,7 @@ const getOne = (app: PublicAPI) => {
106105

107106
const { success, message, code, data } = await updateOption(payload);
108107

109-
if (!success) {
108+
if (!success || !data) {
110109
throw new ApiError({
111110
code: code as ErrorCodeType,
112111
message,
@@ -115,12 +114,12 @@ const getOne = (app: PublicAPI) => {
115114

116115
return c.json(
117116
{
118-
message: message,
119-
data: data as unknown as TOptionSchema,
117+
message,
118+
data,
120119
},
121120
200,
122121
);
123122
});
124123
};
125124

126-
export default getOne;
125+
export default update;

0 commit comments

Comments
 (0)