feat: 新增已发布的问卷再次修改状态会变成修改中 (#20)
This commit is contained in:
parent
a891ad3351
commit
e2fa7db310
@ -82,13 +82,25 @@ class SurveyService {
|
|||||||
const surveyMetaUpdateRes = await surveyMeta.updateOne({
|
const surveyMetaUpdateRes = await surveyMeta.updateOne({
|
||||||
_id,
|
_id,
|
||||||
owner: surveyParams.userData.username,
|
owner: surveyParams.userData.username,
|
||||||
}, {
|
}, [{
|
||||||
$set: {
|
$set: {
|
||||||
remark: surveyParams.remark,
|
remark: surveyParams.remark,
|
||||||
title: surveyParams.title,
|
title: surveyParams.title,
|
||||||
updateDate: Date.now(),
|
updateDate: Date.now(),
|
||||||
}
|
}
|
||||||
})
|
}, {
|
||||||
|
$set: {
|
||||||
|
"curStatus": {
|
||||||
|
$cond: {
|
||||||
|
if: {
|
||||||
|
$eq: ["$curStatus.status", "new"]
|
||||||
|
},
|
||||||
|
then: "$curStatus",
|
||||||
|
else: getStatusObject({ status: SURVEY_STATUS.editing })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}])
|
||||||
if (surveyMetaUpdateRes.matchedCount < 1) {
|
if (surveyMetaUpdateRes.matchedCount < 1) {
|
||||||
throw new CommonError("更新问卷信息失败,问卷不存在或您不是该问卷所有者")
|
throw new CommonError("更新问卷信息失败,问卷不存在或您不是该问卷所有者")
|
||||||
}
|
}
|
||||||
@ -129,10 +141,10 @@ class SurveyService {
|
|||||||
getListHeadByDataList(dataList) {
|
getListHeadByDataList(dataList) {
|
||||||
const listHead = dataList.map(surveyItem => {
|
const listHead = dataList.map(surveyItem => {
|
||||||
let othersCode;
|
let othersCode;
|
||||||
if(surveyItem.type === 'radio-star') {
|
if (surveyItem.type === 'radio-star') {
|
||||||
const rangeConfigKeys = Object.keys(surveyItem.rangeConfig)
|
const rangeConfigKeys = Object.keys(surveyItem.rangeConfig)
|
||||||
if(rangeConfigKeys.length>0) {
|
if (rangeConfigKeys.length > 0) {
|
||||||
othersCode = [{code: `${surveyItem.field}_custom`, option: "填写理由"}]
|
othersCode = [{ code: `${surveyItem.field}_custom`, option: "填写理由" }]
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
othersCode = (surveyItem.options || [])
|
othersCode = (surveyItem.options || [])
|
||||||
@ -164,7 +176,7 @@ class SurveyService {
|
|||||||
return listHead
|
return listHead
|
||||||
}
|
}
|
||||||
|
|
||||||
async data(condition: { userData:UserType,surveyId: string, pageNum: number, pageSize: number, isShowSecret: boolean }) {
|
async data(condition: { userData: UserType, surveyId: string, pageNum: number, pageSize: number, isShowSecret: boolean }) {
|
||||||
const surveyObjectId = mongo.getObjectIdByStr(condition.surveyId)
|
const surveyObjectId = mongo.getObjectIdByStr(condition.surveyId)
|
||||||
const surveyMeta = await mongo.getCollection({ collectionName: 'surveyMeta' });
|
const surveyMeta = await mongo.getCollection({ collectionName: 'surveyMeta' });
|
||||||
const surveyMetaData = await surveyMeta.findOne({ _id: surveyObjectId })
|
const surveyMetaData = await surveyMeta.findOne({ _id: surveyObjectId })
|
||||||
@ -185,15 +197,15 @@ class SurveyService {
|
|||||||
const listBody = surveySubmitData.map((surveySubmitResList) => {
|
const listBody = surveySubmitData.map((surveySubmitResList) => {
|
||||||
const data = surveySubmitResList.data
|
const data = surveySubmitResList.data
|
||||||
const dataKeys = Object.keys(data)
|
const dataKeys = Object.keys(data)
|
||||||
for(const itemKey of dataKeys) {
|
for (const itemKey of dataKeys) {
|
||||||
if(typeof itemKey !== 'string') {continue}
|
if (typeof itemKey !== 'string') { continue }
|
||||||
if(itemKey.indexOf("data")!==0) {continue}
|
if (itemKey.indexOf("data") !== 0) { continue }
|
||||||
const itemConfigKey = itemKey.split("_")[0];
|
const itemConfigKey = itemKey.split("_")[0];
|
||||||
const itemConfig = dataListMap[itemConfigKey];
|
const itemConfig = dataListMap[itemConfigKey];
|
||||||
// 题目删除会出现,数据列表报错
|
// 题目删除会出现,数据列表报错
|
||||||
if(!itemConfig) {continue}
|
if (!itemConfig) { continue }
|
||||||
const doSecretData = (data)=>{
|
const doSecretData = (data) => {
|
||||||
if(itemConfig.isSecret && condition.isShowSecret) {
|
if (itemConfig.isSecret && condition.isShowSecret) {
|
||||||
return hanleSensitiveDate(data)
|
return hanleSensitiveDate(data)
|
||||||
} else {
|
} else {
|
||||||
return data;
|
return data;
|
||||||
@ -201,7 +213,7 @@ class SurveyService {
|
|||||||
}
|
}
|
||||||
data[itemKey] = doSecretData(data[itemKey])
|
data[itemKey] = doSecretData(data[itemKey])
|
||||||
// 处理选项
|
// 处理选项
|
||||||
if(itemConfig.type === 'radio-star' && !data[`${itemConfigKey}_custom`]) {
|
if (itemConfig.type === 'radio-star' && !data[`${itemConfigKey}_custom`]) {
|
||||||
data[`${itemConfigKey}_custom`] = data[`${itemConfigKey}_${data[itemConfigKey]}`]
|
data[`${itemConfigKey}_custom`] = data[`${itemConfigKey}_${data[itemConfigKey]}`]
|
||||||
}
|
}
|
||||||
if (!itemConfig?.options?.length) { continue }
|
if (!itemConfig?.options?.length) { continue }
|
||||||
@ -255,13 +267,30 @@ class SurveyService {
|
|||||||
|
|
||||||
async saveConf(surveyData: { surveyId: string, configData: any }) {
|
async saveConf(surveyData: { surveyId: string, configData: any }) {
|
||||||
const surveyConf = await mongo.getCollection({ collectionName: 'surveyConf' });
|
const surveyConf = await mongo.getCollection({ collectionName: 'surveyConf' });
|
||||||
|
const surveyMeta = await mongo.getCollection({ collectionName: 'surveyMeta' });
|
||||||
const saveRes = await surveyConf.updateOne({
|
const saveRes = await surveyConf.updateOne({
|
||||||
pageId: surveyData.surveyId
|
pageId: surveyData.surveyId
|
||||||
}, {
|
}, {
|
||||||
$set: {
|
$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
|
return saveRes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user