mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 21:23:45 +01:00
Configurable split tests system GitOrigin-RevId: 908dc4f681668b32e95204314ac0d5727f269e65
78 lines
1.8 KiB
JavaScript
78 lines
1.8 KiB
JavaScript
const SplitTestManager = require('./SplitTestManager')
|
|
|
|
async function getSplitTests(req, res, next) {
|
|
try {
|
|
const splitTests = await SplitTestManager.getSplitTests()
|
|
res.send(splitTests)
|
|
} catch (error) {
|
|
res.status(500).json({
|
|
error: `Error while fetching split tests list: ${error.message}`,
|
|
})
|
|
}
|
|
}
|
|
|
|
async function createSplitTest(req, res, next) {
|
|
const { name, configuration } = req.body
|
|
try {
|
|
const splitTest = await SplitTestManager.createSplitTest(
|
|
name,
|
|
configuration
|
|
)
|
|
res.send(splitTest)
|
|
} catch (error) {
|
|
res
|
|
.status(500)
|
|
.json({ error: `Error while creating split test: ${error.message}` })
|
|
}
|
|
}
|
|
|
|
async function updateSplitTest(req, res, next) {
|
|
const { name, configuration } = req.body
|
|
try {
|
|
const splitTest = await SplitTestManager.updateSplitTest(
|
|
name,
|
|
configuration
|
|
)
|
|
res.send(splitTest)
|
|
} catch (error) {
|
|
res
|
|
.status(500)
|
|
.json({ error: `Error while updating split test: ${error.message}` })
|
|
}
|
|
}
|
|
|
|
async function switchToNextPhase(req, res, next) {
|
|
const { name } = req.body
|
|
try {
|
|
const splitTest = await SplitTestManager.switchToNextPhase(name)
|
|
res.send(splitTest)
|
|
} catch (error) {
|
|
res.status(500).json({
|
|
error: `Error while switching split test to next phase: ${error.message}`,
|
|
})
|
|
}
|
|
}
|
|
|
|
async function revertToPreviousVersion(req, res, next) {
|
|
const { name, versionNumber } = req.body
|
|
try {
|
|
const splitTest = await SplitTestManager.revertToPreviousVersion(
|
|
name,
|
|
versionNumber
|
|
)
|
|
res.send(splitTest)
|
|
} catch (error) {
|
|
res.status(500).json({
|
|
error: `Error while reverting to previous version: ${error.message}`,
|
|
})
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
getSplitTests,
|
|
createSplitTest,
|
|
updateSplitTest,
|
|
switchToNextPhase,
|
|
revertToPreviousVersion,
|
|
}
|