27 lines
833 B
TypeScript
27 lines
833 B
TypeScript
import { requireAuth } from '~/server/utils/auth'
|
|
import { nodes, addAchievement } from '~/server/utils/db'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const user = requireAuth(event)
|
|
const id = getRouterParam(event, 'id')
|
|
const body = await readBody(event)
|
|
|
|
const existing = nodes.get(id || '') || { id, state: 'pending', assigned_to: user.id }
|
|
|
|
// Update state
|
|
const updated = { ...existing, ...body, updatedAt: new Date().toISOString() }
|
|
nodes.set(id || '', updated)
|
|
|
|
// Gamification: achievement on completion
|
|
if (body.state === 'completed' && existing.state !== 'completed') {
|
|
addAchievement(user.id, {
|
|
id: `completed-${id}`,
|
|
title: 'Задача выполнена',
|
|
description: `Нода ${id} завершена`,
|
|
icon: '✅'
|
|
})
|
|
}
|
|
|
|
return { node: updated }
|
|
})
|