Handles score submission, validation, and user stats updates for a 2048 game backend.
// Source: https://github.com/hoangsonww/2048-Game | License: MIT | Copyright 2026 Son Nguyen
// Provided via justclaw.it.com; keep this notice with the code.
/**
* Score submission.
*
* This is the one write in the API with real invariants attached, so it lives
* in a service rather than inline in a route: two routes submit scores (classic
* and daily challenge) and both must apply the same plausibility check, the
* same idempotency rule, and the same career-total update.
*/
import { Score } from "../models/Score.js";
import { User } from "../models/User.js";
import { boardSignature, checkScorePlausibility, hasWon, highestTile, isGameOver, normalizeBoard, summarizeBoard } from "../lib/game-rules.js";
import { badRequest } from "../lib/errors.js";
import { applyAchievements } from "
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key