Fixed automated code review warnings

This commit is contained in:
jd
2026-02-18 21:36:27 +00:00
parent 2996a2eb95
commit 035397ea25
7 changed files with 13 additions and 19 deletions

View File

@@ -14,7 +14,7 @@ async function login(request: UnwrappedRequest): Promise<Response> {
refreshCount: string; refreshCount: string;
} | null = await orm.users.verifyCredentials(requestBody.username, requestBody.password); } | null = await orm.users.verifyCredentials(requestBody.username, requestBody.password);
if (!verify) { if (!verify) {
throw new UnauthorizedError('Invalid credentials'); return new UnauthorizedResponse('Invalid credentials');
} }
// Build refresh token that expires in 30 days, return as secure HTTP only cookie. // Build refresh token that expires in 30 days, return as secure HTTP only cookie.
@@ -46,7 +46,7 @@ async function token(request: UnwrappedRequest): Promise<Response> {
const cookies = request.request.cookies; const cookies = request.request.cookies;
const refreshCookie = cookies.get('refresh'); const refreshCookie = cookies.get('refresh');
if (!refreshCookie) { if (!refreshCookie) {
throw new UnauthorizedError('No refresh token found'); return new UnauthorizedResponse('No refresh token found');
} }
const refreshToken: { const refreshToken: {
@@ -69,7 +69,7 @@ async function token(request: UnwrappedRequest): Promise<Response> {
} }
} }
async function logout(request: UnwrappedRequest): Promise<Response> { async function logout(): Promise<Response> {
try { try {
const response = new OkResponse(); const response = new OkResponse();
response.headers.set('Clear-Site-Data', '"cookies","cache","storage","executionContexts"'); response.headers.set('Clear-Site-Data', '"cookies","cache","storage","executionContexts"');
@@ -79,14 +79,13 @@ async function logout(request: UnwrappedRequest): Promise<Response> {
} }
} }
async function changePassword(request: UnwrappedRequest): Promise<Response> { async function changePassword(request: UnwrappedRequest<ChangePasswordRequest>): Promise<Response> {
try { try {
const requestBody = request.body as ChangePasswordRequest;
return new OkResponse( return new OkResponse(
await orm.users.changePassword( await orm.users.changePassword(
SecureId.fromHash(request.params.id), SecureId.fromHash(request.params.id),
requestBody.oldPassword, request.body.oldPassword,
requestBody.newPassword, request.body.newPassword,
request.claims, request.claims,
), ),
); );

View File

@@ -11,7 +11,7 @@ const server = Bun.serve({
...player, ...player,
...game, ...game,
'/test': { '/test': {
GET: (request) => { GET: () => {
return new OkResponse(); return new OkResponse();
}, },
}, },

View File

@@ -1,6 +1,6 @@
import { Claims } from './claims'; import { Claims } from './claims';
import { sql } from 'bun'; import { sql } from 'bun';
import { first, memoize } from 'lodash'; import { first } from 'lodash';
import { NotFoundError, UnauthorizedError } from '../utilities/errors'; import { NotFoundError, UnauthorizedError } from '../utilities/errors';
import { CreateGameRequest, SecureId, UpdateGameRequest } from '../utilities/requestModels'; import { CreateGameRequest, SecureId, UpdateGameRequest } from '../utilities/requestModels';
import { memo } from '../utilities/helpers'; import { memo } from '../utilities/helpers';

View File

@@ -1,7 +1,7 @@
import { Claims } from './claims'; import { Claims } from './claims';
import { sql } from 'bun'; import { sql } from 'bun';
import { first } from 'lodash'; import { first } from 'lodash';
import { BadRequestError, NotFoundError, UnauthorizedError } from '../utilities/errors'; import { NotFoundError, UnauthorizedError } from '../utilities/errors';
import { orm } from './orm'; import { orm } from './orm';
import { SecureId, UpdatePlayerRequest } from '../utilities/requestModels'; import { SecureId, UpdatePlayerRequest } from '../utilities/requestModels';
@@ -28,7 +28,7 @@ export class Player {
} }
export class PlayersOrm { export class PlayersOrm {
async create(model: {name: string}, claims?: Claims): Promise<Player | null> { async create(model: { name: string }, claims?: Claims): Promise<Player | null> {
await sql`INSERT INTO players (name) await sql`INSERT INTO players (name)
VALUES (${model.name})`; VALUES (${model.name})`;
const newPlayerId: string = (first(await sql`SELECT lastval();`) as any)?.lastval as string; const newPlayerId: string = (first(await sql`SELECT lastval();`) as any)?.lastval as string;
@@ -74,11 +74,7 @@ export class PlayersOrm {
async update( async update(
id: SecureId, id: SecureId,
patch: { patch: UpdatePlayerRequest,
name?: string;
isRatingLocked?: boolean;
canBeMultiple?: boolean;
},
claims?: Claims, claims?: Claims,
): Promise<Player | null> { ): Promise<Player | null> {
if (!(Claims.test(Claims.ADMIN, claims) || Claims.test(Claims.PLAYERS.OTHER.UPDATE, claims))) { if (!(Claims.test(Claims.ADMIN, claims) || Claims.test(Claims.PLAYERS.OTHER.UPDATE, claims))) {

View File

@@ -92,7 +92,7 @@ export class UsersOrm {
async update( async update(
id: SecureId, id: SecureId,
patch: { isActive?: boolean; isAdmin?: boolean }, patch: UpdateUserRequest,
claims?: Claims, claims?: Claims,
): Promise<User | null> { ): Promise<User | null> {
if ( if (

View File

@@ -29,7 +29,7 @@ export function guard(
try { try {
const userClaims: Claims = jwt.verify(authHeader as string, process.env.JWT_SECRET_KEY as string) as Claims; const userClaims: Claims = jwt.verify(authHeader as string, process.env.JWT_SECRET_KEY as string) as Claims;
if (!userClaims.claims.some((x: string): boolean => guardedClaims.includes(x))) { if (!userClaims.claims.some((x: string): boolean => guardedClaims.includes(x))) {
throw new UnauthorizedError('Unauthorized'); return new UnauthorizedResponse('Unauthorized');
} }
return method(await unwrap(request, userClaims)); return method(await unwrap(request, userClaims));
} catch (error: any) { } catch (error: any) {

View File

@@ -1,5 +1,4 @@
import { BadRequestError, NotFoundError, UnauthorizedError } from './errors'; import { BadRequestError, NotFoundError, UnauthorizedError } from './errors';
import { hashIds } from './guard';
export class ErrorResponse extends Response { export class ErrorResponse extends Response {
//@ts-ignore //@ts-ignore