Found while resetting the live test world: joinWorld's comment promised POST /worlds/:id/join but no route existed, so after reset-world (accounts kept) nobody could found a POP again. Added POST /me/join (default: first running world; 409 if already joined), a join card on the POP screen, en/nb strings, API.md + openapi. Client no longer polls /movements while it has no operator (that 404ed). Tested: npm test 209/209 (new test/me-join.test.js incl. response contract), openapi check, npm run e2e (new check: account without a POP sees the join card and founds one). NOT tested: joining a second/other world (only the default-world path in the browser), nb text of the card visually. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
27 lines
1.7 KiB
JavaScript
27 lines
1.7 KiB
JavaScript
'use strict';
|
|
const { GameError } = require('../errors');
|
|
const { reply } = require('../http');
|
|
function register(router, { queries, commands, db }) {
|
|
router.get('/me', { summary: 'The current user, their operators and POPs', tag: 'me', response: { $ref: 'Me' }, errors: ['unauthorized'] },
|
|
({ user }) => queries.me(user.id));
|
|
|
|
// An account without an operator (the world was reset, or a new one opened) founds its POP here. Signup does the same inline.
|
|
router.post('/me/join', {
|
|
summary: 'Join a world with this account: creates the operator and its capital POP (default: the first running world)', tag: 'me', status: 201,
|
|
body: { type: 'object', properties: { worldId: { type: 'integer', minimum: 1 } } },
|
|
response: { $ref: 'Me' }, errors: ['unauthorized', 'validation_failed', 'not_found', 'conflict', 'world_full'],
|
|
}, ({ user, body }) => {
|
|
const w = body.worldId !== undefined ? db.get("SELECT id FROM worlds WHERE id = ? AND status = 'running'", body.worldId)
|
|
: db.get("SELECT id FROM worlds WHERE status = 'running' ORDER BY id LIMIT 1");
|
|
if (!w) throw new GameError('not_found', { what: 'world' });
|
|
commands.run('joinWorld', { userId: user.id, worldId: w.id });
|
|
return reply(201, queries.me(user.id));
|
|
});
|
|
|
|
router.get('/notifications', {
|
|
summary: 'Notifications for this user (cursor: after = last seen id)', tag: 'me',
|
|
query: { type: 'object', properties: { after: { type: 'integer', minimum: 0 }, limit: { type: 'integer', minimum: 1, maximum: 100 } } },
|
|
response: { $ref: 'NotificationList' }, errors: ['unauthorized', 'validation_failed'],
|
|
}, ({ user, query }) => queries.notifications(user.id, query));
|
|
}
|
|
module.exports = { register };
|