Atlantis-Software / offshore

An adapter-based ORM for Node.js with support for mysql, mongo, postgres, redis, and more
MIT License
38 stars 15 forks source link

Model validation to ip cause invalid attribute #12

Closed maxoux closed 8 years ago

maxoux commented 8 years ago

Hi ! Express can return (with req.ip) ::ffff:127.0.0.1 (or other ipv4 address translated), but it's appear to be invalid with Offshore. ex:

///

module BannedModule {

var time_banned = 3600;

class Class {

  attributes: Object;

  constructor(attr: Object) {
      this.attributes = attr;
  }

  beforeCreate(values, cb: Function) {
      var expires = (new Date().getTime()) + (time_banned * 1000);
      values.expires = new Date(expires);
  }

}

export var model= new Class({

  ip: {
      ip: true,
      required: true,
      unique: true
  },
  reason: {
      type: "string"
  },
  expires: {
      type: "datetime"
  }

});

}

module.exports = BannedModule.model;

Banned.create({ip: req.ip, reason: "weird guy"}).then(console.log).catch(console.log)

ps : sorry for bad style markdown and poor english

atiertant commented 8 years ago

Hi, Express is a framework, offshore is an orm... you should integrate offshore in Express to do what you need...