mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 11:37:08 +00:00
Let patch regenerate line name.
If the user sends a patch to a line with a `name` which is exactly `null` or the empty string `""`, the server will regenerate the name based on the defaults script.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const { setSurvey, transaction } = require('../connection');
|
||||
const { getLineName } = require('./lib');
|
||||
|
||||
async function patch (projectId, sequence, payload, opts = {}) {
|
||||
const client = await setSurvey(projectId);
|
||||
@@ -25,6 +26,15 @@ async function patch (projectId, sequence, payload, opts = {}) {
|
||||
|
||||
await client.query(text, values);
|
||||
|
||||
// Magic – if the name is (strictly) null or empty, we generate a new one
|
||||
if (p.name === null || p.name === "") {
|
||||
const text = "SELECT * FROM planned_lines WHERE sequence = $1;";
|
||||
const res = await client.query(text, [p.sequence||sequence]);
|
||||
const row = res.rows[0];
|
||||
const name = await getLineName(client, projectId, row);
|
||||
await client.query("UPDATE planned_lines SET name = $2 WHERE sequence = $1", [p.sequence||sequence, name]);
|
||||
}
|
||||
|
||||
transaction.commit(client);
|
||||
} catch (err) {
|
||||
transaction.rollback(client);
|
||||
|
||||
Reference in New Issue
Block a user