From f42a39d231bb688e60c22d477622370fd04452a8 Mon Sep 17 00:00:00 2001 From: Surya Paolo Date: Thu, 5 Jan 2023 01:37:20 +0100 Subject: [PATCH] pagina Attivita + Video e PDF Presentazione --- src/server/models/site.js | 2 ++ src/server/router/index_router.js | 41 +++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/server/models/site.js b/src/server/models/site.js index 2f4d839..887ebce 100755 --- a/src/server/models/site.js +++ b/src/server/models/site.js @@ -132,6 +132,8 @@ const SiteSchema = new Schema({ type: Number, default: 0, }, + videoPromo: { type: String }, + PDFPromo: { type: String }, }, confsite: { options: { // ConfSite diff --git a/src/server/router/index_router.js b/src/server/router/index_router.js index c2be703..c89a2c6 100755 --- a/src/server/router/index_router.js +++ b/src/server/router/index_router.js @@ -668,12 +668,49 @@ router.post('/getpage', async (req, res) => { const idapp = req.body.idapp; const mypath = params.path; - return await MyPage.findOne({ idapp, path: mypath }).then((ris) => { - return res.send({ mypage: ris }); + let found = await MyPage.findOne({ idapp, path: mypath }).then((ris) => { + if (ris) + return res.send({ mypage: ris }); + else + return null; }).catch((e) => { console.log(e.message); res.status(400).send(e); }); + if (!found) { + // trova quelli con il : + let regexp = new RegExp(`:`, 'ig') + const searchpagesSpec = await MyPage.find({ idapp, path: { $regex: regexp } }); + + if (searchpagesSpec) { + let arrsubpath = mypath.split('/'); + for (let i = 0; i < searchpagesSpec.length; i++) { + let arrsubstr = searchpagesSpec[i].path.split('/'); + + if (arrsubpath.length === arrsubpath.length) { + + let mypathbuild = ''; + + for (let j = 0; j < arrsubstr.length; j++) { + if (arrsubstr[j].includes(':')) { + mypathbuild += arrsubpath[j] + '/'; + } else { + mypathbuild += arrsubstr[j] + '/'; + } + } + + if (mypath + '/' === mypathbuild) { + return res.send({ mypage: searchpagesSpec[i] }); + } + } + } + } + + return await MyPage.findOne({ idapp, path: mypath }).then((ris) => { + return res.send({ mypage: ris }); + }); + } + return found; });