Can share survey results with a secret shared key
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
9fd73ce235
commit
fff8b821c5
10 changed files with 367 additions and 7 deletions
|
|
@ -7,7 +7,7 @@
|
|||
export let question = null;
|
||||
|
||||
function refreshProposals() {
|
||||
let req = question.getProposals();
|
||||
let req = question.getProposals(secret);
|
||||
|
||||
req.then((proposals) => {
|
||||
const proposal_idx = { };
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
proposal_idx[proposal.id] = new String(data.labels.length - 1);
|
||||
}
|
||||
|
||||
req_responses = question.getResponses();
|
||||
req_responses = question.getResponses(secret);
|
||||
req_responses.then((responses) => {
|
||||
for (const res of responses) {
|
||||
const rsplt = res.value.split(',');
|
||||
|
|
@ -32,6 +32,7 @@
|
|||
}
|
||||
let req_proposals = null;
|
||||
export let proposals = null;
|
||||
export let secret = null;
|
||||
let req_responses = null;
|
||||
let mean = null;
|
||||
|
||||
|
|
@ -46,7 +47,7 @@
|
|||
|
||||
if (!proposals) {
|
||||
if (question.kind && (question.kind == "int" || question.kind.startsWith("list"))) {
|
||||
req_responses = question.getResponses();
|
||||
req_responses = question.getResponses(secret);
|
||||
req_responses.then((responses) => {
|
||||
const values = [];
|
||||
const proposal_idx = { };
|
||||
|
|
|
|||
|
|
@ -62,8 +62,10 @@ export class Question {
|
|||
this.kind = kind;
|
||||
}
|
||||
|
||||
async getProposals() {
|
||||
const res = await fetch(`api/questions/${this.id}/proposals`, {
|
||||
async getProposals(secret) {
|
||||
let url = `/questions/${this.id}/proposals`;
|
||||
if (secret) url = `/s/surveys/${this.id_survey}` + url + `?secret=${secret}`;
|
||||
const res = await fetch('api' + url, {
|
||||
method: 'GET',
|
||||
headers: {'Accept': 'application/json'},
|
||||
});
|
||||
|
|
@ -91,8 +93,10 @@ export class Question {
|
|||
}
|
||||
}
|
||||
|
||||
async getResponses() {
|
||||
const res = await fetch(`api/surveys/${this.id_survey}/questions/${this.id}/responses`, {
|
||||
async getResponses(secret) {
|
||||
let url = `/surveys/${this.id_survey}/questions/${this.id}/responses`;
|
||||
if (secret) url = `/s` + url + `?secret=${secret}`;
|
||||
const res = await fetch('api' + url, {
|
||||
method: 'GET',
|
||||
headers: {'Accept': 'application/json'},
|
||||
});
|
||||
|
|
@ -161,3 +165,17 @@ export async function getQuestions(sid) {
|
|||
throw new Error((await res.json()).errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getSharedQuestions(sid, secret) {
|
||||
const res = await fetch(`api/s/surveys/${sid}/questions?secret=${secret}`, {headers: {'Accept': 'application/json'}})
|
||||
if (res.status == 200) {
|
||||
const data = await res.json();
|
||||
if (data === null) {
|
||||
return [];
|
||||
} else {
|
||||
return (data).map((q) => new Question(q))
|
||||
}
|
||||
} else {
|
||||
throw new Error((await res.json()).errmsg);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,6 +73,18 @@ export class Survey {
|
|||
}
|
||||
}
|
||||
|
||||
async share() {
|
||||
const res = await fetch(`api/surveys/${this.id}/shares`, {
|
||||
method: 'POST',
|
||||
headers: {'Accept': 'application/json'}
|
||||
});
|
||||
if (res.status == 200) {
|
||||
return await res.json();
|
||||
} else {
|
||||
throw new Error((await res.json()).errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
async save() {
|
||||
const res = await fetch(this.id?`api/surveys/${this.id}`:'api/surveys', {
|
||||
method: this.id?'PUT':'POST',
|
||||
|
|
@ -190,3 +202,12 @@ export async function getSurvey(sid) {
|
|||
throw new Error((await res.json()).errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getSharedSurvey(sid, secret) {
|
||||
const res = await fetch(`api/s/surveys/${sid}?secret=${secret}`, {headers: {'Accept': 'application/json'}})
|
||||
if (res.status == 200) {
|
||||
return new Survey(await res.json());
|
||||
} else {
|
||||
throw new Error((await res.json()).errmsg);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue