Skip to content

Commit

Permalink
add deleted_at filter in map_object request
Browse files Browse the repository at this point in the history
  • Loading branch information
cviolbarbosa committed Nov 7, 2024
1 parent 6af5664 commit a8a12a8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
const databaseServices = require('../../services/database/database_services.js');
const {inMemDB } = require('../../services/in_mem_database/mem_database_service.js');
const rabbitMQServices = require('../../services/message_broker/rabbitMQ_services.js');
const DB_BUFFER_TIME = parseInt(process.env.DB_BUFFER_TIME || 1000);


async function queryDataBase(uuid, objMsg, msgProps) {
console.log(objMsg, msgProps);
inMemDB.agents_stats[uuid]['updtPerSecond'].countMessage();

let replyTo = msgProps.replyTo? msgProps.replyTo : uuid;
Expand Down Expand Up @@ -53,7 +53,9 @@ async function queryDataBase(uuid, objMsg, msgProps) {
break;

case 'allMapObjects':
response = await databaseServices.map_objects.select(objMsg.body['conditions'] || {});
let conditions = objMsg.body['conditions'] || {deleted_at: null};
conditions = {deleted_at: null, ...conditions};
response = await databaseServices.map_objects.select(conditions);
break;
}

Expand All @@ -65,9 +67,20 @@ async function queryDataBase(uuid, objMsg, msgProps) {
console.log(r);
const newObjects = await databaseServices.map_objects.list_in(newIds);
newObjects.forEach( obj => { inMemDB.update('map_objects', 'id', obj, new Date(), 'realtime'); });
return newIds;
});
break;


case 'updateMapObjects':
const patches = objMsg.body['data'];
patches.forEach( patch => {
inMemDB.update('map_objects', 'id', patch, new Date());
});
response = "data saved";
break;


case 'deleteMapObjects':
response = await databaseServices.map_objects.delete(objMsg.body['condition'])
.then( (r) => {
Expand Down
20 changes: 14 additions & 6 deletions helyos_server/src/services/database/postg_access_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,19 @@ const parseConditions = (tableName, conditions) => {
return this.list();
}


let fromTableStatements = [];

const notNullConditions = {};
Object.keys(conditions).forEach((key, idx) => {
if (conditions[key] === null) {
null_conditions.push(` AND ${key} IS NULL `);
} else {
notNullConditions[key]=conditions[key];
}
});


Object.keys(notNullConditions).forEach((key, idx) => {

if (key.includes('.')) {
const [table, field] = key.split('.');
Expand All @@ -38,9 +48,7 @@ const parseConditions = (tableName, conditions) => {
} else {
in_conditions.push(`AND ${key.slice(0, -4)} IN ('${conditions[key].join("','")}') `);
}
} else if (conditions[key] === null) {
null_conditions.push(`AND ${key} IS NULL `);
} else {
} else {
names.push(key);
values.push(conditions[key]);
masks.push('$' + (idx + 1));
Expand Down Expand Up @@ -487,7 +495,7 @@ class AgentDataLayer extends DatabaseLayer {

aggregatedFollowerConnections(agent) {
return this.client.query(`
SELECT A.id, A.uuid, A.geometry, B.connection_geometry FROM public.agents as A
SELECT A.id, A.uuid, A.geometry, A.yard_id, B.connection_geometry FROM public.agents as A
JOIN public.agents_interconnections as B
ON A.id = B.follower_id
WHERE A.id IN (SELECT follower_id FROM public.agents_interconnections WHERE leader_id = $1)
Expand All @@ -497,7 +505,7 @@ class AgentDataLayer extends DatabaseLayer {

aggregatedLeaderConnections(agent) {
return this.client.query(`
SELECT A.id, A.uuid, A.geometry, B.connection_geometry FROM public.agents as A
SELECT A.id, A.uuid, A.geometry, A.yard_id, B.connection_geometry FROM public.agents as A
JOIN public.agents_interconnections as B
ON A.id = B.leader_id
WHERE A.id IN (SELECT leader_id FROM public.agents_interconnections WHERE follower_id = $1)
Expand Down

0 comments on commit a8a12a8

Please sign in to comment.