Commit 4ee89757 authored by antoine masson's avatar antoine masson
Browse files

v0.7

-Add access token mng
- New template files for language
- Update survey model for access token and analysis text
parent 1b219e6c
...@@ -25,7 +25,7 @@ async function json2mango(datajson,mongo){ ...@@ -25,7 +25,7 @@ async function json2mango(datajson,mongo){
exports.dropSurvey = async (req, res) => { exports.dropSurvey = async (req, res) => {
try { try {
await Survey.collection.drop(); // await Survey.collection.drop();
await Survey.syncIndexes(); await Survey.syncIndexes();
return res.status(201).json({ return res.status(201).json({
message: "Survey drop", message: "Survey drop",
...@@ -463,6 +463,8 @@ exports.getSurveykey = async (req, res) => { ...@@ -463,6 +463,8 @@ exports.getSurveykey = async (req, res) => {
} else if (key === "rational"){ } else if (key === "rational"){
let tmp=[] let tmp=[]
survey.general.conclusiontext.content = survey.general.conclusiontext.content.find(o => o.language === req.userData.language)
survey.alternatives.content = survey.alternatives.content.find(o => o.language === req.userData.language) survey.alternatives.content = survey.alternatives.content.find(o => o.language === req.userData.language)
for(let item of survey.alternatives.items){ for(let item of survey.alternatives.items){
if(item.enable) { if(item.enable) {
......
const mongoose = require('mongoose'); const mongoose = require('mongoose');
const Token = mongoose.model('Token'); const Token = mongoose.model('Token');
const Survey = mongoose.model('Survey');
exports.registerNewToken = async (req, res) => { exports.registerNewToken = async (req, res) => {
try { try {
...@@ -136,8 +137,37 @@ exports.loginToken = async (req, res) => { ...@@ -136,8 +137,37 @@ exports.loginToken = async (req, res) => {
res.status(400).json({ message: err,status:"Error"}); res.status(400).json({ message: err,status:"Error"});
} }
}; };
exports.accessToken = async (req, res) => {
if(await Survey.isAccessToken(req.body.survey_id)){
try{
//TODO : add survey verification
let token = await Token.findOne({ token:req.body.token });
if (!token) { //create new token if doesn't exist
const newtoken = new Token({
token: req.body.token,
survey_id: req.body.survey_id,
enable: "true",
status:"new",
comments:"Created with API access token",
test:"false",
});
token = await newtoken.save();
}
if(!token.enable){
return res
.status(201)
.json({ message: "Token disabled!" ,status: "Error"});
}
const authtoken = await token.generateAuthToken();
res.status(201).json({ token:authtoken, message : "Succeeded Login", status: "OK"});
} catch(err){
res.status(400).json({ message: err,status:"Error"});
}
} else {
res.status(400).json({ message: "Forbidden Operation",status:"Error"});
}
}
exports.getTokenDetails = async (req, res) => { exports.getTokenDetails = async (req, res) => {
try { try {
......
...@@ -48,7 +48,6 @@ const objschema = new Schema({ ...@@ -48,7 +48,6 @@ const objschema = new Schema({
_id:mongoose.ObjectId, _id:mongoose.ObjectId,
short_name: { short_name: {
type: String, type: String,
index: { unique: true, sparse: true }
}, },
description: { description: {
type: String, type: String,
...@@ -203,6 +202,9 @@ const SurveySchema = new Schema({ ...@@ -203,6 +202,9 @@ const SurveySchema = new Schema({
required: true, required: true,
default: true, default: true,
}, },
conclusiontext:{
content:[text],
}
}, },
alternatives:{ alternatives:{
...@@ -220,6 +222,19 @@ const SurveySchema = new Schema({ ...@@ -220,6 +222,19 @@ const SurveySchema = new Schema({
SurveySchema.statics.checkExistingField = async function(field, value) { SurveySchema.statics.checkExistingField = async function(field, value) {
return await this.findOne({[`${field}`]: value}); return await this.findOne({[`${field}`]: value});
}; };
SurveySchema.statics.isAccessToken = async function(survey_id){
let survey
try {
survey = await this.findById(survey_id);
} catch {
return false
}
if (survey){
return survey.general.externalurl.enableeentryurl
} else {
return false
}
};
SurveySchema.virtual('status').get(function() { SurveySchema.virtual('status').get(function() {
return "TODO"; return "TODO";
}); });
......
...@@ -382,5 +382,37 @@ ...@@ -382,5 +382,37 @@
"createdAt": "2021-03-18T20:07:24.198Z", "createdAt": "2021-03-18T20:07:24.198Z",
"updatedAt": "2021-03-18T20:07:24.198Z", "updatedAt": "2021-03-18T20:07:24.198Z",
"id": "6053b2fcfe227d253226a971" "id": "6053b2fcfe227d253226a971"
},
{
"type": "html",
"field": "RATIONAL_CONCLUSION_OBJANAL",
"description": "Text on top of objectives analysis on rational conclusion",
"createdAt": "2021-03-25T21:49:19.303Z",
"updatedAt": "2021-03-25T21:49:19.303Z",
"id": "605d055f0383356fef7c795b"
},
{
"type": "html",
"field": "RATIONAL_CONCLUSION_MATCH",
"description": "Text on bottom of alternatives analysis on rational conclusion when matching",
"createdAt": "2021-03-25T21:50:00.030Z",
"updatedAt": "2021-03-25T21:50:00.030Z",
"id": "605d05880383356fef7c795c"
},
{
"type": "html",
"field": "RATIONAL_CONCLUSION_NOMATCH",
"description": "Text on bottom of alternatives analysis on rational conclusion when no matching",
"createdAt": "2021-03-25T21:50:12.745Z",
"updatedAt": "2021-03-25T21:50:12.745Z",
"id": "605d05940383356fef7c795d"
},
{
"type": "String",
"field": "REDIRECTURL",
"description": "Text displayed when redirect to an external URL",
"createdAt": "2021-03-26T21:44:32.682Z",
"updatedAt": "2021-03-26T21:44:32.682Z",
"id": "605e55c052816f12906632fa"
} }
] ]
\ No newline at end of file
...@@ -4,302 +4,326 @@ ...@@ -4,302 +4,326 @@
"flag": "gb", "flag": "gb",
"fields": [ "fields": [
{ {
"_id": "6054b73ffe227d253226a9ac", "_id": "605e55c952816f12906632fb",
"field": "NEXT", "field": "NEXT",
"text": "next", "text": "next",
"id": "6054b73ffe227d253226a9ac" "id": "605e55c952816f12906632fb"
}, },
{ {
"_id": "6054b73ffe227d253226a9ad", "_id": "605e55c952816f12906632fc",
"field": "WELCOME", "field": "WELCOME",
"text": "welcome", "text": "welcome",
"id": "6054b73ffe227d253226a9ad" "id": "605e55c952816f12906632fc"
}, },
{ {
"_id": "6054b73ffe227d253226a9ae", "_id": "605e55c952816f12906632fd",
"field": "ACCEPT", "field": "ACCEPT",
"text": "accept", "text": "accept",
"id": "6054b73ffe227d253226a9ae" "id": "605e55c952816f12906632fd"
}, },
{ {
"_id": "6054b73ffe227d253226a9af", "_id": "605e55c952816f12906632fe",
"field": "REFUSE", "field": "REFUSE",
"text": "refuse", "text": "refuse",
"id": "6054b73ffe227d253226a9af" "id": "605e55c952816f12906632fe"
}, },
{ {
"_id": "6054b73ffe227d253226a9b0", "_id": "605e55c952816f12906632ff",
"field": "PREVIOUS", "field": "PREVIOUS",
"text": "previous", "text": "previous",
"id": "6054b73ffe227d253226a9b0" "id": "605e55c952816f12906632ff"
}, },
{ {
"_id": "6054b73ffe227d253226a9b1", "_id": "605e55c952816f1290663300",
"field": "POC", "field": "POC",
"text": "Person of Contact", "text": "Person of Contact",
"id": "6054b73ffe227d253226a9b1" "id": "605e55c952816f1290663300"
}, },
{ {
"_id": "6054b73ffe227d253226a9b2", "_id": "605e55c952816f1290663301",
"field": "AGREEMENT", "field": "AGREEMENT",
"text": "I accept that my data are used ...", "text": "I accept that my data are used ...",
"id": "6054b73ffe227d253226a9b2" "id": "605e55c952816f1290663301"
}, },
{ {
"_id": "6054b73ffe227d253226a9b3", "_id": "605e55c952816f1290663302",
"field": "AGREETITLE", "field": "AGREETITLE",
"text": "Data Use Agreements", "text": "Data Use Agreements",
"id": "6054b73ffe227d253226a9b3" "id": "605e55c952816f1290663302"
}, },
{ {
"_id": "6054b73ffe227d253226a9b4", "_id": "605e55c952816f1290663303",
"field": "AGREE", "field": "AGREE",
"text": "agree", "text": "agree",
"id": "6054b73ffe227d253226a9b4" "id": "605e55c952816f1290663303"
}, },
{ {
"_id": "6054b73ffe227d253226a9b5", "_id": "605e55c952816f1290663304",
"field": "SELECTONE", "field": "SELECTONE",
"text": "You need to select one value", "text": "You need to select one value",
"id": "6054b73ffe227d253226a9b5" "id": "605e55c952816f1290663304"
}, },
{ {
"_id": "6054b73ffe227d253226a9b6", "_id": "605e55c952816f1290663305",
"field": "USEMAX", "field": "USEMAX",
"text": "Please use maximum", "text": "Please use maximum",
"id": "6054b73ffe227d253226a9b6" "id": "605e55c952816f1290663305"
}, },
{ {
"_id": "6054b73ffe227d253226a9b7", "_id": "605e55c952816f1290663306",
"field": "USEMIN", "field": "USEMIN",
"text": "Please use maximum", "text": "Please use maximum",
"id": "6054b73ffe227d253226a9b7" "id": "605e55c952816f1290663306"
}, },
{ {
"_id": "6054b73ffe227d253226a9b8", "_id": "605e55c952816f1290663307",
"field": "CHARACTERS", "field": "CHARACTERS",
"text": "characters", "text": "characters",
"id": "6054b73ffe227d253226a9b8" "id": "605e55c952816f1290663307"
}, },
{ {
"_id": "6054b73ffe227d253226a9b9", "_id": "605e55c952816f1290663308",
"field": "ALLOWEDMAX", "field": "ALLOWEDMAX",
"text": "Allowed maximum is", "text": "Allowed maximum is",
"id": "6054b73ffe227d253226a9b9" "id": "605e55c952816f1290663308"
}, },
{ {
"_id": "6054b73ffe227d253226a9ba", "_id": "605e55c952816f1290663309",
"field": "ALLOWEDMIN", "field": "ALLOWEDMIN",
"text": "Allowed miniumum is", "text": "Allowed miniumum is",
"id": "6054b73ffe227d253226a9ba" "id": "605e55c952816f1290663309"
}, },
{ {
"_id": "6054b73ffe227d253226a9bb", "_id": "605e55c952816f129066330a",
"field": "MANDATORYFIELD", "field": "MANDATORYFIELD",
"text": "Mandatory field", "text": "Mandatory field",
"id": "6054b73ffe227d253226a9bb" "id": "605e55c952816f129066330a"
}, },
{ {
"_id": "6054b73ffe227d253226a9bc", "_id": "605e55c952816f129066330b",
"field": "MOVEBOX", "field": "MOVEBOX",
"text": "You need to sort all the boxes", "text": "You need to sort all the boxes",
"id": "6054b73ffe227d253226a9bc" "id": "605e55c952816f129066330b"
}, },
{ {
"_id": "6054b73ffe227d253226a9bd", "_id": "605e55c952816f129066330c",
"field": "ALTERNATIVES_INPUTS", "field": "ALTERNATIVES_INPUTS",
"text": "Please move element according to your preference ; one is the most prefered", "text": "Please move element according to your preference ; one is the most prefered",
"id": "6054b73ffe227d253226a9bd" "id": "605e55c952816f129066330c"
}, },
{ {
"_id": "6054b73ffe227d253226a9be", "_id": "605e55c952816f129066330d",
"field": "RESTART", "field": "RESTART",
"text": "Restart", "text": "Restart",
"id": "6054b73ffe227d253226a9be" "id": "605e55c952816f129066330d"
}, },
{ {
"_id": "6054b73ffe227d253226a9bf", "_id": "605e55c952816f129066330e",
"field": "INTROALT", "field": "INTROALT",
"text": "Introduction to Alternatives", "text": "Introduction to Alternatives",
"id": "6054b73ffe227d253226a9bf" "id": "605e55c952816f129066330e"
}, },
{ {
"_id": "6054b73ffe227d253226a9c0", "_id": "605e55c952816f129066330f",
"field": "ALTERNATIVES", "field": "ALTERNATIVES",
"text": "Alternatives", "text": "Alternatives",
"id": "6054b73ffe227d253226a9c0" "id": "605e55c952816f129066330f"
}, },
{ {
"_id": "6054b73ffe227d253226a9c1", "_id": "605e55c952816f1290663310",
"field": "SORTALT", "field": "SORTALT",
"text": "Sort Alternatives", "text": "Sort Alternatives",
"id": "6054b73ffe227d253226a9c1" "id": "605e55c952816f1290663310"
}, },
{ {
"_id": "6054b73ffe227d253226a9c2", "_id": "605e55c952816f1290663311",
"field": "INTROOBJ", "field": "INTROOBJ",
"text": "Introduction to Objectives", "text": "Introduction to Objectives",
"id": "6054b73ffe227d253226a9c2" "id": "605e55c952816f1290663311"
}, },
{ {
"_id": "6054b73ffe227d253226a9c3", "_id": "605e55c952816f1290663312",
"field": "MATCH", "field": "MATCH",
"text": "Congrats Swing and Tradeoff match. You can continue.", "text": "Congrats Swing and Tradeoff match. You can continue.",
"id": "6054b73ffe227d253226a9c3" "id": "605e55c952816f1290663312"
}, },
{ {
"_id": "6054b73ffe227d253226a9c4", "_id": "605e55c952816f1290663313",
"field": "NOMATCH", "field": "NOMATCH",
"text": "Sorry Swing and Tradeoff does not match. You cannot continue.", "text": "Sorry Swing and Tradeoff does not match. You cannot continue.",
"id": "6054b73ffe227d253226a9c4" "id": "605e55c952816f1290663313"
}, },
{ {
"_id": "6054b73ffe227d253226a9c5", "_id": "605e55c952816f1290663314",
"field": "RSWING", "field": "RSWING",
"text": "I would like to restart Swing", "text": "I would like to restart Swing",
"id": "6054b73ffe227d253226a9c5" "id": "605e55c952816f1290663314"
}, },
{ {
"_id": "6054b73ffe227d253226a9c6", "_id": "605e55c952816f1290663315",
"field": "RTRADEOFF", "field": "RTRADEOFF",
"text": "I would like to restart Tradoff", "text": "I would like to restart Tradoff",
"id": "6054b73ffe227d253226a9c6" "id": "605e55c952816f1290663315"
}, },
{ {
"_id": "6054b73ffe227d253226a9c7", "_id": "605e55c952816f1290663316",
"field": "NEEDVAL", "field": "NEEDVAL",
"text": "You need to choose a value", "text": "You need to choose a value",
"id": "6054b73ffe227d253226a9c7" "id": "605e55c952816f1290663316"
}, },
{ {
"_id": "6054b73ffe227d253226a9c8", "_id": "605e55c952816f1290663317",
"field": "ERRHIGHER", "field": "ERRHIGHER",
"text": "Cannot be higher than a upper element", "text": "Cannot be higher than a upper element",
"id": "6054b73ffe227d253226a9c8" "id": "605e55c952816f1290663317"
}, },
{ {
"_id": "6054b73ffe227d253226a9c9", "_id": "605e55c952816f1290663318",
"field": "ERRLOWER", "field": "ERRLOWER",
"text": "Cannot be lower than a lower element", "text": "Cannot be lower than a lower element",
"id": "6054b73ffe227d253226a9c9" "id": "605e55c952816f1290663318"
}, },
{ {
"_id": "6054b73ffe227d253226a9ca", "_id": "605e55c952816f1290663319",
"field": "READOBJ", "field": "READOBJ",
"text": "Read this objective", "text": "Read this objective",
"id": "6054b73ffe227d253226a9ca" "id": "605e55c952816f1290663319"
}, },
{ {
"_id": "6054b73ffe227d253226a9cb", "_id": "605e55c952816f129066331a",
"field": "READALT", "field": "READALT",
"text": "Read this alternative", "text": "Read this alternative",
"id": "6054b73ffe227d253226a9cb" "id": "605e55c952816f129066331a"
}, },
{ {
"_id": "6054b73ffe227d253226a9cc", "_id": "605e55c952816f129066331b",
"field": "NOMATCHSELECT", "field": "NOMATCHSELECT",
"text": "Please select the method that represents your preference if none of them represents what you would like click \"None\"", "text": "Please select the method that represents your preference if none of them represents what you would like click \"None\"",
"id": "6054b73ffe227d253226a9cc" "id": "605e55c952816f129066331b"
}, },
{ {
"_id": "6054b73ffe227d253226a9cd", "_id": "605e55c952816f129066331c",
"field": "CSWING", "field": "CSWING",
"text": "Continuing with Swing values", "text": "Continuing with Swing values",
"id": "6054b73ffe227d253226a9cd" "id": "605e55c952816f129066331c"
}, },
{ {
"_id": "6054b73ffe227d253226a9ce", "_id": "605e55c952816f129066331d",
"field": "CTRADEOFF", "field": "CTRADEOFF",
"text": "Continuing with TradeOff values", "text": "Continuing with TradeOff values",
"id": "6054b73ffe227d253226a9ce" "id": "605e55c952816f129066331d"
}, },
{ {
"_id": "6054b73ffe227d253226a9cf", "_id": "605e55c952816f129066331e",
"field": "CNONE", "field": "CNONE",
"text": "Either Swing or Tradeoff correspond to my wishes", "text": "Either Swing or Tradeoff correspond to my wishes",
"id": "6054b73ffe227d253226a9cf" "id": "605e55c952816f129066331e"
}, },
{ {
"_id": "6054b73ffe227d253226a9d0", "_id": "605e55c952816f129066331f",
"field": "SWINGTEXT", "field": "SWINGTEXT",
"text": "<div><b>This is a presentation of the swing method :</b></div><div><br></div><div>Move sliders and be happy<br></div>", "text": "<div><b>This is a presentation of the swing method :</b></div><div><br></div><div>Move sliders and be happy<br></div>",
"id": "6054b73ffe227d253226a9d0" "id": "605e55c952816f129066331f"
}, },
{ {
"_id": "6054b73ffe227d253226a9d1", "_id": "605e55c952816f1290663320",
"field": "TRADEOFFTEXT", "field": "TRADEOFFTEXT",
"text": "<div><b>This is a presentation of the Tradeoff method :</b></div><div><br></div><div>Select select<br></div>Move sliders and be happy", "text": "<div><b>This is a presentation of the Tradeoff method :</b></div><div><br></div><div>Select select<br></div>Move sliders and be happy",
"id": "6054b73ffe227d253226a9d1" "id": "605e55c952816f1290663320"
}, },
{