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

v0.8

- Client : Add option to get answer for auth token
- Add access in token model
parent 4ee89757
......@@ -16,6 +16,7 @@ exports.registerNewToken = async (req, res) => {
survey_id: req.body.survey_id,
enable: req.body.enable,
status:"new",
access:false,
comments:req.body.comments,
test:req.body.test,
});
......@@ -146,10 +147,11 @@ exports.accessToken = async (req, res) => {
const newtoken = new Token({
token: req.body.token,
survey_id: req.body.survey_id,
enable: "true",
enable: true,
access:true,
status:"new",
comments:"Created with API access token",
test:"false",
test:false,
});
token = await newtoken.save();
}
......@@ -206,7 +208,7 @@ exports.update_status = async (req, res) => {
exports.update_answers = async (req, res) => {
try {
const token = await Token.findById(req.userData.id );
const token = await Token.findById(req.userData.id);
if(token.status==="finished"){
return res
.status(201)
......@@ -229,3 +231,12 @@ exports.update_answers = async (req, res) => {
res.status(400).json({ message: err,status:"Error"});
}
};
exports.get_answers = async (req, res) => {
try {
const token = await Token.findById(req.userData.id);
res.status(201).json({answers:token.answers,message:"",status: "OK"});
} catch (err) {
res.status(400).json({ message: err,status:"Error"});
}
};
......@@ -27,6 +27,11 @@ const TokenSchema = new Schema({
required: false,
default:false
},
access: {
type: Boolean,
required: true,
default:false
},
status: {
type: String,
enum:['new','connected','finished'],
......@@ -47,6 +52,7 @@ TokenSchema.methods.generateAuthToken= async function(extrafields) {
token: user.token,
survey_id: user.survey_id,
status: user.status,
access:user.access,
admin: false,
test:user.test,
answers:user.answers,
......
......@@ -17,8 +17,10 @@ module.exports = app => {
app.post("/tokens/login", Builder.loginToken);
app.post("/tokens/access", Builder.accessToken);
app.get("/tokens/me", auth(), Builder.getTokenDetails);
app.get("/token/me", auth(), Builder.getTokenDetails);
app.put("/token/me/status", auth(), Builder.update_status)
app.put("/token/me/answers", auth(), Builder.update_answers)
app.get("/token/me/answers", auth(), Builder.get_answers)
};
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