EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
Commands.js
Go to the documentation of this file.
1const db = require("../db");
2
3module.exports = {
4 queueCommand,
5 fetchPendingCommands,
6 completeCommand
7};
8
9/**
10 *
11 * @param agentId
12 * @param type
13 * @param data
14 */
15async function queueCommand(agentId, type, data) {
16 const result = await db.query(
17 `INSERT INTO remote_commands (agent_id, type, data, status)
18 VALUES ($1,$2,$3,'queued')
19 RETURNING cmd_id`,
20 [agentId, type, data]
21 );
22 return result.rows[0].cmd_id;
23}
24
25/**
26 *
27 * @param agentId
28 */
29async function fetchPendingCommands(agentId) {
30 const result = await db.query(
31 `SELECT * FROM remote_commands
32 WHERE agent_id = $1 AND status = 'queued'`,
33 [agentId]
34 );
35 return result.rows;
36}
37
38/**
39 *
40 * @param cmdId
41 * @param result
42 * @param success
43 */
44async function completeCommand(cmdId, result, success) {
45 await db.query(
46 `UPDATE remote_commands SET status='success', result=$2 WHERE cmd_id=$1`,
47 [cmdId, result]
48 );
49}