From a1d6b03ec98abbc073b5b73b631da6ea3eae4eb9 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Wed, 27 Mar 2024 15:20:14 +0100 Subject: [node] finished the great typescript rewrite --- nodejs/database/ships.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'nodejs/database/ships.ts') 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 { + const data = getShipsAtStatement.all(symbol) as Array; 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, -- cgit v1.2.3