Skip to content

Commit 73b1ca2

Browse files
committed
misc updates
1 parent e87b998 commit 73b1ca2

File tree

6 files changed

+18
-16
lines changed

6 files changed

+18
-16
lines changed

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ COPY --link . .
1616
# install dependencies, lint project, build frontend, and compile backend
1717
RUN bun install --ignore-scripts --frozen-lockfile
1818
RUN bun run biome ci .
19-
RUN bun run build:prod
2019
RUN bun run compile
2120

2221
# minimalist final stage for app image

src/helpers/auth.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Config, CustomError } from "@helpers";
22

3-
export const assertRequestIsAuthorized = (authorization: string | undefined) => {
3+
export const assertIsRequestAuthorized = (authorization: string | undefined) => {
44
const token = authorization?.split("Bearer ")?.[1];
55
if (!token)
66
throw new CustomError(
@@ -9,4 +9,5 @@ export const assertRequestIsAuthorized = (authorization: string | undefined) =>
99
);
1010
if (token !== Config.API_KEY)
1111
throw new CustomError("Unauthorized - Bearer token does not match API_KEY value", 401);
12+
return true;
1213
};

src/helpers/error.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { StatusCode } from "hono/utils/http-status";
2-
31
import type { OpenAPIHono } from "@hono/zod-openapi";
42

3+
import type { TErrorStatusCode } from "@types";
4+
55
export class CustomError extends Error {
66
status: number;
77

@@ -17,7 +17,7 @@ export const initErrorHandling = (app: OpenAPIHono) => {
1717
app.onError((e, c) => {
1818
const errorStatus = (
1919
"status" in e && typeof e.status === "number" ? e.status : 500
20-
) as StatusCode;
20+
) as TErrorStatusCode;
2121
return c.json({ message: e.message || "Internal Server Error" }, errorStatus);
2222
});
2323
};

src/routes/bag.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { bagSchema } from "discit-types";
22

3-
import { assertRequestIsAuthorized, authHeaderSchema, resMessageSchema } from "@helpers";
3+
import { assertIsRequestAuthorized, authHeaderSchema, resMessageSchema } from "@helpers";
44
import { type OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
55
import { Bag } from "@models";
66

@@ -31,7 +31,7 @@ export const initBagRoutes = (app: OpenAPIHono) => {
3131
}),
3232
async c => {
3333
const { authorization } = c.req.valid("header");
34-
assertRequestIsAuthorized(authorization);
34+
assertIsRequestAuthorized(authorization);
3535
const { user_id } = c.req.valid("query");
3636
const bags = await Bag.getBags(user_id);
3737
return c.json(bags, 200);
@@ -68,7 +68,7 @@ export const initBagRoutes = (app: OpenAPIHono) => {
6868
}),
6969
async c => {
7070
const { authorization } = c.req.valid("header");
71-
assertRequestIsAuthorized(authorization);
71+
assertIsRequestAuthorized(authorization);
7272
const { id } = c.req.valid("param");
7373
const bag = await Bag.assertBagExists(id);
7474
return c.json(bag, 200);
@@ -112,7 +112,7 @@ export const initBagRoutes = (app: OpenAPIHono) => {
112112
}),
113113
async c => {
114114
const { authorization } = c.req.valid("header");
115-
assertRequestIsAuthorized(authorization);
115+
assertIsRequestAuthorized(authorization);
116116
const { user_id, name } = c.req.valid("json");
117117
const bag = await Bag.createBag(user_id, name);
118118
return c.json(bag, 201);
@@ -160,7 +160,7 @@ export const initBagRoutes = (app: OpenAPIHono) => {
160160
}),
161161
async c => {
162162
const { authorization } = c.req.valid("header");
163-
assertRequestIsAuthorized(authorization);
163+
assertIsRequestAuthorized(authorization);
164164
const { id, disc_id } = c.req.valid("json");
165165
const bag = await Bag.addDiscToBag(id, disc_id);
166166
return c.json(bag, 200);
@@ -208,7 +208,7 @@ export const initBagRoutes = (app: OpenAPIHono) => {
208208
}),
209209
async c => {
210210
const { authorization } = c.req.valid("header");
211-
assertRequestIsAuthorized(authorization);
211+
assertIsRequestAuthorized(authorization);
212212
const { id, disc_id } = c.req.valid("json");
213213
const bag = await Bag.removeDiscFromBag(id, disc_id);
214214
return c.json(bag, 200);
@@ -256,7 +256,7 @@ export const initBagRoutes = (app: OpenAPIHono) => {
256256
}),
257257
async c => {
258258
const { authorization } = c.req.valid("header");
259-
assertRequestIsAuthorized(authorization);
259+
assertIsRequestAuthorized(authorization);
260260
const { id, name } = c.req.valid("json");
261261
const bag = await Bag.updateBagName(id, name);
262262
return c.json(bag, 200);
@@ -293,7 +293,7 @@ export const initBagRoutes = (app: OpenAPIHono) => {
293293
}),
294294
async c => {
295295
const { authorization } = c.req.valid("header");
296-
assertRequestIsAuthorized(authorization);
296+
assertIsRequestAuthorized(authorization);
297297
const { id } = c.req.valid("param");
298298
const bag = await Bag.deleteBag(id);
299299
return c.json(bag, 200);

src/routes/disc.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { discSchema } from "discit-types";
22

33
import {
4-
assertRequestIsAuthorized,
4+
assertIsRequestAuthorized,
55
authHeaderSchema,
66
discQuerySchema,
77
resMessageSchema
@@ -99,7 +99,7 @@ export const initDiscRoutes = (app: OpenAPIHono) => {
9999
}),
100100
async c => {
101101
const { authorization } = c.req.valid("header");
102-
assertRequestIsAuthorized(authorization);
102+
assertIsRequestAuthorized(authorization);
103103
const body = c.req.valid("json");
104104
const discs = await Disc.insertDiscs(body);
105105
return c.json(discs, 201);
@@ -131,7 +131,7 @@ export const initDiscRoutes = (app: OpenAPIHono) => {
131131
}),
132132
async c => {
133133
const { authorization } = c.req.valid("header");
134-
assertRequestIsAuthorized(authorization);
134+
assertIsRequestAuthorized(authorization);
135135
await Disc.deleteAllDiscs();
136136
return c.json({ message: "All discs deleted successfully" }, 200);
137137
}

src/types/abstract/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ export type TDisc = types.TDisc;
1313
export type TDiscQuery = z.infer<typeof discQuerySchema>;
1414

1515
export type TBag = types.TBag;
16+
17+
export type TErrorStatusCode = 400 | 401 | 404 | 500;

0 commit comments

Comments
 (0)