fix: 修改默认模板,修改投票题数据回显问题 (#7)
This commit is contained in:
parent
02d6613d63
commit
936b0f52f4
@ -1,10 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
npm install
|
|
||||||
for appDir in `ls src/apps`
|
|
||||||
do
|
|
||||||
cd src/apps/$appDir
|
|
||||||
# 进行安装依赖
|
|
||||||
npm install
|
|
||||||
cd ../../../
|
|
||||||
done
|
|
||||||
cd ..
|
|
@ -120,7 +120,7 @@
|
|||||||
"optionOrigin": "",
|
"optionOrigin": "",
|
||||||
"answerTip": "",
|
"answerTip": "",
|
||||||
"type": "radio-star",
|
"type": "radio-star",
|
||||||
"title": "标题3",
|
"title": "标题2",
|
||||||
"answer": "",
|
"answer": "",
|
||||||
"othersKeyMap": {},
|
"othersKeyMap": {},
|
||||||
"options": [],
|
"options": [],
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
"type": "text",
|
"type": "text",
|
||||||
"valid": "",
|
"valid": "",
|
||||||
"field": "data631",
|
"field": "data631",
|
||||||
"title": "标题3",
|
"title": "标题1",
|
||||||
"placeholder": "",
|
"placeholder": "",
|
||||||
"sLimit": 1,
|
"sLimit": 1,
|
||||||
"randomSort": false,
|
"randomSort": false,
|
||||||
@ -85,7 +85,7 @@
|
|||||||
"innerType": "radio",
|
"innerType": "radio",
|
||||||
"placeholderDesc": "",
|
"placeholderDesc": "",
|
||||||
"field": "data606",
|
"field": "data606",
|
||||||
"title": "标题1",
|
"title": "标题2",
|
||||||
"placeholder": "",
|
"placeholder": "",
|
||||||
"randomSort": false,
|
"randomSort": false,
|
||||||
"checked": false,
|
"checked": false,
|
||||||
@ -93,7 +93,7 @@
|
|||||||
"maxNum": "",
|
"maxNum": "",
|
||||||
"options": [
|
"options": [
|
||||||
{
|
{
|
||||||
"text": "甜的",
|
"text": "选项1",
|
||||||
"imageUrl": "",
|
"imageUrl": "",
|
||||||
"others": false,
|
"others": false,
|
||||||
"mustOthers": false,
|
"mustOthers": false,
|
||||||
@ -102,7 +102,7 @@
|
|||||||
"hash": "115019"
|
"hash": "115019"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"text": "咸的",
|
"text": "选项2",
|
||||||
"imageUrl": "",
|
"imageUrl": "",
|
||||||
"others": false,
|
"others": false,
|
||||||
"mustOthers": false,
|
"mustOthers": false,
|
||||||
|
@ -2,7 +2,7 @@ import { mongo } from '../db/mongo'
|
|||||||
|
|
||||||
// 该服务用于模拟redis
|
// 该服务用于模拟redis
|
||||||
class SurveyKeyStoreService {
|
class SurveyKeyStoreService {
|
||||||
getKeyStoreResult(surveyKeyStoreData:Array<any>) {
|
getKeyStoreResult(surveyKeyStoreData: Array<any>) {
|
||||||
const surveyKeyStoreReult = {}
|
const surveyKeyStoreReult = {}
|
||||||
for (const surveyKeyStoreItem of surveyKeyStoreData) {
|
for (const surveyKeyStoreItem of surveyKeyStoreData) {
|
||||||
surveyKeyStoreReult[surveyKeyStoreItem.key] = surveyKeyStoreItem.data
|
surveyKeyStoreReult[surveyKeyStoreItem.key] = surveyKeyStoreItem.data
|
||||||
@ -10,29 +10,29 @@ class SurveyKeyStoreService {
|
|||||||
return surveyKeyStoreReult
|
return surveyKeyStoreReult
|
||||||
}
|
}
|
||||||
|
|
||||||
async set({surveyPath, key, data, type}) {
|
async set({ surveyPath, key, data, type }) {
|
||||||
const surveyKeyStore = await mongo.getCollection({collectionName:'surveyKeyStore'});
|
const surveyKeyStore = await mongo.getCollection({ collectionName: 'surveyKeyStore' });
|
||||||
const setResult = await surveyKeyStore.updateOne({
|
const setResult = await surveyKeyStore.updateOne({
|
||||||
key,
|
key,
|
||||||
surveyPath,
|
surveyPath,
|
||||||
type
|
type
|
||||||
},{
|
}, {
|
||||||
$set:{
|
$set: {
|
||||||
key,
|
key,
|
||||||
surveyPath,
|
surveyPath,
|
||||||
type,
|
type,
|
||||||
data,
|
data,
|
||||||
createDate:Date.now(),
|
createDate: Date.now(),
|
||||||
updateDate:Date.now(),
|
updateDate: Date.now(),
|
||||||
}
|
}
|
||||||
},{
|
}, {
|
||||||
upsert:true //如果不存在则插入
|
upsert: true //如果不存在则插入
|
||||||
})
|
})
|
||||||
return setResult
|
return setResult
|
||||||
}
|
}
|
||||||
|
|
||||||
async get({surveyPath,key,type}) {
|
async get({ surveyPath, key, type }) {
|
||||||
const surveyKeyStore = await mongo.getCollection({collectionName:'surveyKeyStore'});
|
const surveyKeyStore = await mongo.getCollection({ collectionName: 'surveyKeyStore' });
|
||||||
const surveyKeyStoreData = await surveyKeyStore.findOne({
|
const surveyKeyStoreData = await surveyKeyStore.findOne({
|
||||||
key,
|
key,
|
||||||
surveyPath,
|
surveyPath,
|
||||||
@ -41,16 +41,16 @@ class SurveyKeyStoreService {
|
|||||||
return surveyKeyStoreData?.data
|
return surveyKeyStoreData?.data
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAll({surveyPath,keyList,type}) {
|
async getAll({ surveyPath, keyList, type }) {
|
||||||
const surveyKeyStore = await mongo.getCollection({collectionName:'surveyKeyStore'});
|
const surveyKeyStore = await mongo.getCollection({ collectionName: 'surveyKeyStore' });
|
||||||
const surveyKeyStoreData = await surveyKeyStore.find({
|
const surveyKeyStoreData = await surveyKeyStore.find({
|
||||||
key:{$in:keyList},
|
key: { $in: keyList },
|
||||||
surveyPath,
|
surveyPath,
|
||||||
type
|
type
|
||||||
}).toArray()
|
}).toArray()
|
||||||
return this.getKeyStoreResult(surveyKeyStoreData)
|
return this.getKeyStoreResult(surveyKeyStoreData)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const surveyKeyStoreService = new SurveyKeyStoreService()
|
export const surveyKeyStoreService = new SurveyKeyStoreService()
|
@ -1,18 +1,18 @@
|
|||||||
import { mongo } from '../db/mongo'
|
import { mongo } from '../db/mongo'
|
||||||
import { surveyKeyStoreService } from './surveyKeyStoreService'
|
import { surveyKeyStoreService } from './surveyKeyStoreService'
|
||||||
import {CommonError} from '../../../types/index'
|
import { CommonError } from '../../../types/index'
|
||||||
|
|
||||||
class SurveyPublishService {
|
class SurveyPublishService {
|
||||||
async get({surveyPath}:{surveyPath:string}) {
|
async get({ surveyPath }: { surveyPath: string }) {
|
||||||
const surveyMeta = await mongo.getCollection({collectionName:'surveyMeta'});
|
const surveyMeta = await mongo.getCollection({ collectionName: 'surveyMeta' });
|
||||||
const surveyMetaData = await surveyMeta.findOne({surveyPath})
|
const surveyMetaData = await surveyMeta.findOne({ surveyPath })
|
||||||
if(!surveyMetaData) {
|
if (!surveyMetaData) {
|
||||||
throw new CommonError('该问卷已不存在')
|
throw new CommonError('该问卷已不存在')
|
||||||
}
|
}
|
||||||
const surveyMetaRes = mongo.convertId2StringByDoc(surveyMetaData)
|
const surveyMetaRes = mongo.convertId2StringByDoc(surveyMetaData)
|
||||||
const surveyPublish = await mongo.getCollection({collectionName:'surveyPublish'});
|
const surveyPublish = await mongo.getCollection({ collectionName: 'surveyPublish' });
|
||||||
const surveyPublishData = await surveyPublish.findOne({pageId:surveyMetaRes._id.toString()},{sort:{createDate:-1}})
|
const surveyPublishData = await surveyPublish.findOne({ pageId: surveyMetaRes._id.toString() }, { sort: { createDate: -1 } })
|
||||||
if(!surveyPublishData) {
|
if (!surveyPublishData) {
|
||||||
throw new CommonError('该问卷未发布')
|
throw new CommonError('该问卷未发布')
|
||||||
}
|
}
|
||||||
const surveyPublishRes = mongo.convertId2StringByDoc(surveyPublishData)
|
const surveyPublishRes = mongo.convertId2StringByDoc(surveyPublishData)
|
||||||
@ -22,10 +22,10 @@ class SurveyPublishService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async queryVote({surveyPath,voteKeyList}:{surveyPath:string, voteKeyList:Array<string>}) {
|
async queryVote({ surveyPath, voteKeyList }: { surveyPath: string, voteKeyList: Array<string> }) {
|
||||||
return await surveyKeyStoreService.getAll({surveyPath,keyList:voteKeyList,type:'vote'})
|
return await surveyKeyStoreService.getAll({ surveyPath, keyList: voteKeyList, type: 'vote' })
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const surveyPublishService = new SurveyPublishService()
|
export const surveyPublishService = new SurveyPublishService()
|
@ -62,11 +62,14 @@ class SurveySubmitService {
|
|||||||
const configData = dataListMap[field]
|
const configData = dataListMap[field]
|
||||||
if (configData && /vote/.exec(configData.type)) {
|
if (configData && /vote/.exec(configData.type)) {
|
||||||
const voteData = (await surveyKeyStoreService.get({ surveyPath: surveySubmitData.surveyPath, key: field, type: 'vote' })) || { total: 0 }
|
const voteData = (await surveyKeyStoreService.get({ surveyPath: surveySubmitData.surveyPath, key: field, type: 'vote' })) || { total: 0 }
|
||||||
voteData.total++;
|
const fields = Array.isArray(surveySubmitData.data[field]) ? surveySubmitData.data[field] : [surveySubmitData.data[field]]
|
||||||
if (!voteData[surveySubmitData.data[field]]) {
|
for (const field of fields) {
|
||||||
voteData[surveySubmitData.data[field]] = 1
|
voteData.total++;
|
||||||
} else {
|
if (!voteData[field]) {
|
||||||
voteData[surveySubmitData.data[field]]++;
|
voteData[field] = 1
|
||||||
|
} else {
|
||||||
|
voteData[field]++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await surveyKeyStoreService.set({ surveyPath: surveySubmitData.surveyPath, key: field, data: voteData, type: 'vote' })
|
await surveyKeyStoreService.set({ surveyPath: surveySubmitData.surveyPath, key: field, data: voteData, type: 'vote' })
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 8.9 KiB |
Loading…
Reference in New Issue
Block a user