/
malklopp
/
opencode-course
Обзор
Документация
Войти
/
malklopp
/
opencode-course
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
practice/src/db.js
36 строк
848 B
malklop
Курс изучения OpenCode: модули 0-5, учебный Express-проект, README
10 авг 2026, 22:38
10 авг 2026, 22:38
aa4d518
Код
Авторство
О чём код?
const crypto = require('node:crypto') const notes = new Map() function listNotes() { return [...notes.values()] } function getNote(id) { return notes.get(id) || null } function createNote({ title, body }) { const id = crypto.randomUUID() const now = new Date().toISOString() const note = { id, title, body, createdAt: now, updatedAt: now } notes.set(id, note) return note } function updateNote(id, patch) { const existing = notes.get(id) if (!existing) return null const changes = Object.fromEntries( Object.entries(patch).filter(([, value]) => value !== undefined) ) const next = { ...existing, ...changes, updatedAt: new Date().toISOString() } notes.set(id, next) return next } function deleteNote(id) { return notes.delete(id) } module.exports = { listNotes, getNote, createNote, updateNote, deleteNote }