mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-06 15:49:01 +02:00
3d26c4bb6f
* Setup survey module and admin page skeleton * Replace survey staff access permission with admin-only * Manage survey config with admin tool * Display configurable survey in project list + add preview in admin * Fix linting errors and unit tests * Add acceptance tests for survey module * Move survey-form to survey components * Add configuration option for Recurly group subscription users on surveys * Change survey pre-link text to a lighter gray for accessibility * Cleanup survey options implementation after review GitOrigin-RevId: 8f621951efeae458d1ab081fe98b8d0d539cca1a
38 lines
751 B
JavaScript
38 lines
751 B
JavaScript
const { Survey } = require('../../models/Survey')
|
|
const OError = require('@overleaf/o-error')
|
|
|
|
async function getSurvey() {
|
|
try {
|
|
return await Survey.findOne().exec()
|
|
} catch (error) {
|
|
throw OError.tag(error, 'Failed to get survey')
|
|
}
|
|
}
|
|
|
|
async function updateSurvey({ name, preText, linkText, url, options }) {
|
|
let survey = await getSurvey()
|
|
if (!survey) {
|
|
survey = new Survey()
|
|
}
|
|
survey.name = name
|
|
survey.preText = preText
|
|
survey.linkText = linkText
|
|
survey.url = url
|
|
survey.options = options
|
|
await survey.save()
|
|
return survey
|
|
}
|
|
|
|
async function deleteSurvey() {
|
|
const survey = await getSurvey()
|
|
if (survey) {
|
|
await survey.remove()
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
getSurvey,
|
|
updateSurvey,
|
|
deleteSurvey,
|
|
}
|