-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Merge pull request #495 from BaseAdresseNationale/antoinelude…
- Loading branch information
1 parent
aec1c6c
commit 05fde3f
Showing
9 changed files
with
432 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,42 @@ | ||
import 'dotenv/config.js' // eslint-disable-line import/no-unassigned-import | ||
import express from 'express' | ||
import analyticsMiddleware from '../../middleware/analytics.js' | ||
|
||
import {handleAPIResponse} from '../helper.js' | ||
import {getUuids, uncollidUuids} from './helpers.js' | ||
|
||
const app = new express.Router() | ||
|
||
app.get('/', analyticsMiddleware, async (req, res) => { | ||
let response | ||
try { | ||
const length = Number(req.query.quantity) || 1 | ||
if (length > 100_000) { | ||
handleAPIResponse(res, 400, 'Quantity must be less than 100 000', {}) | ||
res.status(400).send({ | ||
date: new Date(), | ||
status: 'error', | ||
message: 'Quantity must be less than 100 000', | ||
response: {}, | ||
}) | ||
return | ||
} | ||
|
||
const ids = await uncollidUuids(getUuids(length)) | ||
handleAPIResponse(res, 200, 'Successfully generated UUIDs', ids) | ||
|
||
response = { | ||
date: new Date(), | ||
status: 'success', | ||
response: ids, | ||
} | ||
} catch (error) { | ||
console.error(error) | ||
handleAPIResponse(res, 500, 'Internal server error', {}) | ||
const {message} = error | ||
response = { | ||
date: new Date(), | ||
status: 'error', | ||
message, | ||
response: {}, | ||
} | ||
} | ||
|
||
res.send(response) | ||
}) | ||
|
||
export default app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.