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