mirror of
https://github.com/djdevin/recflare.git
synced 2026-09-08 06:31:27 -07:00
add playersettings, img, more match endpoints
This commit is contained in:
@@ -3,10 +3,11 @@ import { useWorkersLogger } from 'workers-tagged-logger'
|
||||
|
||||
import { withNotFound, withOnError } from '@repo/hono-helpers'
|
||||
|
||||
import type { App } from './context'
|
||||
import type { Context } from 'hono'
|
||||
import { validateAndGetAccountId } from './jwt'
|
||||
|
||||
import type { Context } from 'hono'
|
||||
import type { App } from './context'
|
||||
|
||||
/**
|
||||
* Ported from the C# `AccountsController`. Endpoints that the C# backs with EF
|
||||
* Core (`AppDbContext`) are stubbed here — there's no DB binding yet, so reads
|
||||
@@ -36,7 +37,7 @@ interface Account {
|
||||
*/
|
||||
async function authedId(c: Context<App>): Promise<number | null> {
|
||||
const authHeader = c.req.header('Authorization') ?? ''
|
||||
console.log(authHeader);
|
||||
console.log(authHeader)
|
||||
if (!authHeader.toLowerCase().startsWith('bearer ')) return null
|
||||
|
||||
const token = authHeader.slice('Bearer '.length)
|
||||
@@ -100,14 +101,17 @@ const app = new Hono<App>()
|
||||
if (id === null) return unauthorized(c)
|
||||
// TODO: load the real account; the C# 404s when the row is missing.
|
||||
const account = defaultAccount(id)
|
||||
// The C# `SelfAccount` marks `JuniorState` (an enum) and `ParentAccountId`
|
||||
// with `[JsonIgnore(WhenWritingNull)]`, so they're OMITTED when null —
|
||||
// emitting `"juniorState":null` makes the client's enum parser throw
|
||||
// ("Can't parse JSON to Enum format"). `Email`/`Phone`/`Birthday` are kept
|
||||
// as null (the C# has no JsonIgnore on those, and they aren't enums).
|
||||
return c.json({
|
||||
...account,
|
||||
ProfileImage: 'hdqeamlcmatc6qzoi2ybgf0ddijjcf.jpg',
|
||||
Email: null,
|
||||
Phone: null,
|
||||
JuniorState: null,
|
||||
Birthday: null,
|
||||
ParentAccountId: null,
|
||||
AvailableUsernameChanges: 1,
|
||||
})
|
||||
})
|
||||
|
||||
@@ -100,12 +100,16 @@ describe('auth-gated endpoints', () => {
|
||||
test('GET /account/me returns the self account with a valid token', async () => {
|
||||
const res = await exports.default.fetch(`${ORIGIN}/account/me`, { headers: await bearer() })
|
||||
expect(res.status).toBe(200)
|
||||
expect(await res.json()).toMatchObject({
|
||||
const body = (await res.json()) as Record<string, unknown>
|
||||
expect(body).toMatchObject({
|
||||
AccountId: 42,
|
||||
Username: 'Player42',
|
||||
AvailableUsernameChanges: 1,
|
||||
ParentAccountId: null,
|
||||
})
|
||||
// JuniorState + ParentAccountId must be omitted when null, not emitted as
|
||||
// null, or the client's enum parser throws on `juniorState`.
|
||||
expect('JuniorState' in body).toBe(false)
|
||||
expect('ParentAccountId' in body).toBe(false)
|
||||
})
|
||||
|
||||
test('GET /parentalcontrol/me returns the flags', async () => {
|
||||
|
||||
Reference in New Issue
Block a user