<commit_before>Error = require '../error/Error'
User = require '../model/User'

module.exports = class Controller

  constructor: (@request, @dao) ->

  getId: ->
    throw Error.notImplemented('NodeWrapper.wrap()')

  create: (_) ->
    @checkUserLoggedIn('Controller.create()')
    @dao.create(@request.body, @request.user.KN_ID, _)

  show: (_) ->
    @dao.read(@getId(), _)

  update: (_) ->
    # Make sure the KN_ID in request body is the same as the ID in URL parameter
    data = @request.body
    data.KN_ID = @getId()
    @dao.update(@getId(), data, _)

  destroy: (_) ->
    @dao.delete(@getId(), _)

  checkUserLoggedIn: (methodName) ->
    if not @request.user?
      throw Error.unauthorizedOperation(methodName, 'User should be logged in')

  getLoggedUserId: ->
    @checkUserLoggedIn("getLoggedUserId")
    @request.user.KN_ID

  getLoggedUser: (_) ->
    User.wrap(@request.user)

  getLoggedUserIdIfExists: ->
    if @request.user?
      return @request.user.KN_ID
    else
      return null


<commit_msg>bug fix for front page not loading<commit_after>Error = require '../error/Error'
User = require '../model/User'

module.exports = class Controller

  constructor: (@request, @dao) ->

  getId: ->
    throw Error.notImplemented('NodeWrapper.wrap()')

  create: (_) ->
    @checkUserLoggedIn('Controller.create()')
    @dao.create(@request.body, @request.user.KN_ID, _)

  show: (_) ->
    @dao.read(@getId(), _)

  update: (_) ->
    # Make sure the KN_ID in request body is the same as the ID in URL parameter
    data = @request.body
    data.KN_ID = @getId()
    @dao.update(@getId(), data, _)

  destroy: (_) ->
    @dao.delete(@getId(), _)

  checkUserLoggedIn: (methodName) ->
    if not @request.user?
      throw Error.unauthorizedOperation(methodName, 'User should be logged in')

  getLoggedUserId: ->
    @checkUserLoggedIn("getLoggedUserId")
    @request.user.KN_ID

  getLoggedUser: (_) ->
    User.wrap(@request.user)

  getLoggedUserIdIfExists: ->
    if @request.user?
      return @request.user.KN_ID
    else
      return "no user"



{'fraction_non_alphanumeric': 0.15028901734104047, 'fraction_numerical': 0.0, 'mean_word_length': 3.137450199203187, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5370753', 'n_tokens_mistral': 712, 'n_tokens_neox': 704, 'n_words': 149}