diff options
author | Julien Dessaux | 2024-03-27 15:20:14 +0100 |
---|---|---|
committer | Julien Dessaux | 2024-03-27 15:21:37 +0100 |
commit | a1d6b03ec98abbc073b5b73b631da6ea3eae4eb9 (patch) | |
tree | 1566c60bf1155e62821d9561ba1cc998b04b8ea5 /nodejs/database/ships.ts | |
parent | [all] fixed erroneous contracts index (diff) | |
download | spacetraders-a1d6b03ec98abbc073b5b73b631da6ea3eae4eb9.tar.gz spacetraders-a1d6b03ec98abbc073b5b73b631da6ea3eae4eb9.tar.bz2 spacetraders-a1d6b03ec98abbc073b5b73b631da6ea3eae4eb9.zip |
[node] finished the great typescript rewrite
Diffstat (limited to '')
-rw-r--r-- | nodejs/database/ships.ts | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/nodejs/database/ships.ts b/nodejs/database/ships.ts index 58c8abf..414a059 100644 --- a/nodejs/database/ships.ts +++ b/nodejs/database/ships.ts @@ -1,4 +1,4 @@ -import db from './db.ts'; +import { DbData, db } from './db.ts'; import { Cargo } from '../model/cargo.ts'; import { Fuel, Nav, Ship } from '../model/ship.ts'; @@ -11,18 +11,18 @@ const setShipNavStatement = db.prepare(`UPDATE ships SET data = (SELECT json_set const updateShipStatement = db.prepare(`UPDATE ships SET data = json(:data) WHERE data->>'symbol' = :symbol;`); export function getShip(symbol: string): Ship|null { - const data = getShipStatement.get(symbol) as {data: string}|undefined; + const data = getShipStatement.get(symbol) as DbData|undefined; if (!data) return null; return JSON.parse(data.data); } -export function getShipsAt(symbol: string) { - const data = getShipsAtStatement.all(symbol) as Array<{data: string}>; +export function getShipsAt(symbol: string): Array<Ship> { + const data = getShipsAtStatement.all(symbol) as Array<DbData>; return data.map(elt => JSON.parse(elt.data)); } -export function setShip(data: Ship) { +export function setShip(data: Ship): void { if (getShip(data.symbol) === null) { addShipStatement.run(JSON.stringify(data)); } else { @@ -33,21 +33,21 @@ export function setShip(data: Ship) { } } -export function setShipCargo(symbol: string, cargo: Cargo) { +export function setShipCargo(symbol: string, cargo: Cargo): void { setShipCargoStatement.run({ cargo: JSON.stringify(cargo), symbol: symbol, }); } -export function setShipFuel(symbol: string, fuel: Fuel) { +export function setShipFuel(symbol: string, fuel: Fuel): void { setShipFuelStatement.run({ fuel: JSON.stringify(fuel), symbol: symbol, }); } -export function setShipNav(symbol: string, nav: Nav) { +export function setShipNav(symbol: string, nav: Nav): void { setShipNavStatement.run({ nav: JSON.stringify(nav), symbol: symbol, |