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
```
This commit is contained in:
D. Berge
2025-07-12 16:41:29 +02:00
parent a7e02c526b
commit 6b216f7406

View File

@@ -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
};