From 8819cf9c67e33c76cbac65a9ca2b6ff86786d251 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sat, 30 Mar 2024 14:22:59 +0100 Subject: [node] fixed contracting and implemented renegotiation --- nodejs/database/ships.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'nodejs/database/ships.ts') diff --git a/nodejs/database/ships.ts b/nodejs/database/ships.ts index f918099..5ea2ffa 100644 --- a/nodejs/database/ships.ts +++ b/nodejs/database/ships.ts @@ -23,14 +23,11 @@ export function getShipsAt(symbol: string): Array { export function setShip(data: Ship): void { - if (getShip(data.symbol) === null) { - addShipStatement.run(JSON.stringify(data)); - } else { - updateShipStatement.run({ - data: JSON.stringify(data), - symbol: data.symbol, - }); - } + const changes = updateShipStatement.run({ + data: JSON.stringify(data), + symbol: data.symbol, + }).changes; + if (changes === 0) addShipStatement.run(JSON.stringify(data)); } export function setShipCargo(symbol: string, cargo: Cargo): void { -- cgit v1.2.3