Removed console.logs and uncommented cron
This commit is contained in:
parent
2fb612f139
commit
300b9e296b
4 changed files with 14 additions and 21 deletions
|
|
@ -24,12 +24,9 @@ export default function SendMailController() {
|
|||
|
||||
const sendMail = async (fields) => {
|
||||
const { error, status } = await postMail(fields);
|
||||
console.log(error, status, 12313);
|
||||
if (error) {
|
||||
if (status === 500)
|
||||
return { receiver: 'Error' };
|
||||
else if (status === 404)
|
||||
return { receiver: 'User not found' };
|
||||
if (status === 500) return { receiver: 'Error' };
|
||||
else if (status === 404) return { receiver: 'User not found' };
|
||||
} else {
|
||||
window.location.reload(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import Throttle from 'superagent-throttle';
|
|||
|
||||
const throttle = new Throttle({
|
||||
active: true,
|
||||
rate: 2,
|
||||
rate: 10,
|
||||
ratePer: 1000,
|
||||
concurrent: 2,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@ mongoose.connection.on(
|
|||
console.error.bind(console, '[ERROR]: MongoDB connection error - ')
|
||||
);
|
||||
|
||||
// cron.schedule('*/30 * * * * *', refreshQuestions);
|
||||
// cron.schedule('*/2 * * * *', refreshUsers);
|
||||
cron.schedule('*/30 * * * * *', refreshQuestions);
|
||||
cron.schedule('*/2 * * * *', refreshUsers);
|
||||
|
||||
server.listen(port, console.log(`Listening on port: ${port}`));
|
||||
server.on('error', onError);
|
||||
|
|
|
|||
|
|
@ -3,22 +3,20 @@ const superagent = require('superagent');
|
|||
const Throttle = require('superagent-throttle');
|
||||
const throttle = new Throttle({
|
||||
active: true,
|
||||
rate: 2,
|
||||
rate: 5,
|
||||
ratePer: 1000,
|
||||
concurrent: 2,
|
||||
});
|
||||
|
||||
const cleanObject = (data) =>
|
||||
Object.fromEntries(
|
||||
Object.entries(data)
|
||||
.filter(([, v]) => v)
|
||||
)
|
||||
const cleanObject = (data) => Object.fromEntries(Object.entries(data).filter(([, v]) => v));
|
||||
|
||||
const stringifyQuery = (data = {}) =>
|
||||
Object.fromEntries(
|
||||
Object.entries(data)
|
||||
.map(([k, v]) => [k, typeof (v) === 'object' ? JSON.stringify(cleanObject(v)) : v])
|
||||
)
|
||||
Object.entries(data).map(([k, v]) => [
|
||||
k,
|
||||
typeof v === 'object' ? JSON.stringify(cleanObject(v)) : v,
|
||||
])
|
||||
);
|
||||
|
||||
const createRequest = async (op, endpoint, data) => {
|
||||
let request = superagent[op](`${process.env.API_URL}${endpoint}`)
|
||||
|
|
@ -26,10 +24,8 @@ const createRequest = async (op, endpoint, data) => {
|
|||
.set('Authorization', `bearer ${process.env.API_KEY}`);
|
||||
|
||||
if (data)
|
||||
if (op === 'get' || op === 'delete')
|
||||
request = request.query(stringifyQuery(data));
|
||||
else if (op === 'post' || op === 'patch')
|
||||
request = request.send(data);
|
||||
if (op === 'get' || op === 'delete') request = request.query(stringifyQuery(data));
|
||||
else if (op === 'post' || op === 'patch') request = request.send(data);
|
||||
|
||||
return request
|
||||
.then((res) => {
|
||||
|
|
|
|||
Reference in a new issue