- ottimizzato il caricamento del sito
- ottimizzato il caricamento del catalogo.
This commit is contained in:
49
src/server/router/catalogs_router.js
Executable file
49
src/server/router/catalogs_router.js
Executable file
@@ -0,0 +1,49 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
var server_constants = require('../tools/server_constants');
|
||||
|
||||
var { Project } = require('../models/project');
|
||||
|
||||
const { User } = require('../models/user');
|
||||
|
||||
var { authenticate, auth_default } = require('../middleware/authenticate');
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
const { Catalog } = require('../models/catalog');
|
||||
|
||||
//GET /catalogs
|
||||
router.post('/', auth_default, async function (req, res, next) {
|
||||
const idapp = req.body.idapp;
|
||||
const userId = req.body.userId;
|
||||
|
||||
let ismanager = await tools.isManagerByReq(req);
|
||||
|
||||
let catalogs = await Catalog.findAllIdApp(idapp, '', undefined, ismanager);
|
||||
let orders = null;
|
||||
|
||||
if (catalogs) return res.send({ code: server_constants.RIS_CODE_OK, catalogs, orders });
|
||||
else return res.status(400).send({ code: server_constants.RIS_CODE_OK, catalogs, orders });
|
||||
});
|
||||
|
||||
router.get('/id/:id', async function (req, res) {
|
||||
const id = req.params.id;
|
||||
|
||||
try {
|
||||
var catalog = await Catalog.getCatalogById(id);
|
||||
|
||||
if (catalog) {
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, catalog: catalog });
|
||||
} else {
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, catalog: null });
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error fetching catalog by ID:', e);
|
||||
return res.status(400).send({ code: server_constants.RIS_CODE_ERR, msg: e.message });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user