Skip to content

Commit

Permalink
New key for datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
joao-vasconcelos committed Jan 9, 2024
1 parent 971dacd commit 9d290c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions server/endpoints/datasets/facilities.encm.endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ 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')
.send(allItems || []);
};

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')
Expand Down
12 changes: 6 additions & 6 deletions sync/tasks/syncEncmStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() });
Expand Down Expand Up @@ -63,15 +63,15 @@ 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}`);
//
}
// 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
Expand All @@ -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);
Expand All @@ -105,4 +104,5 @@ function getIxDateString(adjustmentSeconds = 0) {
const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
// Return result
return formattedDate;
//
}

0 comments on commit 9d290c1

Please sign in to comment.