*** WOP ***
Liste bearbeiten geht noch nicht
This commit is contained in:
@@ -2,6 +2,8 @@ import { MongoAPIError, ObjectId } from 'mongodb';
|
||||
import bcrypt from 'bcrypt';
|
||||
import { getCollections, update_pflux } from '../db/mongo.js';
|
||||
|
||||
|
||||
|
||||
export function registerApiRoutes(app, requireLogin) {
|
||||
const { usersCollection, prop_fluxCollection } = getCollections();
|
||||
|
||||
@@ -61,7 +63,7 @@ export function registerApiRoutes(app, requireLogin) {
|
||||
const { id } = req.query;
|
||||
if (id) {
|
||||
try {
|
||||
const item = await prop_fluxCollection.findOne({ _id: new ObjectId(id) });
|
||||
const item = await prop_fluxCollection.findOne({ _id: parseInt(id) });
|
||||
if (item) return res.json([item]);
|
||||
return res.json([]);
|
||||
} catch (err) {
|
||||
@@ -69,8 +71,15 @@ export function registerApiRoutes(app, requireLogin) {
|
||||
return res.status(500).json({ error: 'Fehler beim Laden' });
|
||||
}
|
||||
}
|
||||
|
||||
let gesamtZahl = 0
|
||||
try {
|
||||
gesamtZahl = await prop_fluxCollection.countDocuments({chip: {$exists: true}})
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
const page = parseInt(req.query.page) || 1;
|
||||
const limit = parseInt(req.query.limit) || 10;
|
||||
const limit = parseInt(req.query.limit) || 50;
|
||||
const skip = (page - 1) * limit;
|
||||
try {
|
||||
const items = await prop_fluxCollection.find({chip: {$exists: true}})
|
||||
@@ -78,7 +87,8 @@ export function registerApiRoutes(app, requireLogin) {
|
||||
.skip(skip)
|
||||
.limit(limit)
|
||||
.toArray();
|
||||
res.json(items);
|
||||
const data = {items: items, anzahl: gesamtZahl}
|
||||
res.json(data);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
res.status(500).json({ error: 'Fehler beim Laden' });
|
||||
|
||||
Reference in New Issue
Block a user