diff --git a/package.json b/package.json index 4399c64..0eb1e79 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "@types/node": "^16.18.59", "@types/react": "^18.2.31", "@types/react-dom": "^18.2.14", - "node-promises": "^0.2.1", "react": "^18.2.0", "react-dom": "^18.2.0", "typescript": "^5.2.2", diff --git a/public/api/index.php b/public/api/index.php index 2032833..52e1f97 100644 --- a/public/api/index.php +++ b/public/api/index.php @@ -28,4 +28,5 @@ if ($match == null) { exit(1); } +header('Content-type: application/json'); call_user_func_array($match['target'], $match['params']); \ No newline at end of file diff --git a/sql/setup-tables.sql b/sql/setup-tables.sql index 949e902..068c2e1 100644 --- a/sql/setup-tables.sql +++ b/sql/setup-tables.sql @@ -8,5 +8,5 @@ CREATE TABLE FormEntries(name varchar, description varchar); CREATE TABLE TacticInfo( id integer PRIMARY KEY AUTOINCREMENT, name varchar, - creation_date timestamp + creation_date timestamp DEFAULT CURRENT_TIMESTAMP ); \ No newline at end of file diff --git a/src/Connexion.php b/src/Connexion.php index ef9c909..cefb8fd 100644 --- a/src/Connexion.php +++ b/src/Connexion.php @@ -15,6 +15,10 @@ class Connexion { $this->pdo = $pdo; } + public function lastInsertId() { + return $this->pdo->lastInsertId(); + } + /** * execute a request * @param string $query diff --git a/src/Data/TacticInfo.php b/src/Data/TacticInfo.php index c8db912..901280d 100644 --- a/src/Data/TacticInfo.php +++ b/src/Data/TacticInfo.php @@ -26,7 +26,7 @@ class TacticInfo implements \JsonSerializable { return $this->name; } - public function getCreationDate(): int { + public function getCreationTimestamp(): int { return $this->creation_date; } diff --git a/src/Gateway/TacticInfoGateway.php b/src/Gateway/TacticInfoGateway.php index 1f95d55..20d2957 100644 --- a/src/Gateway/TacticInfoGateway.php +++ b/src/Gateway/TacticInfoGateway.php @@ -33,10 +33,13 @@ class TacticInfoGateway { public function insert(string $name): TacticInfo { $this->con->exec( - "INSERT INTO TacticInfo(name, creation_date) VALUES(:name, CURRENT_TIMESTAMP)", + "INSERT INTO TacticInfo(name) VALUES(:name)", [":name" => [$name, PDO::PARAM_STR]] ); - $row = $this->con->fetch("SELECT id, creation_date FROM TacticInfo ORDER BY id DESC LIMIT 1", [])[0]; + $row = $this->con->fetch( + "SELECT id, creation_date FROM TacticInfo WHERE :id = id", + [':id' => [$this->con->lastInsertId(), PDO::PARAM_INT]] + )[0]; return new TacticInfo(intval($row["id"]), $name, strtotime($row["creation_date"])); } diff --git a/src/Model/TacticModel.php b/src/Model/TacticModel.php index bc5af53..7f31572 100644 --- a/src/Model/TacticModel.php +++ b/src/Model/TacticModel.php @@ -27,7 +27,7 @@ class TacticModel { if ($failure) { return null; } - return $this->tactics->insert($name); + $this->tactics->insert($name); } public function makeNewDefault(): ?TacticInfo { diff --git a/tsconfig.json b/tsconfig.json index bd8a98e..9da1fb5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,7 @@ "dom.iterable", "esnext" ], + "types": ["vite/client"], "allowJs": true, "skipLibCheck": true, "esModuleInterop": true,