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": "",
|
||||
"answerTip": "",
|
||||
"type": "radio-star",
|
||||
"title": "标题3",
|
||||
"title": "标题2",
|
||||
"answer": "",
|
||||
"othersKeyMap": {},
|
||||
"options": [],
|
||||
|
@ -20,7 +20,7 @@
|
||||
"type": "text",
|
||||
"valid": "",
|
||||
"field": "data631",
|
||||
"title": "标题3",
|
||||
"title": "标题1",
|
||||
"placeholder": "",
|
||||
"sLimit": 1,
|
||||
"randomSort": false,
|
||||
@ -85,7 +85,7 @@
|
||||
"innerType": "radio",
|
||||
"placeholderDesc": "",
|
||||
"field": "data606",
|
||||
"title": "标题1",
|
||||
"title": "标题2",
|
||||
"placeholder": "",
|
||||
"randomSort": false,
|
||||
"checked": false,
|
||||
@ -93,7 +93,7 @@
|
||||
"maxNum": "",
|
||||
"options": [
|
||||
{
|
||||
"text": "甜的",
|
||||
"text": "选项1",
|
||||
"imageUrl": "",
|
||||
"others": false,
|
||||
"mustOthers": false,
|
||||
@ -102,7 +102,7 @@
|
||||
"hash": "115019"
|
||||
},
|
||||
{
|
||||
"text": "咸的",
|
||||
"text": "选项2",
|
||||
"imageUrl": "",
|
||||
"others": false,
|
||||
"mustOthers": false,
|
||||
|
@ -2,7 +2,7 @@ import { mongo } from '../db/mongo'
|
||||
|
||||
// 该服务用于模拟redis
|
||||
class SurveyKeyStoreService {
|
||||
getKeyStoreResult(surveyKeyStoreData:Array<any>) {
|
||||
getKeyStoreResult(surveyKeyStoreData: Array<any>) {
|
||||
const surveyKeyStoreReult = {}
|
||||
for (const surveyKeyStoreItem of surveyKeyStoreData) {
|
||||
surveyKeyStoreReult[surveyKeyStoreItem.key] = surveyKeyStoreItem.data
|
||||
@ -10,29 +10,29 @@ class SurveyKeyStoreService {
|
||||
return surveyKeyStoreReult
|
||||
}
|
||||
|
||||
async set({surveyPath, key, data, type}) {
|
||||
const surveyKeyStore = await mongo.getCollection({collectionName:'surveyKeyStore'});
|
||||
async set({ surveyPath, key, data, type }) {
|
||||
const surveyKeyStore = await mongo.getCollection({ collectionName: 'surveyKeyStore' });
|
||||
const setResult = await surveyKeyStore.updateOne({
|
||||
key,
|
||||
surveyPath,
|
||||
type
|
||||
},{
|
||||
$set:{
|
||||
}, {
|
||||
$set: {
|
||||
key,
|
||||
surveyPath,
|
||||
type,
|
||||
data,
|
||||
createDate:Date.now(),
|
||||
updateDate:Date.now(),
|
||||
createDate: Date.now(),
|
||||
updateDate: Date.now(),
|
||||
}
|
||||
},{
|
||||
upsert:true //如果不存在则插入
|
||||
}, {
|
||||
upsert: true //如果不存在则插入
|
||||
})
|
||||
return setResult
|
||||
}
|
||||
|
||||
async get({surveyPath,key,type}) {
|
||||
const surveyKeyStore = await mongo.getCollection({collectionName:'surveyKeyStore'});
|
||||
async get({ surveyPath, key, type }) {
|
||||
const surveyKeyStore = await mongo.getCollection({ collectionName: 'surveyKeyStore' });
|
||||
const surveyKeyStoreData = await surveyKeyStore.findOne({
|
||||
key,
|
||||
surveyPath,
|
||||
@ -41,16 +41,16 @@ class SurveyKeyStoreService {
|
||||
return surveyKeyStoreData?.data
|
||||
}
|
||||
|
||||
async getAll({surveyPath,keyList,type}) {
|
||||
const surveyKeyStore = await mongo.getCollection({collectionName:'surveyKeyStore'});
|
||||
async getAll({ surveyPath, keyList, type }) {
|
||||
const surveyKeyStore = await mongo.getCollection({ collectionName: 'surveyKeyStore' });
|
||||
const surveyKeyStoreData = await surveyKeyStore.find({
|
||||
key:{$in:keyList},
|
||||
key: { $in: keyList },
|
||||
surveyPath,
|
||||
type
|
||||
}).toArray()
|
||||
return this.getKeyStoreResult(surveyKeyStoreData)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
export const surveyKeyStoreService = new SurveyKeyStoreService()
|
@ -1,18 +1,18 @@
|
||||
import { mongo } from '../db/mongo'
|
||||
import { surveyKeyStoreService } from './surveyKeyStoreService'
|
||||
import {CommonError} from '../../../types/index'
|
||||
import { CommonError } from '../../../types/index'
|
||||
|
||||
class SurveyPublishService {
|
||||
async get({surveyPath}:{surveyPath:string}) {
|
||||
const surveyMeta = await mongo.getCollection({collectionName:'surveyMeta'});
|
||||
const surveyMetaData = await surveyMeta.findOne({surveyPath})
|
||||
if(!surveyMetaData) {
|
||||
async get({ surveyPath }: { surveyPath: string }) {
|
||||
const surveyMeta = await mongo.getCollection({ collectionName: 'surveyMeta' });
|
||||
const surveyMetaData = await surveyMeta.findOne({ surveyPath })
|
||||
if (!surveyMetaData) {
|
||||
throw new CommonError('该问卷已不存在')
|
||||
}
|
||||
const surveyMetaRes = mongo.convertId2StringByDoc(surveyMetaData)
|
||||
const surveyPublish = await mongo.getCollection({collectionName:'surveyPublish'});
|
||||
const surveyPublishData = await surveyPublish.findOne({pageId:surveyMetaRes._id.toString()},{sort:{createDate:-1}})
|
||||
if(!surveyPublishData) {
|
||||
const surveyPublish = await mongo.getCollection({ collectionName: 'surveyPublish' });
|
||||
const surveyPublishData = await surveyPublish.findOne({ pageId: surveyMetaRes._id.toString() }, { sort: { createDate: -1 } })
|
||||
if (!surveyPublishData) {
|
||||
throw new CommonError('该问卷未发布')
|
||||
}
|
||||
const surveyPublishRes = mongo.convertId2StringByDoc(surveyPublishData)
|
||||
@ -22,10 +22,10 @@ class SurveyPublishService {
|
||||
}
|
||||
}
|
||||
|
||||
async queryVote({surveyPath,voteKeyList}:{surveyPath:string, voteKeyList:Array<string>}) {
|
||||
return await surveyKeyStoreService.getAll({surveyPath,keyList:voteKeyList,type:'vote'})
|
||||
async queryVote({ surveyPath, voteKeyList }: { surveyPath: string, voteKeyList: Array<string> }) {
|
||||
return await surveyKeyStoreService.getAll({ surveyPath, keyList: voteKeyList, type: 'vote' })
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
export const surveyPublishService = new SurveyPublishService()
|
@ -62,11 +62,14 @@ class SurveySubmitService {
|
||||
const configData = dataListMap[field]
|
||||
if (configData && /vote/.exec(configData.type)) {
|
||||
const voteData = (await surveyKeyStoreService.get({ surveyPath: surveySubmitData.surveyPath, key: field, type: 'vote' })) || { total: 0 }
|
||||
voteData.total++;
|
||||
if (!voteData[surveySubmitData.data[field]]) {
|
||||
voteData[surveySubmitData.data[field]] = 1
|
||||
} else {
|
||||
voteData[surveySubmitData.data[field]]++;
|
||||
const fields = Array.isArray(surveySubmitData.data[field]) ? surveySubmitData.data[field] : [surveySubmitData.data[field]]
|
||||
for (const field of fields) {
|
||||
voteData.total++;
|
||||
if (!voteData[field]) {
|
||||
voteData[field] = 1
|
||||
} else {
|
||||
voteData[field]++;
|
||||
}
|
||||
}
|
||||
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