Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 32 33 34 35 36 | 4x 4x 4x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x | import { startSession } from "mongoose";
import { storeVariablesNames } from "../../CONSTANT/storeVariables.js";
import SettingsController from "../../controllers/settings-controllers/SettingsController.js";
import asyncRouteHandler from "../../utilities/asyncRouteHandler.js";
import updateRedisCache from "../../cache/updateRedisCache.js";
export default asyncRouteHandler(
async function settings_updateSetting_post(req, res) {
const { setting, newValue } = req.body;
const isStoreVariable = storeVariablesNames.includes(setting);
if (isStoreVariable) {
const session = await startSession();
session.startTransaction();
const respond = await SettingsController.updateSetting(setting, newValue, session);
Eif (respond) {
const updateResult = await updateRedisCache("store-variables", (currentData) => {
Iif (currentData) {
currentData[setting] = newValue
}
return currentData
})
Eif (updateResult) {
await session.commitTransaction();
res.status(200).json(respond);
return;
}
}
await session.abortTransaction();
res.status(400).json(false);
} else {
const respond = await SettingsController.updateSetting(setting, newValue);
res.status(respond === undefined ? 400 : 200).json(respond);
}
}
) |