From 6b216f740654e118771757d14e75ed21a97423bd Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Sat, 12 Jul 2025 16:41:29 +0200 Subject: [PATCH] Add library function to retrieve vessel information. In the `keystore` table, we now store information for our own vessel (usually, where the Dougal server is installed). This is an access function to retrieve that information. The info stored for the vessel looks like this: ```yaml type: vessel key: ego data: imo: 9631890 mmsi: 257419000 name: Havila Charisma contacts: - name: HC OM phone: tel:+47123456789 email: hc.om@magseisfairfield.com organisations: Havila Charisma: read: true write: true edit: true ``` --- lib/www/server/lib/db/vessel/index.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lib/www/server/lib/db/vessel/index.js diff --git a/lib/www/server/lib/db/vessel/index.js b/lib/www/server/lib/db/vessel/index.js new file mode 100644 index 0000000..75d2f07 --- /dev/null +++ b/lib/www/server/lib/db/vessel/index.js @@ -0,0 +1,23 @@ +const { pool } = require('../connection'); + +/** Retrieve vessel info. + * + * @a vesselID The ID of the target vessel. Defaults to `ego` + * which is this server's parent vessel. + */ +async function info (vesselID = "ego") { + + const text = ` + SELECT * + FROM keystore + WHERE type = 'vessel' AND key = $1; + `; + + const res = await pool.query(text, [ vesselID ]); + return res.rows[0]?.data ?? {}; + +} + +module.exports = { + info +};