mirror of
https://github.com/djdevin/recflare.git
synced 2026-09-08 14:41:28 -07:00
more routes
This commit is contained in:
@@ -142,6 +142,16 @@ export async function getRoomsByCreator(db: D1Database, accountId: number): Prom
|
||||
return parseAll(results)
|
||||
}
|
||||
|
||||
/**
|
||||
* An account's public, non-dorm rooms — the publicly viewable "rooms owned by
|
||||
* <player>" list (excludes private rooms, dorms, and list-excluded rooms).
|
||||
*/
|
||||
export async function getPublicRoomsByCreator(db: D1Database, accountId: number): Promise<Room[]> {
|
||||
return (await getRoomsByCreator(db, accountId)).filter(
|
||||
(r) => r.IsDorm !== true && r.Accessibility === 1 && r.ExcludeFromLists !== true
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Rooms the player has favorited (interaction.favorited = 1), most recently
|
||||
* interacted first. Joins the `interaction` table to `rooms`, so a favorited room
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
getFavoritedRooms,
|
||||
getHotRooms,
|
||||
getInteraction,
|
||||
getPublicRoomsByCreator,
|
||||
getRoomById,
|
||||
getRoomByName,
|
||||
getRoomsByCreator,
|
||||
@@ -206,6 +207,12 @@ const app = new Hono<App>()
|
||||
.get('/rooms/ownedby/me', ownedRooms)
|
||||
.get('/rooms/createdby/me', ownedRooms)
|
||||
|
||||
// Public: the rooms a given account owns that are publicly viewable. No auth —
|
||||
// returns a bare array (empty when the account owns no public rooms).
|
||||
.get('/rooms/ownedby/:accountId{[0-9]+}', async (c) =>
|
||||
c.json(await getPublicRoomsByCreator(c.env.DB, Number.parseInt(c.req.param('accountId'), 10)))
|
||||
)
|
||||
|
||||
// Rooms the caller has favorited (from the interaction table). Auth-gated.
|
||||
// Paginated via skip/take (take defaults to 100). Returns a bare array, like the
|
||||
// other room-source `*by/me` lists the client loads.
|
||||
|
||||
@@ -115,6 +115,27 @@ describe('rooms endpoints', () => {
|
||||
expect(other).toEqual([])
|
||||
})
|
||||
|
||||
it('GET /rooms/ownedby/:id returns an account public rooms (no auth)', async () => {
|
||||
const res = await SELF.fetch(`${ORIGIN}/rooms/ownedby/1`)
|
||||
expect(res.status).toBe(200)
|
||||
const body = (await res.json()) as Array<{
|
||||
RoomId: number
|
||||
Accessibility: number
|
||||
IsDorm?: boolean
|
||||
CreatorAccountId: number
|
||||
}>
|
||||
expect(body.length).toBeGreaterThan(0)
|
||||
// Only public, non-dorm rooms owned by account 1 — the private dorm (RoomId 1)
|
||||
// is excluded.
|
||||
expect(
|
||||
body.every((r) => r.Accessibility === 1 && r.IsDorm !== true && r.CreatorAccountId === 1)
|
||||
).toBe(true)
|
||||
expect(body.some((r) => r.RoomId === 1)).toBe(false)
|
||||
|
||||
// An account that owns no public rooms → empty array.
|
||||
expect(await (await SELF.fetch(`${ORIGIN}/rooms/ownedby/999`)).json()).toEqual([])
|
||||
})
|
||||
|
||||
it('GET /rooms/search returns a paginated { Results, TotalResults }', async () => {
|
||||
// Name-term search resolves a known public room.
|
||||
const res = await SELF.fetch(`${ORIGIN}/rooms/search?query=reccenter&skip=0&take=100`)
|
||||
|
||||
Reference in New Issue
Block a user