This repository has been archived on 2025-11-04. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
qoverflow/server/utils/question/refreshQuestion.js

22 lines
542 B
JavaScript

const Question = require('server/db/models/Question');
const createRequest = require('server/utils/api');
async function refreshQuestion(question_id) {
const { question, success } = await createRequest(
'get',
`/questions/${question_id}`
);
if (!success) return false;
// Refresh cache
const newQuestion = {
...question,
id: question.question_id,
};
return Question.findByIdAndUpdate(question.id, newQuestion, {
upsert: true,
});
}
module.exports = refreshQuestion;