-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.js
31 lines (26 loc) · 917 Bytes
/
controller.js
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
30
31
const catchAsyncWrapper = require('./utils/catchAsync');
const AppError = require('./utils/appError');
const WeakSet = require('./utils/weakSet');
const set = new WeakSet();
const getController = async (req, res, next) => {
if (req.query.key) {
res.status(200).json({
status: 'success',
key: req.query.key,
present: set.contains(req.query.key),
});
} else next(new AppError(400, 'No Key Provided'));
};
const insertController = async (req, res, next) => {
if (req.query.key) {
if (set.contains(req.query.key))
return next(new AppError(400, 'Duplicated Key'));
set.insert(req.query.key, req.query.age);
res.status(200).json({
status: 'success',
key: req.query.key,
});
} else next(new AppError(400, 'No Key Provided'));
};
exports.getController = catchAsyncWrapper(getController);
exports.insertController = catchAsyncWrapper(insertController);