示例#1
0
    post: function(sid, callback) {
      var validated = Thread.validate(this.body);
      
      if (validated.valid === false) {
        return callback({
          error: 'Error validating thread body',
          missing: validated.missing,
          fields: validated.error,
          body: this.body
        });
      }

      validated.body.created = Date.now();
      validated.body.message_count = 0;

      storage.createThread(sid, validated.body, function(err, tid) {
        if (err) { return callback(err); }

        callback(null, { statusCode: 201, id: tid });
      });
    }
示例#2
0
    post: function(callback) {
      var validated = Section.validate(this.body);
      
      if (validated.valid === false) {
        return callback({
          error: 'Error validating section body',
          missing: validated.missing,
          fields: validated.error,
          body: this.body
        });
      }

      validated.body.created = Date.now();
      validated.body.thread_count = 0;

      storage.createSection(validated.body, function(err, sid) {
        if (err) { return callback(err); }
        
        callback(null, { statusCode: 201, id: sid });
      });
    }
示例#3
0
    post: function(sid, tid, callback) {
      var validated = Message.validate(this.body);

      if (validated.valid === false) {
        return callback({
          error: 'Error validating message body',
          missing: validated.missing,
          fields: validated.error,
          body: this.body
        });
      }

      if (validated.body.username !=  this.token.username) {
        return callback({ statusCode: 401 });
      }

      validated.body.created = Date.now();

      storage.createMessage(sid, tid, validated.body, function(err, mid) {
        if (err) { return callback(err); }

        callback(null, { statusCode: 201, id: mid });
      });
    }