Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/main/resources/services/postMarkdown/postMarkdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { connect } from '/lib/xp/node'

export const post = (req: XP.Request): XP.Response => {
const setFields = (obj) => {
obj.displayName = req.params.displayName
Copy link
Contributor

@johnnadeluy johnnadeluy Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:
const params = { displayName: req.params.displayName markdown: req.params.markdown }

obj.markdown = req.params.markdown
return obj
}

const conn = connect({
repoId: 'no.ssb.pubmd',
branch: 'master',
principals: ['role:system.admin'],
})

const nodeId = typeof req.params._id === 'string' ? req.params._id : ''
const nodeExists = nodeId ? conn.exists(nodeId) : false

let result
if (nodeExists) {
result = conn.modify({
key: nodeId,
editor: setFields,
})
} else {
const params = setFields({})
result = conn.create(params)
Copy link
Contributor

@johnnadeluy johnnadeluy Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then you can set result = conn.create(params)

}

return {
status: 200,
body: result,
contentType: 'application/json',
}
}
5 changes: 5 additions & 0 deletions src/main/resources/services/postMarkdown/postMarkdown.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<service>
<allow>
<principal>role:system.everyone</principal>
</allow>
</service>
Loading