pre updating version control
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const express = require("express");
|
||||
const crypto = require("crypto");
|
||||
const db = require("../db/polygons");
|
||||
const { applyEntityBatchChanges } = require("../lib/entityBatch");
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -95,16 +96,15 @@ router.post("/", (req, res) => {
|
||||
try {
|
||||
db.prepare(`
|
||||
INSERT INTO entities (
|
||||
id, name, slug, description, type_id, kind, status, is_deleted, created_at, updated_at
|
||||
id, name, slug, description, type_id, status, is_deleted, created_at, updated_at
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, 0, ?, ?)
|
||||
VALUES (?, ?, ?, ?, ?, ?, 0, ?, ?)
|
||||
`).run(
|
||||
id,
|
||||
name,
|
||||
slug,
|
||||
description,
|
||||
typeId,
|
||||
null,
|
||||
status,
|
||||
now,
|
||||
now
|
||||
@@ -173,7 +173,6 @@ router.put("/:id", (req, res) => {
|
||||
slug = ?,
|
||||
description = ?,
|
||||
type_id = ?,
|
||||
kind = ?,
|
||||
status = ?,
|
||||
updated_at = ?
|
||||
WHERE id = ?
|
||||
@@ -182,7 +181,6 @@ router.put("/:id", (req, res) => {
|
||||
slug,
|
||||
description,
|
||||
typeId,
|
||||
null,
|
||||
status,
|
||||
now,
|
||||
req.params.id
|
||||
@@ -277,6 +275,33 @@ router.delete("/:id", (req, res) => {
|
||||
res.json({ success: true });
|
||||
});
|
||||
|
||||
router.post("/batch", (req, res) => {
|
||||
const { changes } = req.body || {};
|
||||
if (!Array.isArray(changes)) {
|
||||
return res.status(400).json({ error: "changes must be an array" });
|
||||
}
|
||||
|
||||
const now = new Date().toISOString();
|
||||
try {
|
||||
const tx = db.transaction((items) => applyEntityBatchChanges(items, { now }));
|
||||
const result = tx(changes);
|
||||
res.json({
|
||||
success: true,
|
||||
applied: result.applied,
|
||||
created_entity_ids: result.createdEntityIds,
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.status) {
|
||||
return res.status(err.status).json({ error: err.message });
|
||||
}
|
||||
if (isSqliteConstraint(err)) {
|
||||
return res.status(409).json({ error: "Entity name/slug must be unique" });
|
||||
}
|
||||
console.error("Batch entity apply failed", err);
|
||||
res.status(500).json({ error: "Batch entity apply failed" });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
function normalizeEntityRow(row) {
|
||||
|
||||
Reference in New Issue
Block a user