functional application without amazon update

This commit is contained in:
GotPPay
2017-12-02 22:48:45 +01:00
parent 0e193fa5a8
commit d5120a1ba2
12 changed files with 375 additions and 98 deletions

View File

@@ -1,3 +1,5 @@
import { sendUpdateToAmazon } from './helpers/amazon';
var express = require('express');
var alexa = require('alexa-app');
@@ -12,13 +14,22 @@ var ObjectID = require ('mongodb').ObjectID;
const router = express.Router ();
router.get ('/intents', async (req, res, next) => {
router.get ('/getSkill/:id', async (req, res, next) => {
try {
const id = req.params.id;
db.collection ('intent_list').find({}).toArray((err,result)=>{
if (err) throw err;
res.json(result);
if (id.length !== 24){
res.json([]);
throw("error");
}
db.collection ('skill_list').find({_id: ObjectID(id)}).toArray((err,result)=>{
if (err){
throw err;
res.json([]);
}else{
res.json(result);
}
});
} catch (e) {
@@ -27,10 +38,11 @@ router.get ('/intents', async (req, res, next) => {
}
});
router.get ('/deleteIntent/:id', async (req, res, next) => {
router.get ('/deleteSkill/:skillID', async (req, res, next) => {
try {
let id = req.params.id;
let result = db.collection('intent_list').remove({_id: ObjectID(id)},(err,result)=>{
let result = db.collection('skill_list').remove({_id: ObjectID(id)},(err,result)=>{
if (err) throw err;
res.json(result);
});
@@ -40,15 +52,20 @@ router.get ('/deleteIntent/:id', async (req, res, next) => {
}
});
router.post ('/updateIntent/:id', async (req, res, next) => {
router.post ('/updateSkill/:id', async (req, res, next) => {
try {
let id = req.params.id;
let intent = req.body;
delete intent._id;
let result = db.collection('intent_list').update({_id: ObjectID(id)}, intent,{upsert:true}, (err, result)=>{
if (err) throw(err);
res.json(result);
});
let skill = req.body;
delete skill._id;
if (id !== '-1'){
let result = db.collection('skill_list').update({_id: ObjectID(id)}, skill,{upsert:true}, (err, result)=>{
if (err) throw(err);
res.json(result);
});
}else{
//no new skills for now
}
} catch (e) {
console.log ('error:', e);
next (e);