mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 11:57:08 +00:00
Add preplot line patching endpoint.
Allows us to change remarks, meta and ntba fields in preplot lines.
This commit is contained in:
@@ -91,11 +91,11 @@ app.map({
|
||||
'/project/:project/line/': {
|
||||
get: [ mw.line.list ],
|
||||
},
|
||||
// '/project/:project/line/:line': {
|
||||
'/project/:project/line/:line': {
|
||||
// get: [ mw.line.get ],
|
||||
// patch: [ mw.line.patch ],
|
||||
// },
|
||||
//
|
||||
patch: [ mw.line.patch ],
|
||||
},
|
||||
|
||||
'/project/:project/sequence/': {
|
||||
get: [ mw.sequence.list ],
|
||||
},
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
module.exports = {
|
||||
list: require('./list'),
|
||||
// get: require('./get')
|
||||
get: require('./get'),
|
||||
patch: require('./patch')
|
||||
};
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
const { line } = require('../../../lib/db');
|
||||
|
||||
module.exports = async function (req, res, next) {
|
||||
|
||||
try {
|
||||
const payload = req.body;
|
||||
|
||||
await line.patch(req.params.project, req.params.line, payload);
|
||||
res.status(201).send();
|
||||
next();
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
0
lib/www/server/lib/db/line/delete.js
Normal file
0
lib/www/server/lib/db/line/delete.js
Normal file
0
lib/www/server/lib/db/line/get.js
Normal file
0
lib/www/server/lib/db/line/get.js
Normal file
9
lib/www/server/lib/db/line/index.js
Normal file
9
lib/www/server/lib/db/line/index.js
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
module.exports = {
|
||||
list: require('./list'),
|
||||
get: require('./get'),
|
||||
post: require('./post'),
|
||||
put: require('./put'),
|
||||
patch: require('./patch'),
|
||||
delete: require('./delete')
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
const { setSurvey } = require('./connection');
|
||||
const { setSurvey } = require('../connection');
|
||||
|
||||
async function list (projectId, opts = {}) {
|
||||
const client = await setSurvey(projectId);
|
||||
@@ -42,6 +42,4 @@ async function list (projectId, opts = {}) {
|
||||
return res.rows;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
list
|
||||
};
|
||||
module.exports = list;
|
||||
33
lib/www/server/lib/db/line/patch.js
Normal file
33
lib/www/server/lib/db/line/patch.js
Normal file
@@ -0,0 +1,33 @@
|
||||
const { setSurvey, transaction } = require('../connection');
|
||||
|
||||
async function patch (projectId, line, payload, opts = {}) {
|
||||
const client = await setSurvey(projectId);
|
||||
|
||||
const patchables = {
|
||||
"remarks": "UPDATE preplot_lines SET remarks = $2 WHERE line = $1;",
|
||||
"meta": "UPDATE preplot_lines SET meta = $2 WHERE line = $1;",
|
||||
"ntba": "UPDATE preplot_lines SET ntba = $2 WHERE line = $1;",
|
||||
};
|
||||
|
||||
try {
|
||||
transaction.begin(client);
|
||||
for (const key in payload) {
|
||||
const text = patchables[key];
|
||||
const values = [ line, payload[key] ];
|
||||
|
||||
if (!text) {
|
||||
throw {status: 400, message: "Invalid patch" };
|
||||
}
|
||||
|
||||
await client.query(text, values);
|
||||
}
|
||||
transaction.commit(client);
|
||||
} catch (err) {
|
||||
transaction.rollback(err);
|
||||
throw err;
|
||||
} finally {
|
||||
client.release();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = patch;
|
||||
0
lib/www/server/lib/db/line/post.js
Normal file
0
lib/www/server/lib/db/line/post.js
Normal file
0
lib/www/server/lib/db/line/put.js
Normal file
0
lib/www/server/lib/db/line/put.js
Normal file
Reference in New Issue
Block a user