forked from mongodb/docs-sample-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmovieController.ts
More file actions
29 lines (23 loc) · 802 Bytes
/
movieController.ts
File metadata and controls
29 lines (23 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* Movie Controller
*/
import { Request, Response } from 'express';
import { getCollection } from '../config/database';
import { createSuccessResponse } from '../utils/errorHandler';
/**
* GET /api/movies
*/
export async function getAllMovies(req: Request, res: Response): Promise<void> {
const moviesCollection = getCollection('movies');
try {
// Execute the find operation with all options
const movies = await moviesCollection
.find({})
.limit(10) // TODO: Remove temp limit used for testing
.toArray();
// Return successful response
res.json(createSuccessResponse(movies, `Found ${movies.length} movies`));
} catch (error) {
throw new Error(`Failed to retrieve movies: ${error instanceof Error ? error.message : 'Unknown error'}`);
}
}