From 69f5faffe43b2f1e03429a721b565c60bd16b317 Mon Sep 17 00:00:00 2001 From: Edin Dazdarevic Date: Thu, 19 Mar 2015 14:27:04 +0100 Subject: [PATCH] added children to users --- .../migrate/20150319104317_create_children.rb | 10 ++++++++ front-api/db/schema.rb | 23 ++++++++++++++++++- front-api/models/child.rb | 3 +++ front-api/models/user.rb | 4 ++++ front-ui/app/components/account/register.js | 19 ++++++++++++--- 5 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 front-api/db/migrate/20150319104317_create_children.rb create mode 100644 front-api/models/child.rb diff --git a/front-api/db/migrate/20150319104317_create_children.rb b/front-api/db/migrate/20150319104317_create_children.rb new file mode 100644 index 0000000..5c23449 --- /dev/null +++ b/front-api/db/migrate/20150319104317_create_children.rb @@ -0,0 +1,10 @@ +class CreateChildren < ActiveRecord::Migration + def change + create_table :children do |t| + t.string :name + t.integer :gender + t.date :date_of_birth + t.integer :user_id + end + end +end diff --git a/front-api/db/schema.rb b/front-api/db/schema.rb index 46060f5..0b1c792 100644 --- a/front-api/db/schema.rb +++ b/front-api/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150318174814) do +ActiveRecord::Schema.define(version: 20150319104317) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -38,6 +38,13 @@ ActiveRecord::Schema.define(version: 20150318174814) do t.integer "order" end + create_table "children", force: :cascade do |t| + t.string "name" + t.integer "gender" + t.date "date_of_birth" + t.integer "user_id" + end + create_table "delivery_destinations", force: :cascade do |t| t.string "name" t.string "address" @@ -96,6 +103,7 @@ ActiveRecord::Schema.define(version: 20150318174814) do t.json "traits" t.decimal "weight", precision: 5, scale: 3 t.integer "special_offer_id" + t.integer "supplier_id" end create_table "media_types", force: :cascade do |t| @@ -145,6 +153,19 @@ ActiveRecord::Schema.define(version: 20150318174814) do t.integer "order" end + create_table "suppliers", force: :cascade do |t| + t.string "name" + t.string "address" + t.string "postal_code" + t.string "town" + t.string "phone" + t.string "contact_person" + t.string "email" + t.text "note" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "units", force: :cascade do |t| t.string "name" t.string "short_name", limit: 4 diff --git a/front-api/models/child.rb b/front-api/models/child.rb new file mode 100644 index 0000000..4482237 --- /dev/null +++ b/front-api/models/child.rb @@ -0,0 +1,3 @@ +class Child < ActiveRecord::Base + belongs_to :user +end diff --git a/front-api/models/user.rb b/front-api/models/user.rb index 41ba46d..a0b9d6c 100644 --- a/front-api/models/user.rb +++ b/front-api/models/user.rb @@ -1,5 +1,9 @@ class User < ActiveRecord::Base has_many :carts + has_many :children + + accepts_nested_attributes_for :children + has_secure_password validates_presence_of :first_name, :last_name, :password, :email, :password_confirmation diff --git a/front-ui/app/components/account/register.js b/front-ui/app/components/account/register.js index c61217c..237fa4d 100644 --- a/front-ui/app/components/account/register.js +++ b/front-ui/app/components/account/register.js @@ -164,14 +164,27 @@ var Register = React.createClass({ }, register: function(e) { if(this.validate()) { + var children = []; + if (this.state.myBabyDetailsVisible) { + children.push({ + name: 'Dijete', + gender: 1 + }); + } + var user = new UserRegistration({ first_name: this.state.firstName, last_name: this.state.lastName, email: this.state.email, password: this.state.password, - password_confirmation: this.state.passwordConfirmation + password_confirmation: this.state.passwordConfirmation, + children_attributes : children + }); + // need to add info about child + + UserActions.registerUser(user); } @@ -263,8 +276,8 @@ var Register = React.createClass({
+ Registruj me +