File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ const firestore = require ( '../utils/db' ) ;
2
+ const { convertToArray, createSuccessResponse, createErrorResponse } = require ( '../utils/helpers' ) ;
3
+
4
+ /**
5
+ * List versions with optional technology filtering
6
+ */
7
+ const listVersions = async ( req , res ) => {
8
+ try {
9
+ const params = req . query ;
10
+ let ref = firestore . collection ( 'versions' ) ;
11
+ let query = ref ;
12
+
13
+ // Filter by technology if provided
14
+ if ( params . technology ) {
15
+ const technologyArray = convertToArray ( params . technology ) ;
16
+ if ( technologyArray . length > 0 ) {
17
+ // Using 'in' operator for filtering by technology names
18
+ query = query . where ( 'technology' , 'in' , technologyArray ) ;
19
+ }
20
+ }
21
+
22
+ // Execute query
23
+ const snapshot = await query . get ( ) ;
24
+ const data = [ ] ;
25
+
26
+ // Extract all version documents
27
+ snapshot . forEach ( doc => {
28
+ data . push ( doc . data ( ) ) ;
29
+ } ) ;
30
+
31
+ res . statusCode = 200 ;
32
+ res . end ( JSON . stringify ( createSuccessResponse ( data ) ) ) ;
33
+ } catch ( error ) {
34
+ console . error ( 'Error fetching versions:' , error ) ;
35
+ res . statusCode = 400 ;
36
+ res . end ( JSON . stringify ( createErrorResponse ( [ [ 'query' , error . message ] ] ) ) ) ;
37
+ }
38
+ } ;
39
+
40
+ module . exports = {
41
+ listVersions
42
+ } ;
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ const { listLighthouse } = require('./controllers/lighthouseController');
12
12
const { listPageWeight } = require ( './controllers/pageWeightController' ) ;
13
13
const { listRanks } = require ( './controllers/ranksController' ) ;
14
14
const { listGeos } = require ( './controllers/geosController' ) ;
15
+ const { listVersions } = require ( './controllers/versionsController' ) ;
15
16
16
17
// Helper function to set CORS headers
17
18
const setCORSHeaders = ( res ) => {
@@ -101,6 +102,8 @@ const handleRequest = async (req, res) => {
101
102
await listRanks ( req , res ) ;
102
103
} else if ( pathname === '/v1/geos' && req . method === 'GET' ) {
103
104
await listGeos ( req , res ) ;
105
+ } else if ( pathname === '/v1/versions' && req . method === 'GET' ) {
106
+ await listVersions ( req , res ) ;
104
107
} else {
105
108
// 404 Not Found
106
109
res . statusCode = 404 ;
You can’t perform that action at this time.
0 commit comments