From 9d290c16b9a752ff985e94629eabfad99582b751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20de=20Vasconcelos?= Date: Tue, 9 Jan 2024 15:16:23 +0000 Subject: [PATCH] New key for datasets --- .../endpoints/datasets/facilities.encm.endpoint.js | 4 ++-- sync/tasks/syncEncmStatus.js | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/server/endpoints/datasets/facilities.encm.endpoint.js b/server/endpoints/datasets/facilities.encm.endpoint.js index 14f0d8b7..4a6a5f2e 100644 --- a/server/endpoints/datasets/facilities.encm.endpoint.js +++ b/server/endpoints/datasets/facilities.encm.endpoint.js @@ -5,7 +5,7 @@ const SERVERDB = require('../../services/SERVERDB'); /* * */ module.exports.all = async (request, reply) => { - const allItems = await SERVERDB.client.get('encm:all'); + const allItems = await SERVERDB.client.get('datasets/facilities/encm/all'); return reply .code(200) .header('Content-Type', 'application/json; charset=utf-8') @@ -13,7 +13,7 @@ module.exports.all = async (request, reply) => { }; module.exports.single = async (request, reply) => { - const singleItem = await SERVERDB.client.get(`encm:${request.params.id}`); + const singleItem = await SERVERDB.client.get(`datasets/facilities/encm/${request.params.id}`); return reply .code(200) .header('Content-Type', 'application/json; charset=utf-8') diff --git a/sync/tasks/syncEncmStatus.js b/sync/tasks/syncEncmStatus.js index bd7e1bdd..b5172ca0 100644 --- a/sync/tasks/syncEncmStatus.js +++ b/sync/tasks/syncEncmStatus.js @@ -32,7 +32,7 @@ module.exports = async () => { console.log(`→ Updating ENCM status...`); const startTime = process.hrtime(); // Retrieve ENCM from database - const foundManyDocuments_raw = await SERVERDB.client.get('encm:all'); + const foundManyDocuments_raw = await SERVERDB.client.get('datasets/facilities/encm/all'); const foundManyDocuments = JSON.parse(foundManyDocuments_raw); // Query IXAPI for the status of the requested ENCM const allEncmTicketsWaiting = await IXAPI.request({ reportType: 'ticket', status: 'W', initialDate: getIxDateString(-7200), finalDate: getIxDateString() }); @@ -63,7 +63,7 @@ module.exports = async () => { }; // Update the current document with the new values allEncmData.push(updatedDocument); - await SERVERDB.client.set(`encm:${updatedDocument.id}`, JSON.stringify(updatedDocument)); + await SERVERDB.client.set(`datasets/facilities/encm/${updatedDocument.id}`, JSON.stringify(updatedDocument)); // Log progress console.log(`→ id: ${foundDocument.id} | currently_waiting: ${updatedDocument.currently_waiting} | expected_wait_time: ${updatedDocument.expected_wait_time} | active_counters: ${updatedDocument.active_counters} | is_open: ${updatedDocument.is_open} | name: ${foundDocument.name}`); // @@ -71,7 +71,7 @@ module.exports = async () => { // Save all documents const collator = new Intl.Collator('en', { numeric: true, sensitivity: 'base' }); allEncmData.sort((a, b) => collator.compare(a.id, b.id)); - await SERVERDB.client.set('encm:all', JSON.stringify(allEncmData)); + await SERVERDB.client.set('datasets/facilities/encm/all', JSON.stringify(allEncmData)); // Switch the flag OFF TASK_IS_RUNNING = false; // Log elapsed time in the current operation @@ -86,11 +86,10 @@ module.exports = async () => { // }; -// -// -// +/* * */ function getIxDateString(adjustmentSeconds = 0) { + // Create a new date object const dateObj = new Date(); // Apply the adjustment to the current date dateObj.setSeconds(dateObj.getSeconds() + adjustmentSeconds); @@ -105,4 +104,5 @@ function getIxDateString(adjustmentSeconds = 0) { const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; // Return result return formattedDate; + // }