<commit_before>/**
 * Created by aldo on 5/4/14.
 */
var fortune = require('fortune')
  , express = fortune.express
  , RSVP = fortune.RSVP
  , util = require('util');

var container = express()
  , port = process.argv[2] || 1337;

var app = fortune({
  db: 'fortune-admin',
  adapter: 'mongodb',
  namespace: '/api/v1'
})

.resource("user", {
  title : String,
  firstName : String,
  lastName : String,
  role : String,
  email : String,
  nationality: String,
  languageCode: String,
  addresses: [{ref: "address", inverse: "user"}],
  flights: [{ref: "flight", inverse: "flights", pkType: String}]
}, {
  model: {pk: "email"}
})

.resource("address", {
  type: String,
  addressLine1: String,
  addressLine2: String,
  addressLine3: String,
  addressLine4: String,
  city: String,
  region: String,
  postCode: String,
  country: String,
  dateDeleted: Date,
  user: {ref: "user", inverse: "addresses", pkType: String}
})

.resource("flight", {
  flightNumber: String,
  users: [{ref: "user", inverse: "users", pkType : String}]
}, { model: { pk: "flightNumber" }})

.transform(
//  before
  function () {
    return this;
  },
//  after
  function (request) {
    console.log('Request : ' + util.inspect(request.body));
    if (request.body.addresses) {
      findUser(request.body.addresses[0].user).then(function (user) {
        console.log(user);
        user.addresses.push(this._id);
      });
    }<commit_msg>Fix typo in resources schema<commit_after>/**
 * Created by aldo on 5/4/14.
 */
var fortune = require('fortune')
  , express = fortune.express
  , RSVP = fortune.RSVP
  , util = require('util');

var container = express()
  , port = process.argv[2] || 1337;

var app = fortune({
  db: 'fortune-admin',
  adapter: 'mongodb',
  namespace: '/api/v1'
})

.resource("user", {
  title : String,
  firstName : String,
  lastName : String,
  role : String,
  email : String,
  nationality: String,
  languageCode: String,
  addresses: [{ref: "address", inverse: "user"}],
  flights: [{ref: "flight", inverse: "users", pkType: String}]
}, {
  model: {pk: "email"}
})

.resource("address", {
  type: String,
  addressLine1: String,
  addressLine2: String,
  addressLine3: String,
  addressLine4: String,
  city: String,
  region: String,
  postCode: String,
  country: String,
  dateDeleted: Date,
  user: {ref: "user", inverse: "addresses", pkType: String}
})

.resource("flight", {
  flightNumber: String,
  users: [{ref: "user", inverse: "flights", pkType : String}]
}, { model: { pk: "flightNumber" }})

.transform(
//  before
  function () {
    return this;
  },
//  after
  function (request) {
    console.log('Request : ' + util.inspect(request.body));
    if (request.body.addresses) {
      findUser(request.body.addresses[0].user).then(function (user) {
        console.log(user);
        user.addresses.push(this._id);
      });
    }
{'fraction_non_alphanumeric': 0.17418677859391396, 'fraction_numerical': 0.01049317943336831, 'mean_word_length': 3.532488114104596, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1380703', 'n_tokens_mistral': 1012, 'n_tokens_neox': 996, 'n_words': 238}