Global

Members

DELETE /notes/:id

Move a note to recycle bin (soft delete)

Source:
Example
// Successful move to recycle bin returns 204 with no content
// Failed move (note not found) returns:
{
  "error": "Note not found"
}

DELETE /notes/:id/permanent

Permanently delete a note

Source:
Example
// Successful permanent deletion returns 204 with no content
// Failed deletion (note not found) returns:
{
  "error": "Note not found"
}

DELETE /notes/recycle-bin

Empty the recycle bin by permanently deleting all deleted notes

Source:
Example
// Response format (200):
{
  "message": "Recycle bin emptied successfully",
  "deletedCount": 5
}

GET /notes

Retrieve all active notes from the database

Source:
Example
// Response format:
[
  {
    "id": "note_123",
    "title": "Sample Note",
    "content": "This is a sample note content",
    "deletedAt": null,
    "createdAt": "2023-01-01T00:00:00.000Z",
    "updatedAt": "2023-01-02T00:00:00.000Z"
  }
]

GET /notes/:id

Retrieve a specific note by its ID

Source:
Example
// Response format (200):
{
  "id": "note_123",
  "title": "Sample Note",
  "content": "This is a sample note content",
  "deletedAt": null,
  "createdAt": "2023-01-01T00:00:00.000Z",
  "updatedAt": "2023-01-02T00:00:00.000Z"
}

GET /notes/recycle-bin

Retrieve all deleted notes from the recycle bin

Source:
Example
// Response format:
[
  {
    "id": "note_456",
    "title": "Deleted Note",
    "content": "This note is in recycle bin",
    "deletedAt": "2023-01-03T00:00:00.000Z",
    "createdAt": "2023-01-01T00:00:00.000Z",
    "updatedAt": "2023-01-03T00:00:00.000Z"
  }
]

GET /notes/recycle-bin/count

Get the count of notes in recycle bin

Source:
Example
// Response format:
{
  "count": 5
}

GET /notes/trash

Legacy route - use /recycle-bin instead

Deprecated:
  • Use GET /recycle-bin instead
Source:

POST /notes

Create a new note

Source:
Example
// Request body:
{
  "title": "New Note",
  "content": "This is the content of the new note"
}

// Response format (201):
{
  "id": "note_456",
  "title": "New Note",
  "content": "This is the content of the new note",
  "deletedAt": null,
  "createdAt": "2023-01-03T00:00:00.000Z",
  "updatedAt": "2023-01-03T00:00:00.000Z"
}

POST /notes/:id/restore

Restore a note from recycle bin

Source:
Example
// Successful restoration returns 204 with no content
// Failed restoration (note not found) returns:
{
  "error": "Note not found"
}

POST /notes/recycle-bin/restore-all

Restore all notes from recycle bin

Source:
Example
// Response format (200):
{
  "message": "All notes restored successfully",
  "restoredCount": 5
}

PUT /notes/:id

Update an existing note

Source:
Example
// Request body:
{
  "title": "Updated Note Title",
  "content": "Updated note content"
}

// Response format (200):
{
  "id": "note_123",
  "title": "Updated Note Title",
  "content": "Updated note content",
  "deletedAt": null,
  "createdAt": "2023-01-01T00:00:00.000Z",
  "updatedAt": "2023-01-03T00:00:00.000Z"
}

(constant) app :express.Application

Global Express application instance for backward compatibility

Type:
  • express.Application
Deprecated:
  • Use NotesServer class for better control
Source:
Example
import { app } from './notes-api-server.js';
// Note: Prefer using NotesServer class directly

(constant) createNoteRepository

Create repository instance using global server (backward compatibility)

Deprecated:
  • Use NotesServer.createNoteRepository() for better testability
Source:
Example
import { createNoteRepository } from './notes-api-server.js';
const repo = createNoteRepository();

(constant) gracefulShutdown

Graceful shutdown using global server (backward compatibility)

Deprecated:
  • Use NotesServer.gracefulShutdown() for better control
Source:
Example
import { gracefulShutdown } from './notes-api-server.js';
gracefulShutdown();

(constant) initializeApp

Initialize application using global server (backward compatibility)

Deprecated:
  • Use NotesServer.initializeApp() for better testability
Source:
Example
import { initializeApp } from './notes-api-server.js';
const { app, repository } = await initializeApp();

(constant) startServer

Start server using global server instance (backward compatibility)

Deprecated:
  • Use NotesServer.startServer() for better control
Source:
Example
import { startServer } from './notes-api-server.js';
const server = startServer();

Methods

addRecycleBinButtons(count) → {void}

Add the Restore All and Empty Recycle Bin buttons to the header actions

Parameters:
Name Type Description
count number

The number of notes in the recycle bin

Source:
Returns:
Type
void

closeModal() → {void}

Close the modal dialog and hide it from view

Source:
Returns:
Type
void

createNotesRouter(noteRepository) → {express.Router}

Create a router for note-related endpoints

Parameters:
Name Type Description
noteRepository NoteRepository

Repository for note operations (CouchDB or MongoDB implementation)

Source:
Returns:

Express router configured with note endpoints

Type
express.Router
Example
import { createNotesRouter } from './routes/notes-routes.js';
import { CouchDbNoteRepository } from './db/couchdb-note-repository.js';

const repository = new CouchDbNoteRepository(url, dbName);
const router = createNotesRouter(repository);
app.use('/api/notes', router);

displayDeletedNotes(notes) → {void}

Display deleted notes in the UI container

Parameters:
Name Type Description
notes Array.<Object>

Array of deleted note objects to display

Source:
Returns:
Type
void

displayNotes(notes) → {void}

Display active notes in the UI container

Parameters:
Name Type Description
notes Array.<Object>

Array of note objects to display

Source:
Returns:
Type
void

(async) emptyRecycleBin() → {Promise.<void>}

Empty the recycle bin by permanently deleting all deleted notes

Source:
Throws:

When empty recycle bin fails

Type
Error
Returns:
Type
Promise.<void>

escapeHtml(unsafe) → {string}

Escape HTML characters to prevent XSS attacks

Parameters:
Name Type Description
unsafe string

The unsafe string that may contain HTML characters

Source:
Returns:

The escaped string safe for HTML insertion

Type
string

(async) fetchDeletedNotes() → {Promise.<void>}

Fetch all deleted notes from the API and display them in the UI

Source:
Throws:

When API request fails or response is not ok

Type
Error
Returns:
Type
Promise.<void>

(async) fetchNotes() → {Promise.<void>}

Fetch all active notes from the API and display them in the UI

Source:
Throws:

When API request fails or response is not ok

Type
Error
Returns:
Type
Promise.<void>
Example
// Automatically called on page load
await fetchNotes();

(async) handleFormSubmit(e) → {Promise.<void>}

Handle form submission for creating or updating a note

Parameters:
Name Type Description
e Event

The form submit event

Source:
Throws:

When note creation/update fails

Type
Error
Returns:
Type
Promise.<void>

handleNoteActions(e) → {void}

Handle clicks on note action buttons using event delegation

Parameters:
Name Type Description
e Event

The click event on the notes container

Source:
Returns:
Type
void

handleRecycleBinActions(e) → {void}

Handle clicks on recycle bin action buttons using event delegation

Parameters:
Name Type Description
e Event

The click event on the recycle bin container

Source:
Returns:
Type
void

initializeTabs() → {void}

Initialize tab navigation

Source:
Returns:
Type
void

(async) moveToRecycleBin(id) → {Promise.<void>}

Move a note to recycle bin after user confirmation

Parameters:
Name Type Description
id string

The unique identifier of the note to move to recycle bin

Source:
Throws:

When move to recycle bin fails

Type
Error
Returns:
Type
Promise.<void>

openCreateNoteModal() → {void}

Open the modal dialog for creating a new note

Source:
Returns:
Type
void

(async) openEditNoteModal(id) → {Promise.<void>}

Open the modal dialog for editing an existing note

Parameters:
Name Type Description
id string

The unique identifier of the note to edit

Source:
Throws:

When note fetch fails or note is not found

Type
Error
Returns:
Type
Promise.<void>

(async) permanentDeleteNote(id) → {Promise.<void>}

Permanently delete a note after user confirmation

Parameters:
Name Type Description
id string

The unique identifier of the note to permanently delete

Source:
Throws:

When permanent deletion fails

Type
Error
Returns:
Type
Promise.<void>

(async) restoreAllNotes() → {Promise.<void>}

Restore all notes from recycle bin

Source:
Throws:

When restore all fails

Type
Error
Returns:
Type
Promise.<void>

(async) restoreNote(id) → {Promise.<void>}

Restore a note from recycle bin

Parameters:
Name Type Description
id string

The unique identifier of the note to restore

Source:
Throws:

When restore fails

Type
Error
Returns:
Type
Promise.<void>

switchToView(view) → {void}

Switch between notes and recycle bin views

Parameters:
Name Type Description
view string

The view to switch to ('notes' or 'recycleBin')

Source:
Returns:
Type
void

(async) updateRecycleBinCount() → {Promise.<void>}

Fetch and update the recycle bin count in the tab

Source:
Returns:
Type
Promise.<void>