models/indexModel.js

// RDF stuff
const N3 = require('n3')
const {
  DataFactory
} = N3
const {
  namedNode
} = DataFactory

const BaseModel = require('./baseModel.js')
/**
 * The index model handles processing of for data shown on the root route of the server

 * @extends BaseModel
 */
class IndexModel extends BaseModel {
  constructor (req) {
    super(req)
    this.extendedFolder = ''
    this.fileName = 'data.ttl'
    this.controllers = ['shapes', 'states', 'steps']
  }

  /**
  * gets all of the items from the 'shapes', 'states' and 'steps' models and converts them to jsonLD
  * @override
  * @param {Object} req - Request, currently unused
  * @returns {Object} - Json representation of data
  */
  getAll (req) {
    return new Promise(
      (resolve, reject) => {
        // get current URL
        // let currentURL = req.protocol + "://" + req.get('host') + req.originalUrl;
        const currentURL = this.url
        // list the controllers

        const writer = new N3.Writer({ prefixes: this.prefixes })

        this.controllers.forEach(current => {
          writer.addQuad(
            namedNode(currentURL),
            namedNode('http://www.w3.org/ns/ldp#contains'),
            namedNode(currentURL + '/' + current)
          )
        })

        writer.end((error, result) => {
          if (error) {
            reject(error)
          }
          // Return a JSON-LD representation back to the controller
          resolve(this.fileService.stringToJSONLD(result))
        })
      }
    )
  }
}

module.exports = IndexModel