Files
JMuseum/models/renderModels/feedback.js
2018-02-26 14:09:18 +08:00

28 lines
1.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var User = require("../mongooseSchemas/User");
/**
* 頁面「意見回饋」的插值函式。
* @param {BasicLayout} renderData 基本插值物件。
* @param {string} route 路由路徑。
* @param {Express.Session} session Express的Session物件。
* @param {CallbackFunction} callback 回呼函式。
*/
function FeedBackRender(renderData, route, session, callback) {
renderData.datas.currentDate = (new Date()).toLocaleDateString();
// 如果使用者沒有登入則設定hasPostFeedback為false並呼叫回呼函式。
if (!renderData.hasLogin) {
renderData.datas.hasPostFeedback = false;
callback(null, true);
return;
}
// 如果使用者有登入則尋找資料庫中指定的使用者資料的「hasPostFeedback」欄位。
User.findOne({ "username": renderData.username }).select("hasPostFeedback").exec(function (err, userDoc) {
if (err) {
callback(err, null);
return;
}
renderData.datas.hasPostFeedback = userDoc.hasPostFeedback;
callback(null, true);
});
}
module.exports.Render = FeedBackRender;