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


-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){
exports.dropSurvey = async (req, res) => {
try {
await Survey.collection.drop();
// await Survey.collection.drop();
await Survey.syncIndexes();
return res.status(201).json({
message: "Survey drop",
......@@ -463,6 +463,8 @@ exports.getSurveykey = async (req, res) => {
} else if (key === "rational"){
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)
for(let item of survey.alternatives.items){
if(item.enable) {
const mongoose = require('mongoose');
const Token = mongoose.model('Token');
const Survey = mongoose.model('Survey');
exports.registerNewToken = async (req, res) => {
try {
......@@ -136,8 +137,37 @@ exports.loginToken = async (req, res) => {
res.status(400).json({ message: err,status:"Error"});
exports.accessToken = async (req, res) => {
if(await Survey.isAccessToken(req.body.survey_id)){
//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",
comments:"Created with API access token",
token = await;
return res
.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) => {
try {
......@@ -48,7 +48,6 @@ const objschema = new Schema({
short_name: {
type: String,
index: { unique: true, sparse: true }
description: {
type: String,
......@@ -203,6 +202,9 @@ const SurveySchema = new Schema({
required: true,
default: true,
......@@ -220,6 +222,19 @@ const SurveySchema = new Schema({
SurveySchema.statics.checkExistingField = async function(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() {
return "TODO";
......@@ -382,5 +382,37 @@
"createdAt": "2021-03-18T20:07:24.198Z",
"updatedAt": "2021-03-18T20:07:24.198Z",
"id": "6053b2fcfe227d253226a971"
"type": "html",
"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",
"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",
"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 @@
"flag": "gb",
"fields": [
"_id": "6054b73ffe227d253226a9ac",
"_id": "605e55c952816f12906632fb",
"field": "NEXT",
"text": "next",
"id": "6054b73ffe227d253226a9ac"
"id": "605e55c952816f12906632fb"
"_id": "6054b73ffe227d253226a9ad",
"_id": "605e55c952816f12906632fc",
"field": "WELCOME",
"text": "welcome",
"id": "6054b73ffe227d253226a9ad"
"id": "605e55c952816f12906632fc"
"_id": "6054b73ffe227d253226a9ae",
"_id": "605e55c952816f12906632fd",
"field": "ACCEPT",
"text": "accept",
"id": "6054b73ffe227d253226a9ae"
"id": "605e55c952816f12906632fd"
"_id": "6054b73ffe227d253226a9af",
"_id": "605e55c952816f12906632fe",
"field": "REFUSE",
"text": "refuse",
"id": "6054b73ffe227d253226a9af"
"id": "605e55c952816f12906632fe"
"_id": "6054b73ffe227d253226a9b0",
"_id": "605e55c952816f12906632ff",
"field": "PREVIOUS",
"text": "previous",
"id": "6054b73ffe227d253226a9b0"
"id": "605e55c952816f12906632ff"
"_id": "6054b73ffe227d253226a9b1",
"_id": "605e55c952816f1290663300",
"field": "POC",
"text": "Person of Contact",
"id": "6054b73ffe227d253226a9b1"
"id": "605e55c952816f1290663300"
"_id": "6054b73ffe227d253226a9b2",
"_id": "605e55c952816f1290663301",
"field": "AGREEMENT",
"text": "I accept that my data are used ...",
"id": "6054b73ffe227d253226a9b2"
"id": "605e55c952816f1290663301"
"_id": "6054b73ffe227d253226a9b3",
"_id": "605e55c952816f1290663302",
"field": "AGREETITLE",
"text": "Data Use Agreements",
"id": "6054b73ffe227d253226a9b3"
"id": "605e55c952816f1290663302"
"_id": "6054b73ffe227d253226a9b4",
"_id": "605e55c952816f1290663303",
"field": "AGREE",
"text": "agree",
"id": "6054b73ffe227d253226a9b4"
"id": "605e55c952816f1290663303"
"_id": "6054b73ffe227d253226a9b5",
"_id": "605e55c952816f1290663304",
"field": "SELECTONE",
"text": "You need to select one value",
"id": "6054b73ffe227d253226a9b5"
"id": "605e55c952816f1290663304"
"_id": "6054b73ffe227d253226a9b6",
"_id": "605e55c952816f1290663305",
"field": "USEMAX",
"text": "Please use maximum",
"id": "6054b73ffe227d253226a9b6"
"id": "605e55c952816f1290663305"
"_id": "6054b73ffe227d253226a9b7",
"_id": "605e55c952816f1290663306",
"field": "USEMIN",
"text": "Please use maximum",
"id": "6054b73ffe227d253226a9b7"
"id": "605e55c952816f1290663306"
"_id": "6054b73ffe227d253226a9b8",
"_id": "605e55c952816f1290663307",
"field": "CHARACTERS",
"text": "characters",
"id": "6054b73ffe227d253226a9b8"
"id": "605e55c952816f1290663307"
"_id": "6054b73ffe227d253226a9b9",
"_id": "605e55c952816f1290663308",
"field": "ALLOWEDMAX",
"text": "Allowed maximum is",
"id": "6054b73ffe227d253226a9b9"
"id": "605e55c952816f1290663308"
"_id": "6054b73ffe227d253226a9ba",
"_id": "605e55c952816f1290663309",
"field": "ALLOWEDMIN",
"text": "Allowed miniumum is",
"id": "6054b73ffe227d253226a9ba"
"id": "605e55c952816f1290663309"
"_id": "6054b73ffe227d253226a9bb",
"_id": "605e55c952816f129066330a",
"text": "Mandatory field",
"id": "6054b73ffe227d253226a9bb"
"id": "605e55c952816f129066330a"
"_id": "6054b73ffe227d253226a9bc",
"_id": "605e55c952816f129066330b",
"field": "MOVEBOX",
"text": "You need to sort all the boxes",
"id": "6054b73ffe227d253226a9bc"
"id": "605e55c952816f129066330b"
"_id": "6054b73ffe227d253226a9bd",
"_id": "605e55c952816f129066330c",
"text": "Please move element according to your preference ; one is the most prefered",
"id": "6054b73ffe227d253226a9bd"
"id": "605e55c952816f129066330c"
"_id": "6054b73ffe227d253226a9be",
"_id": "605e55c952816f129066330d",
"field": "RESTART",
"text": "Restart",
"id": "6054b73ffe227d253226a9be"
"id": "605e55c952816f129066330d"
"_id": "6054b73ffe227d253226a9bf",
"_id": "605e55c952816f129066330e",
"field": "INTROALT",
"text": "Introduction to Alternatives",
"id": "6054b73ffe227d253226a9bf"
"id": "605e55c952816f129066330e"
"_id": "6054b73ffe227d253226a9c0",
"_id": "605e55c952816f129066330f",
"field": "ALTERNATIVES",
"text": "Alternatives",
"id": "6054b73ffe227d253226a9c0"
"id": "605e55c952816f129066330f"
"_id": "6054b73ffe227d253226a9c1",
"_id": "605e55c952816f1290663310",
"field": "SORTALT",
"text": "Sort Alternatives",
"id": "6054b73ffe227d253226a9c1"
"id": "605e55c952816f1290663310"
"_id": "6054b73ffe227d253226a9c2",
"_id": "605e55c952816f1290663311",
"field": "INTROOBJ",
"text": "Introduction to Objectives",
"id": "6054b73ffe227d253226a9c2"
"id": "605e55c952816f1290663311"
"_id": "6054b73ffe227d253226a9c3",
"_id": "605e55c952816f1290663312",
"field": "MATCH",
"text": "Congrats Swing and Tradeoff match. You can continue.",
"id": "6054b73ffe227d253226a9c3"
"id": "605e55c952816f1290663312"
"_id": "6054b73ffe227d253226a9c4",
"_id": "605e55c952816f1290663313",
"field": "NOMATCH",
"text": "Sorry Swing and Tradeoff does not match. You cannot continue.",
"id": "6054b73ffe227d253226a9c4"
"id": "605e55c952816f1290663313"
"_id": "6054b73ffe227d253226a9c5",
"_id": "605e55c952816f1290663314",
"field": "RSWING",
"text": "I would like to restart Swing",
"id": "6054b73ffe227d253226a9c5"
"id": "605e55c952816f1290663314"
"_id": "6054b73ffe227d253226a9c6",
"_id": "605e55c952816f1290663315",
"field": "RTRADEOFF",
"text": "I would like to restart Tradoff",
"id": "6054b73ffe227d253226a9c6"
"id": "605e55c952816f1290663315"
"_id": "6054b73ffe227d253226a9c7",
"_id": "605e55c952816f1290663316",
"field": "NEEDVAL",
"text": "You need to choose a value",
"id": "6054b73ffe227d253226a9c7"
"id": "605e55c952816f1290663316"
"_id": "6054b73ffe227d253226a9c8",
"_id": "605e55c952816f1290663317",
"field": "ERRHIGHER",
"text": "Cannot be higher than a upper element",
"id": "6054b73ffe227d253226a9c8"
"id": "605e55c952816f1290663317"
"_id": "6054b73ffe227d253226a9c9",
"_id": "605e55c952816f1290663318",
"field": "ERRLOWER",
"text": "Cannot be lower than a lower element",
"id": "6054b73ffe227d253226a9c9"
"id": "605e55c952816f1290663318"
"_id": "6054b73ffe227d253226a9ca",
"_id": "605e55c952816f1290663319",
"field": "READOBJ",
"text": "Read this objective",
"id": "6054b73ffe227d253226a9ca"
"id": "605e55c952816f1290663319"
"_id": "6054b73ffe227d253226a9cb",
"_id": "605e55c952816f129066331a",
"field": "READALT",
"text": "Read this alternative",
"id": "6054b73ffe227d253226a9cb"
"id": "605e55c952816f129066331a"
"_id": "6054b73ffe227d253226a9cc",
"_id": "605e55c952816f129066331b",
"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",
"text": "Continuing with Swing values",
"id": "6054b73ffe227d253226a9cd"
"id": "605e55c952816f129066331c"
"_id": "6054b73ffe227d253226a9ce",
"_id": "605e55c952816f129066331d",
"field": "CTRADEOFF",
"text": "Continuing with TradeOff values",
"id": "6054b73ffe227d253226a9ce"
"id": "605e55c952816f129066331d"
"_id": "6054b73ffe227d253226a9cf",
"_id": "605e55c952816f129066331e",
"field": "CNONE",
"text": "Either Swing or Tradeoff correspond to my wishes",
"id": "6054b73ffe227d253226a9cf"
"id": "605e55c952816f129066331e"
"_id": "6054b73ffe227d253226a9d0",
"_id": "605e55c952816f129066331f",
"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>",
"id": "6054b73ffe227d253226a9d0"
"id": "605e55c952816f129066331f"
"_id": "6054b73ffe227d253226a9d1",
"_id": "605e55c952816f1290663320",
"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",
"id": "6054b73ffe227d253226a9d1"
"id": "605e55c952816f1290663320"
"_id": "6054b73ffe227d253226a9d2",
"_id": "605e55c952816f1290663321",
"field": "OBJCAT",
"text": "Objective Category",
"id": "6054b73ffe227d253226a9d2"
"id": "605e55c952816f1290663321"
"_id": "6054b73ffe227d253226a9d3",
"_id": "605e55c952816f1290663322",
"field": "OBJROOT",
"text": "Objective Root",
"id": "6054b73ffe227d253226a9d3"
"id": "605e55c952816f1290663322"
"_id": "6054b73ffe227d253226a9d4",
"_id": "605e55c952816f1290663323",
"field": "RATCONC",
"text": "Conclusion",
"id": "6054b73ffe227d253226a9d4"
"id": "605e55c952816f1290663323"
"_id": "6054b73ffe227d253226a9d5",
"_id": "605e55c952816f1290663324",
"field": "CLICKITEMSEQ",
"text": "Please click on each items sequentially",
"id": "6054b73ffe227d253226a9d5"
"id": "605e55c952816f1290663324"
"_id": "6054b73ffe227d253226a9d6",
"_id": "605e55c952816f1290663325",
"field": "SORTITEMSEQ",
"text": "Click on each item for sorting, the first element is your preferred",
"id": "6054b73ffe227d253226a9d6"
"id": "605e55c952816f1290663325"
"_id": "6054b73ffe227d253226a9d7",
"_id": "605e55c952816f1290663326",
"field": "SWINGSORT",
"text": "Sort by clicking the option by order of preference, the first element is your preferred",
"id": "6054b73ffe227d253226a9d7"
"id": "605e55c952816f1290663326"
"_id": "6054b73ffe227d253226a9d8",
"_id": "605e55c952816f1290663327",
"text": "Move the slider so ...",
"id": "6054b73ffe227d253226a9d8"
"id": "605e55c952816f1290663327"
"_id": "6054b73ffe227d253226a9d9",
"_id": "605e55c952816f1290663328",
"field": "TRADESEL",
"text": "Select your best option between the two possiblities, if you like them both you can click on equivalent",
"id": "6054b73ffe227d253226a9d9"
"id": "605e55c952816f1290663328"
"_id": "6054b73ffe227d253226a9da",
"_id": "605e55c952816f1290663329",
"text": "Move the slider so you like both option alike",
"id": "6054b73ffe227d253226a9da"
"id": "605e55c952816f1290663329"
"_id": "6054b73ffe227d253226a9db",
"_id": "605e55c952816f129066332a",
"field": "EQUIVALENT",
"text": "EQUIVALENT",
"id": "6054b73ffe227d253226a9db"
"id": "605e55c952816f129066332a"
"_id": "6054b73ffe227d253226a9dc",
"_id": "605e55c952816f129066332b",
"text": "Sorry Swing and Tradeoff does not match, but you can continue or restart one of the method.",
"id": "6054b73ffe227d253226a9dc"
"id": "605e55c952816f129066332b"
"_id": "605e55c952816f129066332c",
"text": "Here are your favorite objectives sorted by order of preference<br>",
"id": "605e55c952816f129066332c"
"_id": "605e55c952816f129066332d",
"text": "It's a match <br>",
"id": "605e55c952816f129066332d"
"_id": "605e55c952816f129066332e",
"text": "Sorry it doesn't match<br>",
"id": "605e55c952816f129066332e"
"_id": "605e55c952816f129066332f",
"field": "REDIRECTURL",
"text": "You will be redirect to (click to the link if it does'nt work.",
"id": "605e55c952816f129066332f"
"updatedAt": "2021-03-19T14:37:51.802Z",
"createdAt": "2021-03-19T14:37:51.802Z",
"updatedAt": "2021-03-26T21:44:41.952Z",
"createdAt": "2021-03-26T21:44:41.952Z",
"status": "TODO",
"id": "6034171c10a7dcbd297bd67d"
......@@ -15,7 +15,7 @@ module.exports = app => {
//Client side"/tokens/login", Builder.loginToken);
//"/tokens/access", Builder.accessToken);"/tokens/access", Builder.accessToken);
app.get("/tokens/me", auth(), Builder.getTokenDetails);
app.put("/token/me/status", auth(), Builder.update_status)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment