Commit a3e3ecb0 by Иван Кубота

trash storage

parent 679e51d3
......@@ -63,6 +63,7 @@ updated_at
created_at
*/
var getTrash;
var fs = require('fs');
const util = require('util');
const readFile = util.promisify(fs.readFile);
......@@ -386,5 +387,49 @@ module.exports = {
return questions;
}
}
},
'/api/user/data/:userID': {
options: {
userID: {required: false, description: 'id of user', type: Number},
},
method: 'POST',
summary: 'Assign user any data storage',
fn: async function (args) {
var trash = await getTrash(args);
trash = Object.assign(trash, args.body);
// sub my completed attempt
var str = JSON.stringify(trash);
await asyncPool(`
INSERT INTO trash (user_id, json)
VALUES(?, ?)
ON DUPLICATE KEY UPDATE json = ?;`, [args.userID, str, str]);
return trash;
}
},
'/api/user/data/get/:userID': {
options: {
userID: {required: false, description: 'id of user', type: Number},
},
method: 'GET',
summary: 'Get user data storage',
fn: getTrash = async function (args) {
var out = {};
var data = await asyncPool(`select * from trash where user_id=?;`, [args.userID]);
if(data && data[0]){
var json = data[0].json;
if(json){
try{
out = JSON.parse(json);
if(typeof out!== 'object')
out = {};
}catch (e) {
}
}
}
return out;
}
},
};
\ No newline at end of file
Markdown is supported
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