Skip to content

Commit d15d557

Browse files
committed
Moved CleezyFunction.js to api/util and renamed it cleezyHelpers.js.
1 parent cf4bad1 commit d15d557

File tree

3 files changed

+6
-40
lines changed

3 files changed

+6
-40
lines changed

api/main_endpoints/routes/Cleezy.js

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const router = express.Router();
44
const {
55
decodeToken,
66
checkIfTokenSent,
7-
checkIfTokenValid,
87
} = require('../util/token-functions.js');
98
const {
109
OK,
@@ -14,7 +13,6 @@ const {
1413
} = require('../../util/constants').STATUS_CODES;
1514
const logger = require('../../util/logger');
1615
const { Cleezy } = require('../../config/config.json');
17-
const membershipState = require('../../util/constants').MEMBERSHIP_STATE;
1816
const { ENABLED } = Cleezy;
1917

2018
let CLEEZY_URL = process.env.CLEEZY_URL
@@ -99,36 +97,4 @@ router.post('/deleteUrl', async (req, res) => {
9997
});
10098
});
10199

102-
const searchCleezyUrls = async (req) => {
103-
if(!ENABLED || !req.body.query) {
104-
return { status: OK, data: [] };
105-
}
106-
107-
if (!checkIfTokenSent(req)) {
108-
return { status: FORBIDDEN, data: [] };
109-
} else if (!checkIfTokenValid(req, membershipState.OFFICER)) {
110-
return { status: UNAUTHORIZED, data: [] };
111-
}
112-
113-
try {
114-
const cleezyQuery = req.body.query.replace(/[^a-zA-Z0-9]/g, '');
115-
const cleezyRes = await axios.get(CLEEZY_URL + '/list', {
116-
params: {
117-
search: cleezyQuery
118-
}
119-
});
120-
const cleezyData = cleezyRes.data?.data
121-
.slice(0, 5)
122-
.map(e => {
123-
const u = new URL(e.alias, URL_SHORTENER_BASE_URL);
124-
return { ...e, link: u.href };
125-
});
126-
127-
return { status: OK, data: cleezyData };
128-
} catch (err) {
129-
logger.error('cleezy search urls had an error', err);
130-
return { status: SERVER_ERROR, data: [] };
131-
}
132-
};
133-
134-
module.exports = {router, searchCleezyUrls};
100+
module.exports = router;

api/main_endpoints/routes/ShortcutSearch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const membershipState = require('../../util/constants').MEMBERSHIP_STATE;
1717
const logger = require('../../util/logger');
1818
const { Cleezy } = require('../../config/config.json');
1919
const { ENABLED } = Cleezy;
20-
const cleezy = require('../routes/Cleezy.js');
20+
const cleezy = require('../util/cleezyHelpers.js');
2121

2222
// Search for all members using either first name, last name or email
2323
// Search for all cleezy urls using either alias or url

api/main_endpoints/routes/CleezyFunction.js renamed to api/main_endpoints/util/cleezyHelpers.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ const {
55
decodeToken,
66
checkIfTokenSent,
77
checkIfTokenValid,
8-
} = require('../util/token-functions.js');
8+
} = require('./token-functions.js');
99
const {
1010
OK,
1111
UNAUTHORIZED,
1212
FORBIDDEN,
1313
SERVER_ERROR,
14-
} = require('../../util/constants').STATUS_CODES;
15-
const logger = require('../../util/logger');
14+
} = require('../../util/constants.js').STATUS_CODES;
15+
const logger = require('../../util/logger.js');
1616
const { Cleezy } = require('../../config/config.json');
17-
const membershipState = require('../../util/constants').MEMBERSHIP_STATE;
17+
const membershipState = require('../../util/constants.js').MEMBERSHIP_STATE;
1818
const { ENABLED } = Cleezy;
1919

2020
let CLEEZY_URL = process.env.CLEEZY_URL

0 commit comments

Comments
 (0)