Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions routes/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ const router = express.Router()
import controller from '../db-controller.js'
import auth from '../auth/index.js'

/**
* POST /v1/api/create - Create new object
* Requires JWT authentication
*
* @param {object} req.body - JSON object to create
* @param {string} [req.body.@context] - JSON-LD context (optional)
* @param {object} req.user - Authenticated user from JWT token
* @returns {object} Created object with @id and __rerum metadata
*/
router.route('/')
.post(auth.checkJwt, controller.create)
.all((req, res, next) => {
Expand Down
9 changes: 9 additions & 0 deletions routes/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ const router = express.Router()
import controller from '../db-controller.js'
import auth from '../auth/index.js'

/**
* DELETE /v1/api/delete or DELETE /v1/api/delete/:_id - Delete an object
* Requires JWT authentication
*
* @param {string} [req.params._id] - Optional object ID from URL
* @param {object} req.body - Object containing delete instructions
* @param {object} req.user - Authenticated user from JWT token
* @returns {object} Deleted object metadata or status information
*/
router.route('/')
.delete(auth.checkJwt, controller.deleteObj)
.all((req, res, next) => {
Expand Down
8 changes: 8 additions & 0 deletions routes/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ const router = express.Router()
//This controller will handle all MongoDB interactions.
import controller from '../db-controller.js'

/**
* GET /v1/id/:_id - Retrieve object by ID or slug
* HEAD /v1/id/:_id - Retrieve metadata headers for an object
* Public endpoint, no authentication required
*
* @param {string} req.params._id - Object ID or slug
* @returns {object} Retrieved object or deleted object metadata
*/
router.route('/:_id')
.get(controller.id)
.head(controller.idHeadRequest)
Expand Down
8 changes: 8 additions & 0 deletions routes/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ const router = express.Router()
//This controller will handle all MongoDB interactions.
import controller from '../db-controller.js'

/**
* POST /v1/api/query - Query objects by matching properties
* HEAD /v1/api/query - Query head request for matching objects
* Public endpoint, no authentication required
*
* @param {object} req.body - Query object with properties to match
* @returns {object[]} Array of matching objects
*/
router.route('/')
.post(controller.query)
.head(controller.queryHeadRequest)
Expand Down
8 changes: 8 additions & 0 deletions routes/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ const router = express.Router()
import controller from '../db-controller.js'
import auth from '../auth/index.js'

/**
* PATCH /v1/api/release/:_id - Release an object to make it immutable
* Requires JWT authentication
*
* @param {string} req.params._id - Object ID or slug to release
* @param {object} req.user - Authenticated user from JWT token
* @returns {object} Released object metadata with updated __rerum state
*/
router.route('/:_id')
.patch(auth.checkJwt, controller.release)
.all((req, res, next) => {
Expand Down
16 changes: 16 additions & 0 deletions routes/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import express from 'express'
const router = express.Router()
import controller from '../db-controller.js'

/**
* POST /v1/api/search - Full-text search by words
* Public endpoint, no authentication required
*
* @param {object} req.body - Search query payload
* @param {string} req.body.query - Search terms to match
* @returns {object[]} Array of matching objects
*/
router.route('/')
.post(controller.searchAsWords)
.all((req, res, next) => {
Expand All @@ -10,6 +18,14 @@ router.route('/')
next(res)
})

/**
* POST /v1/api/search/phrase - Full-text search by phrase
* Public endpoint, no authentication required
*
* @param {object} req.body - Search query payload
* @param {string} req.body.query - Exact phrase to match
* @returns {object[]} Array of matching objects
*/
router.route('/phrase')
.post(controller.searchAsPhrase)
.all((req, res, next) => {
Expand Down
Loading