codecombat/server/middleware/codelogs.coffee
Josh Callebaut c4652d82e2 Implements the SPADE logger into the SpellView
* Updates spade.js vendor file, adds a sublime-project for developers to use
* Moves server logic away from handlers
* Moves session update logic to middleware, sets up server schema to autorender IDs as ObjectIDs
* Modernizes the supermodel loading scheme and switches from constructor to initalize
2016-04-26 09:56:30 -07:00

22 lines
674 B
CoffeeScript

errors = require '../commons/errors'
wrap = require 'co-express'
database = require '../commons/database'
mongoose = require 'mongoose'
CodeLog = require '../models/CodeLog'
LevelSession = require '../models/LevelSession'
module.exports =
post: wrap (req, res) ->
codeLog = database.initDoc(req, CodeLog)
database.assignBody(req, codeLog)
database.validateDoc(codeLog)
codeLog = yield codeLog.save()
# Update the level session with sessionID to include the new codelog.
yield LevelSession.update(
{_id: mongoose.Types.ObjectId(req.body.sessionID)},
{$push:{codeLogs: codeLog._id}}
)
res.status(201).send(codeLog.toObject())