Skip to content

Commit b348e07

Browse files
authored
Merge pull request #3176 from statisticsnorway/MIM-2232-post-markdown-service
[MIM-2232] Created service to add markdown content in a node in repo no.ssb.pubmd
2 parents 6bb3f3c + 64b1ea6 commit b348e07

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { connect } from '/lib/xp/node'
2+
3+
export const post = (req: XP.Request): XP.Response => {
4+
const params = {
5+
displayName: req.params.displayName,
6+
markdown: req.params.markdown,
7+
}
8+
9+
const conn = connect({
10+
repoId: 'no.ssb.pubmd',
11+
branch: 'master',
12+
principals: ['role:system.admin'],
13+
})
14+
15+
const nodeId = typeof req.params._id === 'string' ? req.params._id : ''
16+
const nodeExists = nodeId ? conn.exists(nodeId) : false
17+
18+
let result
19+
if (nodeExists) {
20+
result = conn.modify({
21+
key: nodeId,
22+
editor: (node) => ({
23+
...node,
24+
...params,
25+
}),
26+
})
27+
} else {
28+
result = conn.create(params)
29+
}
30+
31+
return {
32+
status: 200,
33+
body: result,
34+
contentType: 'application/json',
35+
}
36+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<service>
2+
<allow>
3+
<principal>role:system.everyone</principal>
4+
</allow>
5+
</service>

0 commit comments

Comments
 (0)