Spaces:
Sleeping
Sleeping
Download server/models/UserNote.js from umaine/COS498-Group7: direct link, hf CLI and curl.
- Browser
- Download file 935 Bytes
-
https://huggingface.co/spaces/umaine/COS498-Group7/resolve/main/server/models/UserNote.js
- Command line
-
hf download hf://spaces/umaine/COS498-Group7/server/models/UserNote.js
-
curl -L -o UserNote.js https://huggingface.co/spaces/umaine/COS498-Group7/resolve/main/server/models/UserNote.js
935 Bytes
| const db = require('../db/database'); | |
| const { v4: uuidv4 } = require('uuid'); | |
| const UserNote = { | |
| create(data) { | |
| if (!data.user_id) throw new Error('UserNote.create: user_id is required'); | |
| if (!data.title) throw new Error('UserNote.create: title is required'); | |
| if (!data.content) throw new Error('UserNote.create: content is required'); | |
| const id = data.id || uuidv4(); | |
| db.prepare(` | |
| INSERT INTO user_notes (id, user_id, title, content) | |
| VALUES (?, ?, ?, ?) | |
| `).run(id, data.user_id, data.title, data.content); | |
| return this.findById(id); | |
| }, | |
| findById(id) { | |
| return db.prepare('SELECT * FROM user_notes WHERE id = ?').get(id) || null; | |
| }, | |
| findByUserId(userId) { | |
| return db.prepare('SELECT * FROM user_notes WHERE user_id = ? ORDER BY created_at DESC').all(userId); | |
| }, | |
| delete(id) { | |
| db.prepare('DELETE FROM user_notes WHERE id = ?').run(id); | |
| }, | |
| }; | |
| module.exports = UserNote; | |