|
1 | 1 | const fjp = require("fast-json-patch") |
2 | | -const samplePathRe = /\/samples\/([^/]+)(.*)/ |
| 2 | +const samplePathRe = "\\/(sample|samples)\\/([^/]+)(.*)" |
3 | 3 | const applyRemoveSample = require("./apply-remove-sample") |
4 | 4 | const getSampleIndexAndId = require("./get-sample-index-and-id") |
5 | 5 |
|
6 | 6 | module.exports = async ({ db, patch, sessionId, workingSummaryObject }) => { |
7 | 7 | // Get relevant sample existing data |
8 | 8 | const m = patch.path.match(samplePathRe) |
9 | | - if (!m[1]) throw new Error(`Invalid sample patch to path "${patch.path}"`) |
| 9 | + if (!m[2]) throw new Error(`Invalid sample patch to path "${patch.path}"`) |
10 | 10 |
|
11 | | - let { sampleIndex, sampleId } = getSampleIndexAndId(sessionId, m[1]) |
12 | | - let sampleChangePath = m[2] |
| 11 | + let { sampleIndex, sampleId } = getSampleIndexAndId(sessionId, m[2]) |
| 12 | + let sampleChangePath = m[3] |
13 | 13 |
|
14 | 14 | if (patch.op === "replace" && !sampleChangePath) { |
15 | 15 | sampleChangePath = "" |
@@ -42,9 +42,10 @@ module.exports = async ({ db, patch, sessionId, workingSummaryObject }) => { |
42 | 42 | // Update sample in database with new content and new version |
43 | 43 |
|
44 | 44 | db.prepare( |
45 | | - "UPDATE sample_state SET sample_version=?, content=? WHERE session_short_id=? AND sample_ref_id=?" |
| 45 | + "UPDATE sample_state SET sample_version=?, sample_ref_id=?, content=? WHERE session_short_id=? AND sample_ref_id=?" |
46 | 46 | ).run( |
47 | 47 | sample.sample_version + 1, |
| 48 | + newSampleContent._id, |
48 | 49 | JSON.stringify(newSampleContent), |
49 | 50 | sessionId, |
50 | 51 | sampleId |
|
0 commit comments