Adminfunktion eingeführt
This commit is contained in:
parent
6fa98c8d6c
commit
ebc97b5470
20
app.js
20
app.js
|
@ -17,6 +17,7 @@ const dbhog = require('./dbhog')
|
||||||
|
|
||||||
const PORT = process.env.PORT || 4000;
|
const PORT = process.env.PORT || 4000;
|
||||||
|
|
||||||
|
|
||||||
var indexRouter = require('./routes/index');
|
var indexRouter = require('./routes/index');
|
||||||
var usersRouter = require('./routes/users');
|
var usersRouter = require('./routes/users');
|
||||||
var valuelistRouter = require('./routes/valuelist');
|
var valuelistRouter = require('./routes/valuelist');
|
||||||
|
@ -39,19 +40,6 @@ var corsOptions = {
|
||||||
methods: ['GET', 'PUT', 'POST', 'DELETE', 'COPY']
|
methods: ['GET', 'PUT', 'POST', 'DELETE', 'COPY']
|
||||||
}
|
}
|
||||||
app.use(cors(corsOptions));
|
app.use(cors(corsOptions));
|
||||||
|
|
||||||
// Setting up passport
|
|
||||||
|
|
||||||
/*passport.use(
|
|
||||||
new LocalStrategy(
|
|
||||||
function(username, password, done) {
|
|
||||||
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
|
|
||||||
app.use(logger('dev'));
|
app.use(logger('dev'));
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(express.urlencoded({ extended: false }));
|
app.use(express.urlencoded({ extended: false }));
|
||||||
|
@ -66,16 +54,17 @@ app.use(express.static(path.join(__dirname, 'public')));
|
||||||
app.use('/', (req, res, next ) => {
|
app.use('/', (req, res, next ) => {
|
||||||
req.db = db;
|
req.db = db;
|
||||||
next();
|
next();
|
||||||
})
|
});
|
||||||
|
|
||||||
app.use('/api/v1', (req, res, next ) => {
|
app.use('/api/v1', (req, res, next ) => {
|
||||||
req.db = dbhog;
|
req.db = dbhog;
|
||||||
next();
|
next();
|
||||||
})
|
});
|
||||||
|
|
||||||
app.use('/', indexRouter);
|
app.use('/', indexRouter);
|
||||||
app.use('/users', usersRouter);
|
app.use('/users', usersRouter);
|
||||||
app.use('/wl', valuelistRouter);
|
app.use('/wl', valuelistRouter);
|
||||||
|
app.use('/vl', valuelistRouter);
|
||||||
app.use('/recepies', recepieRouter);
|
app.use('/recepies', recepieRouter);
|
||||||
|
|
||||||
app.use('/api/v1/person', personRouter);
|
app.use('/api/v1/person', personRouter);
|
||||||
|
@ -85,6 +74,7 @@ app.use('/api/v1/punkte', punkteRouter);
|
||||||
app.use('/api/v1/haus', hausRouter);
|
app.use('/api/v1/haus', hausRouter);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// catch 404 and forward to error handler
|
// catch 404 and forward to error handler
|
||||||
app.use(function(req, res, next) {
|
app.use(function(req, res, next) {
|
||||||
next(createError(404));
|
next(createError(404));
|
||||||
|
|
62
db/index.js
62
db/index.js
|
@ -32,32 +32,38 @@ const dataStructure = {
|
||||||
|
|
||||||
categories: {
|
categories: {
|
||||||
tableName: "kategorie",
|
tableName: "kategorie",
|
||||||
jsonName: "categories"
|
jsonName: "categories",
|
||||||
|
displayName: "Kategorien"
|
||||||
},
|
},
|
||||||
|
|
||||||
units: {
|
units: {
|
||||||
tableName: "einheit",
|
tableName: "einheit",
|
||||||
jsonName: "units"
|
jsonName: "units",
|
||||||
|
displayName: "Einheiten"
|
||||||
},
|
},
|
||||||
|
|
||||||
tools: {
|
tools: {
|
||||||
tableName: "geraet",
|
tableName: "geraet",
|
||||||
jsonName: "tools"
|
jsonName: "tools",
|
||||||
|
displayName: "Geräte und Sonstiges"
|
||||||
},
|
},
|
||||||
|
|
||||||
difficulties: {
|
difficulties: {
|
||||||
tableName: "schwierigkeit",
|
tableName: "schwierigkeit",
|
||||||
jsonName: "difficulties"
|
jsonName: "difficulties",
|
||||||
|
displayName: "Schwierigkeit"
|
||||||
},
|
},
|
||||||
|
|
||||||
ingredients: {
|
ingredients: {
|
||||||
tableName: "zutat",
|
tableName: "zutat",
|
||||||
jsonName: "ingredients"
|
jsonName: "ingredients",
|
||||||
|
displayName: "Zutaten"
|
||||||
},
|
},
|
||||||
|
|
||||||
ratingcategories: {
|
ratingcategories: {
|
||||||
tableName: "wertungkategorie",
|
tableName: "wertungkategorie",
|
||||||
jsonName: "ratingcategories"
|
jsonName: "ratingcategories",
|
||||||
|
displayName: "Wertungskategorien"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -99,7 +105,14 @@ const updateNameKeyObject = function(req, res, next) {
|
||||||
if(DEBUG) console.log("Update Valuelist");
|
if(DEBUG) console.log("Update Valuelist");
|
||||||
let structure = getStructure(req);
|
let structure = getStructure(req);
|
||||||
if(DEBUG) console.log(req.body[structure.jsonName]);
|
if(DEBUG) console.log(req.body[structure.jsonName]);
|
||||||
let obj = req.body[structure.jsonName][0];
|
let obj = req.body['item'];
|
||||||
|
if(req.body[structure.jsonName]) {
|
||||||
|
obj = req.body[structure.jsonName][0];
|
||||||
|
}
|
||||||
|
if(!obj.beschreibung) {
|
||||||
|
obj.beschreibung = "";
|
||||||
|
}
|
||||||
|
|
||||||
let query = "UPDATE "+structure.tableName+
|
let query = "UPDATE "+structure.tableName+
|
||||||
" set schluessel = '"+obj.schluessel+
|
" set schluessel = '"+obj.schluessel+
|
||||||
"', name = '"+obj.name+
|
"', name = '"+obj.name+
|
||||||
|
@ -148,6 +161,15 @@ const getStructure = function(req) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getDataStructure = function(req, res, next) {
|
||||||
|
let structure = dataStructure;
|
||||||
|
res.status(200).json(structure);
|
||||||
|
return structure;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const getAllFromTable = function(req, res, next) {
|
const getAllFromTable = function(req, res, next) {
|
||||||
|
|
||||||
let structure = getStructure(req);
|
let structure = getStructure(req);
|
||||||
|
@ -168,6 +190,28 @@ const getAllFromTable = function(req, res, next) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const getItemFromTable = function(req, res, next) {
|
||||||
|
|
||||||
|
let structure = getStructure(req);
|
||||||
|
if(DEBUG) {
|
||||||
|
console.log("Found Structure-Object for WL-Item: ");
|
||||||
|
console.log(structure);
|
||||||
|
console.log(structure['tableName']);
|
||||||
|
}
|
||||||
|
if(structure === undefined) return res.status(404).send();
|
||||||
|
pool.query(selectItemFromTable(structure['tableName'], req.itemId), (err, rs) => {
|
||||||
|
if(err) next(err)
|
||||||
|
else {
|
||||||
|
if(DEBUG) console.log(res);
|
||||||
|
let result = {};
|
||||||
|
result = rs.rows[0];
|
||||||
|
console.log(result);
|
||||||
|
res.status(200).json(result);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const getUserByEmail = function(username) {
|
const getUserByEmail = function(username) {
|
||||||
let query = "Select id, name, email, kennwort, beschreibung FROM nutzer WHERE email ilike '"+username+"'";
|
let query = "Select id, name, email, kennwort, beschreibung FROM nutzer WHERE email ilike '"+username+"'";
|
||||||
if(DEBUG) console.log(query);
|
if(DEBUG) console.log(query);
|
||||||
|
@ -189,6 +233,8 @@ module.exports = {
|
||||||
insertNameKeyObject,
|
insertNameKeyObject,
|
||||||
deleteNameKeyObject,
|
deleteNameKeyObject,
|
||||||
getAllFromTable,
|
getAllFromTable,
|
||||||
|
getItemFromTable,
|
||||||
getUserByEmail,
|
getUserByEmail,
|
||||||
getStructure
|
getStructure,
|
||||||
|
getDataStructure
|
||||||
};
|
};
|
||||||
|
|
|
@ -72,7 +72,7 @@ router.get('/', function(req, res, next) {
|
||||||
"%' OR rezept.beschreibung ilike '%"+req.query.term+"%' "+
|
"%' OR rezept.beschreibung ilike '%"+req.query.term+"%' "+
|
||||||
" OR rezept.id in (select rezept from rezept_zutat where zutat in (select id from zutat where name ilike '%"+req.query.term+"%'))";
|
" OR rezept.id in (select rezept from rezept_zutat where zutat in (select id from zutat where name ilike '%"+req.query.term+"%'))";
|
||||||
if(req.query.hashtag) query += " AND rezept.schluessel ilike '"+req.query.hashtag+"' "
|
if(req.query.hashtag) query += " AND rezept.schluessel ilike '"+req.query.hashtag+"' "
|
||||||
if(req.query.cat) query += " AND kategorie.id ="+req.query.cat+" "
|
if(req.query.cat) query += " AND kategorie.id IN ("+req.query.cat+")"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,9 @@ updateNameKeyObject,
|
||||||
insertNameKeyObject,
|
insertNameKeyObject,
|
||||||
deleteNameKeyObject,
|
deleteNameKeyObject,
|
||||||
getAllFromTable,
|
getAllFromTable,
|
||||||
getStructure} = require('./../db/');
|
getItemFromTable,
|
||||||
|
getStructure,
|
||||||
|
getDataStructure} = require('./../db/');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,11 +30,25 @@ router.param('path', function(req, res, next, id) {
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/* OPTIONS */
|
||||||
|
|
||||||
|
router.get('/options', function(req, res, next) {
|
||||||
|
getDataStructure(req, res, next);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* GET users listing. */
|
/* GET users listing. */
|
||||||
router.get('/:path', function(req, res, next) {
|
router.get('/:path', function(req, res, next) {
|
||||||
getAllFromTable(req, res, next)
|
getAllFromTable(req, res, next)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get('/:path/:id', function(req, res, next) {
|
||||||
|
if (DEBUG) console.log("Get Item from WL");
|
||||||
|
getItemFromTable(req, res, next)
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
router.put('/:path/:id', function(req, res, next) {
|
router.put('/:path/:id', function(req, res, next) {
|
||||||
if (DEBUG) console.log("Update WL");
|
if (DEBUG) console.log("Update WL");
|
||||||
updateNameKeyObject(req, res, next)
|
updateNameKeyObject(req, res, next)
|
||||||
|
|
Loading…
Reference in New Issue