Commit b868a717 authored by antoine masson's avatar antoine masson
Browse files

v0.4

- Correct model bug for empty id in Survey
- Add possibility to drop survey database
- Get token related to one survey_id
- Get test token of survey_id
parent 8c96c6d7
......@@ -23,6 +23,20 @@ async function json2mango(datajson,mongo){
await mongo.create(datajson);
}
exports.dropSurvey = async (req, res) => {
try {
await Survey.collection.drop();
await Survey.syncIndexes();
return res.status(201).json({
message: "Survey drop",
status: "OK"
});
} catch (err) {
res.status(400).json({ message: err,status:"Error"});
}
}
exports.initSurveyTemplate = async()=>{
if(await LanguageTrans.countDocuments() === 0){
fs.readFile(API.template_dir+'LanguageTrans.json', 'utf-8', async (err, data) => {
......
......@@ -52,6 +52,28 @@ exports.list_all_tokens = async (req, res) => { //TODO : add number of attached
}
};
exports.list_survey_tokens = async (req,res)=>{
try {
Token.find({survey_id:req.params.survey_id,test:false},).
exec(async function (err, tokens) {
await res.status(201).json({tokens:tokens,message:"",status:"OK"});
});
} catch (err) {
res.status(400).json({ message: err,status:"Error"});
}
};
exports.test_survey_token = async (req,res)=>{
try {
console.log(req.params.survey_id)
Token.findOne({survey_id:req.params.survey_id,test:true},).
exec(async function (err, tokens) {
await res.status(201).json({tokens:tokens,message:"",status:"OK"});
});
} catch (err) {
res.status(400).json({ message: err,status:"Error"});
}
};
exports.get_a_token = async (req, res) => {
try {
const token = await Token.findOne({ _id: req.params.id });
......
......@@ -3,6 +3,54 @@ const mongoose = require("mongoose");
const { Schema } = mongoose;
const validator = require( "validator");
const textinputs = new Schema(
{
language:String,
html:{
content:String,
inputs:String,
},
}
);
const text = new Schema(
{
language:String,
html:{
content:String,
},
}
);
const altschema = new Schema(
{
_id:mongoose.ObjectId,
short_name: {
type: String,
index: { unique: true, sparse: true }
},
description: {
type: String,
},
comments: {
type: String,
},
enable: {
type: Boolean,
default: true
},
contents:[textinputs],
items:[{
picture: String,
contents:[text],
}],
}
)
const POCSchema = new Schema({
firstname: {
type: String,
......@@ -40,11 +88,11 @@ SurveyGlobalOptSSchema.statics.checkExistingField = async function(field, value)
module.exports = mongoose.model("SurveyGlobalOptions", SurveyGlobalOptSSchema);
const PrePostSurveySchema = new Schema({
_id:String,
_id:mongoose.ObjectId,
short_name: {
type: String,
required: true,
unique:true,
index: { unique: true, sparse: true }
},
description: {
type: String,
......@@ -72,16 +120,8 @@ const PrePostSurveySchema = new Schema({
required: true
},
type_attribut:Object,
contents:
[
{
language:String,
html:{
content:String,
inputs:String,
},
}
]
contents: [textinputs],
}
)
......@@ -120,8 +160,7 @@ const SurveySchema = new Schema({
}
},
welcome:
[
{
[{
language:String,
html:{
content:String
......@@ -129,18 +168,19 @@ const SurveySchema = new Schema({
movie:{
url:String
}
}
],
presurvey:[PrePostSurveySchema],
postsurvey:[PrePostSurveySchema],
swing:{
type: Object
},
tradeoff:{
type: Object
}],
presurvey:[PrePostSurveySchema],
postsurvey:[PrePostSurveySchema],
rational:{
general: {
learnloop:Boolean
},
alternatives:[altschema],
objectives:Array,
},
},{ timestamps: true });
SurveySchema.statics.checkExistingField = async function(field, value) {
......
......@@ -2,6 +2,7 @@ const Builder = require("../controllers/SurveyController");
const auth = require("../middleware/auth");
module.exports = app => {
app.get("/surveys/drop", auth(true), Builder.dropSurvey);
app.get("/surveys/all", auth(true), Builder.list_all_surveys);
app.post("/surveys/create", auth(true), Builder.createNewSurvey);
......
......@@ -6,6 +6,9 @@ module.exports = app => {
app.get("/tokens/all", auth(true), Builder.list_all_tokens);
app.post("/tokens/register", auth(true), Builder.registerNewToken);
app.get("/tokens/survey/:survey_id", auth(true), Builder.list_survey_tokens);
app.get("/tokens/survey/:survey_id/test", auth(true), Builder.test_survey_token);
app.get("/tokens/token/:id", auth(true), Builder.get_a_token);
app.delete("/tokens/token/:id", auth(true), Builder.delete_a_token);
app.put("/tokens/token/:id", auth(true), Builder.update_a_token);
......
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