feat: 新增已发布的问卷再次修改状态会变成修改中 (#20)

This commit is contained in:
luch 2023-12-06 17:07:48 +08:00 committed by GitHub
parent a891ad3351
commit e2fa7db310
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -82,13 +82,25 @@ class SurveyService {
const surveyMetaUpdateRes = await surveyMeta.updateOne({
_id,
owner: surveyParams.userData.username,
}, {
}, [{
$set: {
remark: surveyParams.remark,
title: surveyParams.title,
updateDate: Date.now(),
}
})
}, {
$set: {
"curStatus": {
$cond: {
if: {
$eq: ["$curStatus.status", "new"]
},
then: "$curStatus",
else: getStatusObject({ status: SURVEY_STATUS.editing })
}
}
}
}])
if (surveyMetaUpdateRes.matchedCount < 1) {
throw new CommonError("更新问卷信息失败,问卷不存在或您不是该问卷所有者")
}
@ -255,13 +267,30 @@ class SurveyService {
async saveConf(surveyData: { surveyId: string, configData: any }) {
const surveyConf = await mongo.getCollection({ collectionName: 'surveyConf' });
const surveyMeta = await mongo.getCollection({ collectionName: 'surveyMeta' });
const saveRes = await surveyConf.updateOne({
pageId: surveyData.surveyId
}, {
$set: {
code: surveyData.configData
code: surveyData.configData,
}
})
const _id = mongo.getObjectIdByStr(surveyData.surveyId)
surveyMeta.updateOne({
_id,
}, [{
$set: {
"curStatus": {
$cond: {
if: {
$eq: ["$curStatus.status", "new"]
},
then: "$curStatus",
else: getStatusObject({ status: SURVEY_STATUS.editing })
}
}
}
}])
return saveRes
}