2014-06-30 22:16:26 -04:00
|
|
|
LevelComponent = require './LevelComponent'
|
|
|
|
Handler = require '../../commons/Handler'
|
2014-11-01 17:15:57 -04:00
|
|
|
mongoose = require 'mongoose'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
LevelComponentHandler = class LevelComponentHandler extends Handler
|
|
|
|
modelClass: LevelComponent
|
2014-04-12 13:51:02 -04:00
|
|
|
jsonSchema: require '../../../app/schemas/models/level_component'
|
2014-01-03 13:32:13 -05:00
|
|
|
editableProperties: [
|
|
|
|
'system'
|
|
|
|
'description'
|
|
|
|
'code'
|
|
|
|
'js'
|
2014-06-09 06:26:47 -04:00
|
|
|
'codeLanguage'
|
2014-01-03 13:32:13 -05:00
|
|
|
'dependencies'
|
|
|
|
'propertyDocumentation'
|
|
|
|
'configSchema'
|
2014-02-05 14:03:32 -05:00
|
|
|
'name'
|
2014-10-27 20:11:48 -04:00
|
|
|
'i18nCoverage'
|
2014-01-03 13:32:13 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
getEditableProperties: (req, document) ->
|
|
|
|
props = super(req, document)
|
|
|
|
props.push('official') if req.user?.isAdmin()
|
|
|
|
props
|
|
|
|
|
2015-03-01 23:59:50 -05:00
|
|
|
hasAccessToDocument: (req, document, method) ->
|
|
|
|
if req.user?.isArtisan() then true else super req, document, method
|
|
|
|
|
2014-11-01 17:15:57 -04:00
|
|
|
get: (req, res) ->
|
|
|
|
if req.query.view is 'prop-doc-lookup'
|
|
|
|
projection = {}
|
|
|
|
if req.query.project
|
|
|
|
projection[field] = 1 for field in req.query.project.split(',')
|
|
|
|
|
|
|
|
query = slug: {$exists: true}
|
|
|
|
|
|
|
|
try
|
|
|
|
components = req.query.componentOriginals.split(',')
|
|
|
|
components = (mongoose.Types.ObjectId(c) for c in components)
|
|
|
|
properties = req.query.propertyNames.split(',')
|
|
|
|
catch e
|
|
|
|
return @sendBadInputError(res, 'Could not parse componentOriginals or propertyNames.')
|
2014-11-12 14:01:52 -05:00
|
|
|
|
2014-11-01 17:15:57 -04:00
|
|
|
query['original'] = {$in: components}
|
2014-11-12 14:01:52 -05:00
|
|
|
query.$or = [
|
|
|
|
{'propertyDocumentation.name': {$in: properties}}
|
|
|
|
{'propertyDocumentation.name': {$regex: /^cast.+/}}
|
|
|
|
]
|
2014-11-01 17:15:57 -04:00
|
|
|
|
|
|
|
q = LevelComponent.find(query, projection)
|
|
|
|
q.exec (err, documents) =>
|
|
|
|
return @sendDatabaseError(res, err) if err
|
|
|
|
documents = (@formatEntity(req, doc) for doc in documents)
|
|
|
|
@sendSuccess(res, documents)
|
|
|
|
else
|
|
|
|
super(arguments...)
|
|
|
|
|
2014-06-09 06:26:47 -04:00
|
|
|
module.exports = new LevelComponentHandler()
|