Refactored customer table and fixed all tests form that
This commit is contained in:
parent
d0cbb215d8
commit
f69b06bda2
13 changed files with 67 additions and 232 deletions
|
@ -79,7 +79,7 @@ sub post_register{
|
|||
if ( $usertype eq 'customer' ) {
|
||||
|
||||
my $age_rs = $c->schema->resultset('AgeRange');
|
||||
$validation->required('age')->in_resultset('agerangestring', $age_rs);
|
||||
$validation->required('age')->in_resultset('id', $age_rs);
|
||||
|
||||
} elsif ( $usertype eq 'organisation' ) {
|
||||
|
||||
|
@ -103,8 +103,6 @@ sub post_register{
|
|||
}
|
||||
|
||||
if ($usertype eq 'customer'){
|
||||
# TODO replace with actually using the value on the post request
|
||||
my $ageForeignKey = $c->get_age_foreign_key( $validation->param('age') );
|
||||
|
||||
$c->schema->txn_do( sub {
|
||||
$c->schema->resultset('AccountToken')->find({
|
||||
|
@ -113,9 +111,9 @@ sub post_register{
|
|||
})->update({ used => 1 });
|
||||
$c->schema->resultset('User')->create({
|
||||
customer => {
|
||||
username => $validation->param('username'),
|
||||
agerange_fk => $ageForeignKey,
|
||||
postcode => $validation->param('postcode'),
|
||||
username => $validation->param('username'),
|
||||
age_range_id => $validation->param('age'),
|
||||
postcode => $validation->param('postcode'),
|
||||
},
|
||||
email => $validation->param('email'),
|
||||
password => $validation->param('password'),
|
||||
|
|
|
@ -38,7 +38,7 @@ sub register {
|
|||
$validation->required('token')->in_resultset('accounttokenname', $token_rs);
|
||||
|
||||
my $age_rs = $c->schema->resultset('AgeRange');
|
||||
$validation->required('agerange')->in_resultset('agerangeid', $age_rs);
|
||||
$validation->required('agerange')->in_resultset('id', $age_rs);
|
||||
|
||||
my @error_messages;
|
||||
if ( $validation->has_error ) {
|
||||
|
@ -51,7 +51,7 @@ sub register {
|
|||
customer => {
|
||||
username => $validation->param('name'),
|
||||
postcode => $validation->param('postcode'),
|
||||
agerange_fk => $validation->param('agerange'),
|
||||
age_range_id => $validation->param('agerange'),
|
||||
},
|
||||
});
|
||||
if ( $new_user->in_storage ) {
|
||||
|
|
|
@ -1,107 +1,29 @@
|
|||
use utf8;
|
||||
package Pear::LocalLoop::Schema::Result::AgeRange;
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader
|
||||
# DO NOT MODIFY THE FIRST PART OF THIS FILE
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Pear::LocalLoop::Schema::Result::AgeRange
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'DBIx::Class::Core';
|
||||
|
||||
=head1 COMPONENTS LOADED
|
||||
|
||||
=over 4
|
||||
|
||||
=item * L<DBIx::Class::InflateColumn::DateTime>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->load_components("InflateColumn::DateTime");
|
||||
|
||||
=head1 TABLE: C<AgeRanges>
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->table("AgeRanges");
|
||||
|
||||
=head1 ACCESSORS
|
||||
|
||||
=head2 agerangeid
|
||||
|
||||
data_type: 'integer'
|
||||
is_auto_increment: 1
|
||||
is_nullable: 0
|
||||
|
||||
=head2 agerangestring
|
||||
|
||||
data_type: 'text'
|
||||
is_nullable: 0
|
||||
|
||||
=cut
|
||||
__PACKAGE__->table("age_ranges");
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
"agerangeid",
|
||||
"id",
|
||||
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
|
||||
"agerangestring",
|
||||
"string",
|
||||
{ data_type => "text", is_nullable => 0 },
|
||||
);
|
||||
|
||||
=head1 PRIMARY KEY
|
||||
__PACKAGE__->set_primary_key("id");
|
||||
|
||||
=over 4
|
||||
|
||||
=item * L</agerangeid>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->set_primary_key("agerangeid");
|
||||
|
||||
=head1 UNIQUE CONSTRAINTS
|
||||
|
||||
=head2 C<agerangestring_unique>
|
||||
|
||||
=over 4
|
||||
|
||||
=item * L</agerangestring>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->add_unique_constraint("agerangestring_unique", ["agerangestring"]);
|
||||
|
||||
=head1 RELATIONS
|
||||
|
||||
=head2 customers
|
||||
|
||||
Type: has_many
|
||||
|
||||
Related object: L<Pear::LocalLoop::Schema::Result::Customer>
|
||||
|
||||
=cut
|
||||
__PACKAGE__->add_unique_constraint(["string"]);
|
||||
|
||||
__PACKAGE__->has_many(
|
||||
"customers",
|
||||
"Pear::LocalLoop::Schema::Result::Customer",
|
||||
{ "foreign.agerange_fk" => "self.agerangeid" },
|
||||
{ "foreign.age_range_id" => "self.id" },
|
||||
{ cascade_copy => 0, cascade_delete => 0 },
|
||||
);
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-02-24 17:32:21
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:4zGNm0RlwptF9hlj9oErVA
|
||||
|
||||
|
||||
# You can replace this text with custom code or comments, and it will be preserved on regeneration
|
||||
1;
|
||||
|
|
|
@ -1,137 +1,52 @@
|
|||
use utf8;
|
||||
package Pear::LocalLoop::Schema::Result::Customer;
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader
|
||||
# DO NOT MODIFY THE FIRST PART OF THIS FILE
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Pear::LocalLoop::Schema::Result::Customer
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'DBIx::Class::Core';
|
||||
|
||||
=head1 COMPONENTS LOADED
|
||||
|
||||
=over 4
|
||||
|
||||
=item * L<DBIx::Class::InflateColumn::DateTime>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->load_components("InflateColumn::DateTime");
|
||||
|
||||
=head1 TABLE: C<Customers>
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->table("Customers");
|
||||
|
||||
=head1 ACCESSORS
|
||||
|
||||
=head2 customerid
|
||||
|
||||
data_type: 'integer'
|
||||
is_auto_increment: 1
|
||||
is_nullable: 0
|
||||
|
||||
=head2 username
|
||||
|
||||
data_type: 'text'
|
||||
is_nullable: 0
|
||||
|
||||
=head2 agerange_fk
|
||||
|
||||
data_type: 'integer'
|
||||
is_foreign_key: 1
|
||||
is_nullable: 0
|
||||
|
||||
=head2 postcode
|
||||
|
||||
data_type: 'text'
|
||||
is_nullable: 0
|
||||
|
||||
=cut
|
||||
__PACKAGE__->table("customers");
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
"customerid",
|
||||
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
|
||||
"username",
|
||||
{ data_type => "text", is_nullable => 0 },
|
||||
"agerange_fk",
|
||||
{ data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
|
||||
"postcode",
|
||||
{ data_type => "text", is_nullable => 0 },
|
||||
"id" => {
|
||||
data_type => "integer",
|
||||
is_auto_increment => 1,
|
||||
is_nullable => 0,
|
||||
},
|
||||
"username" => {
|
||||
data_type => "varchar",
|
||||
size => 255,
|
||||
is_nullable => 0,
|
||||
},
|
||||
"age_range_id" => {
|
||||
data_type => "integer",
|
||||
is_foreign_key => 1,
|
||||
is_nullable => 0,
|
||||
},
|
||||
"postcode" => {
|
||||
data_type => "varchar",
|
||||
size => 16,
|
||||
is_nullable => 0,
|
||||
},
|
||||
);
|
||||
|
||||
=head1 PRIMARY KEY
|
||||
__PACKAGE__->set_primary_key("id");
|
||||
|
||||
=over 4
|
||||
|
||||
=item * L</customerid>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->set_primary_key("customerid");
|
||||
|
||||
=head1 UNIQUE CONSTRAINTS
|
||||
|
||||
=head2 C<username_unique>
|
||||
|
||||
=over 4
|
||||
|
||||
=item * L</username>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->add_unique_constraint("username_unique", ["username"]);
|
||||
|
||||
=head1 RELATIONS
|
||||
|
||||
=head2 agerange_fk
|
||||
|
||||
Type: belongs_to
|
||||
|
||||
Related object: L<Pear::LocalLoop::Schema::Result::AgeRange>
|
||||
|
||||
=cut
|
||||
__PACKAGE__->add_unique_constraint(["username"]);
|
||||
|
||||
__PACKAGE__->belongs_to(
|
||||
"agerange_fk",
|
||||
"age_range",
|
||||
"Pear::LocalLoop::Schema::Result::AgeRange",
|
||||
{ agerangeid => "agerange_fk" },
|
||||
{ id => "age_range_id" },
|
||||
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
|
||||
);
|
||||
|
||||
=head2 user
|
||||
|
||||
Type: might_have
|
||||
|
||||
Related object: L<Pear::LocalLoop::Schema::Result::User>
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->might_have(
|
||||
"user",
|
||||
"Pear::LocalLoop::Schema::Result::User",
|
||||
{ "foreign.customer_id" => "self.customerid" },
|
||||
{ "foreign.customer_id" => "self.id" },
|
||||
{ cascade_copy => 0, cascade_delete => 0 },
|
||||
);
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-02-24 17:32:21
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ocoCGZYvw9O9wxzr14okiQ
|
||||
|
||||
|
||||
# You can replace this text with custom code or comments, and it will be preserved on regeneration
|
||||
1;
|
||||
|
|
|
@ -70,7 +70,7 @@ __PACKAGE__->might_have(
|
|||
__PACKAGE__->belongs_to(
|
||||
"customer",
|
||||
"Pear::LocalLoop::Schema::Result::Customer",
|
||||
{ customerid => "customer_id" },
|
||||
{ id => "customer_id" },
|
||||
{
|
||||
is_deferrable => 0,
|
||||
join_type => "LEFT",
|
||||
|
|
|
@ -29,7 +29,7 @@ has framework => sub {
|
|||
$schema->deploy;
|
||||
|
||||
$schema->resultset('AgeRange')->populate([
|
||||
[ qw/ agerangestring / ],
|
||||
[ qw/ string / ],
|
||||
[ '20-35' ],
|
||||
[ '35-50' ],
|
||||
[ '50+' ],
|
||||
|
|
Reference in a new issue