// server/api/village/action.post.ts import { getUserIdFromSession } from '../../utils/auth'; import { buildOnTile } from '../../services/villageService'; import { getVillageState } from '../../services/villageService'; export default defineEventHandler(async (event) => { const userId = await getUserIdFromSession(event); const body = await readBody(event); const { tileId, actionType, payload } = body; if (!tileId || !actionType) { throw createError({ statusCode: 400, statusMessage: 'Missing tileId or actionType' }); } switch (actionType) { case 'BUILD': if (!payload?.buildingType) { throw createError({ statusCode: 400, statusMessage: 'Missing buildingType for BUILD action' }); } await buildOnTile(userId, tileId, payload.buildingType); break; default: throw createError({ statusCode: 400, statusMessage: 'Invalid actionType' }); } // Return the full updated village state return getVillageState(userId); });