Refactor Organisation table to easier column names
This commit is contained in:
parent
e2cf58c895
commit
6596fd10aa
6 changed files with 93 additions and 142 deletions
|
@ -32,8 +32,11 @@ has error_messages => sub {
|
|||
required => { message => 'No age sent.', status => 400 },
|
||||
in_resultset => { message => 'Age range is invalid.', status => 400 },
|
||||
},
|
||||
fulladdress => {
|
||||
required => { message => 'No fulladdress sent.', status => 400 },
|
||||
street_address => {
|
||||
required => { message => 'No street_address sent.', status => 400 },
|
||||
},
|
||||
town => {
|
||||
required => { message => 'No town sent.', status => 400 },
|
||||
},
|
||||
};
|
||||
};
|
||||
|
@ -80,8 +83,8 @@ sub post_register{
|
|||
|
||||
} elsif ( $usertype eq 'organisation' ) {
|
||||
|
||||
#TODO validation on the address. Or perhaps add the organisation to a "to be inspected" list then manually check them.
|
||||
$validation->required('fulladdress');
|
||||
$validation->required('street_address');
|
||||
$validation->required('town');
|
||||
|
||||
}
|
||||
|
||||
|
@ -99,30 +102,24 @@ sub post_register{
|
|||
}
|
||||
}
|
||||
|
||||
my $token = $validation->param('token');
|
||||
my $username = $validation->param('username');
|
||||
my $email = $validation->param('email');
|
||||
my $postcode = $validation->param('postcode');
|
||||
my $password = $validation->param('password');
|
||||
|
||||
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({
|
||||
accounttokenname => $token,
|
||||
accounttokenname => $validation->param('token'),
|
||||
used => 0,
|
||||
})->update({ used => 1 });
|
||||
$c->schema->resultset('User')->create({
|
||||
customer => {
|
||||
username => $username,
|
||||
username => $validation->param('username'),
|
||||
agerange_fk => $ageForeignKey,
|
||||
postcode => $postcode,
|
||||
postcode => $validation->param('postcode'),
|
||||
},
|
||||
email => $email,
|
||||
hashedpassword => $password,
|
||||
joindate => DateTime->now,
|
||||
email => $validation->param('email'),
|
||||
hashedpassword => $validation->param('password'),
|
||||
joindate => DateTime->now,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -132,23 +129,27 @@ sub post_register{
|
|||
|
||||
$c->schema->txn_do( sub {
|
||||
$c->schema->resultset('AccountToken')->find({
|
||||
accounttokenname => $token,
|
||||
accounttokenname => $validation->param('token'),
|
||||
used => 0,
|
||||
})->update({ used => 1 });
|
||||
$c->schema->resultset('User')->create({
|
||||
organisation => {
|
||||
name => $username,
|
||||
fulladdress => $fullAddress,
|
||||
postcode => $postcode,
|
||||
name => $validation->param('username'),
|
||||
street_address => $validation->param('street_address'),
|
||||
town => $validation->param('town'),
|
||||
postcode => $validation->param('postcode'),
|
||||
},
|
||||
email => $email,
|
||||
hashedpassword => $password,
|
||||
joindate => DateTime->now,
|
||||
email => $validation->param('email'),
|
||||
hashedpassword => $validation->param('password'),
|
||||
joindate => DateTime->now,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return $c->render( json => { success => Mojo::JSON->true } );
|
||||
return $c->render( json => {
|
||||
success => Mojo::JSON->true,
|
||||
message => 'Registered Successfully',
|
||||
});
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -94,7 +94,7 @@ sub post_upload {
|
|||
if ( $type == 1 ) {
|
||||
# Validated Organisation
|
||||
my $valid_org_rs = $c->schema->resultset('Organisation');
|
||||
$validation->required('organisation_id')->number->in_resultset( 'organisationalid', $valid_org_rs );
|
||||
$validation->required('organisation_id')->number->in_resultset( 'id', $valid_org_rs );
|
||||
} elsif ( $type == 2 ) {
|
||||
# Unvalidated Organisation
|
||||
my $valid_org_rs = $c->schema->resultset('PendingOrganisation')->search({ usersubmitted_fk => $user->id });
|
||||
|
|
|
@ -1,85 +1,42 @@
|
|||
use utf8;
|
||||
package Pear::LocalLoop::Schema::Result::Organisation;
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader
|
||||
# DO NOT MODIFY THE FIRST PART OF THIS FILE
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Pear::LocalLoop::Schema::Result::Organisation
|
||||
|
||||
=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<Organisations>
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->table("Organisations");
|
||||
|
||||
=head1 ACCESSORS
|
||||
|
||||
=head2 organisationalid
|
||||
|
||||
data_type: 'integer'
|
||||
is_auto_increment: 1
|
||||
is_nullable: 0
|
||||
|
||||
=head2 name
|
||||
|
||||
data_type: 'text'
|
||||
is_nullable: 0
|
||||
|
||||
=head2 fulladdress
|
||||
|
||||
data_type: 'text'
|
||||
is_nullable: 0
|
||||
|
||||
=head2 postcode
|
||||
|
||||
data_type: 'text'
|
||||
is_nullable: 0
|
||||
|
||||
=cut
|
||||
__PACKAGE__->table("organisations");
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
"organisationalid",
|
||||
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
|
||||
"name",
|
||||
{ data_type => "text", is_nullable => 0 },
|
||||
"fulladdress",
|
||||
{ data_type => "text", is_nullable => 0 },
|
||||
"postcode",
|
||||
{ data_type => "text", is_nullable => 0 },
|
||||
id => {
|
||||
data_type => 'integer',
|
||||
is_auto_increment => 1,
|
||||
is_nullable => 0,
|
||||
},
|
||||
name => {
|
||||
data_type => 'varchar',
|
||||
size => 255,
|
||||
is_nullable => 0,
|
||||
},
|
||||
street_address => {
|
||||
data_type => 'text',
|
||||
is_nullable => 1,
|
||||
},
|
||||
town => {
|
||||
data_type => 'varchar',
|
||||
size => 255,
|
||||
is_nullable => 0,
|
||||
},
|
||||
postcode => {
|
||||
data_type => 'varchar',
|
||||
size => 16,
|
||||
is_nullable => 1,
|
||||
},
|
||||
);
|
||||
|
||||
=head1 PRIMARY KEY
|
||||
|
||||
=over 4
|
||||
|
||||
=item * L</organisationalid>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->set_primary_key("organisationalid");
|
||||
__PACKAGE__->set_primary_key('id');
|
||||
|
||||
=head1 RELATIONS
|
||||
|
||||
|
@ -94,7 +51,7 @@ Related object: L<Pear::LocalLoop::Schema::Result::Transaction>
|
|||
__PACKAGE__->has_many(
|
||||
"transactions",
|
||||
"Pear::LocalLoop::Schema::Result::Transaction",
|
||||
{ "foreign.sellerorganisationid_fk" => "self.organisationalid" },
|
||||
{ "foreign.sellerorganisationid_fk" => 'self.id' },
|
||||
{ cascade_copy => 0, cascade_delete => 0 },
|
||||
);
|
||||
|
||||
|
@ -109,14 +66,8 @@ Related object: L<Pear::LocalLoop::Schema::Result::User>
|
|||
__PACKAGE__->might_have(
|
||||
"user",
|
||||
"Pear::LocalLoop::Schema::Result::User",
|
||||
{ "foreign.organisationalid_fk" => "self.organisationalid" },
|
||||
{ "foreign.organisationalid_fk" => '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:p9FzM/H5YQbo2d0lN/DfCg
|
||||
|
||||
|
||||
# You can replace this text with custom code or comments, and it will be preserved on regeneration
|
||||
1;
|
||||
|
|
|
@ -139,7 +139,7 @@ Related object: L<Pear::LocalLoop::Schema::Result::Organisation>
|
|||
__PACKAGE__->belongs_to(
|
||||
"sellerorganisationid_fk",
|
||||
"Pear::LocalLoop::Schema::Result::Organisation",
|
||||
{ organisationalid => "sellerorganisationid_fk" },
|
||||
{ id => "sellerorganisationid_fk" },
|
||||
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
|
||||
);
|
||||
|
||||
|
|
|
@ -194,7 +194,7 @@ Related object: L<Pear::LocalLoop::Schema::Result::Organisation>
|
|||
__PACKAGE__->belongs_to(
|
||||
"organisation",
|
||||
"Pear::LocalLoop::Schema::Result::Organisation",
|
||||
{ organisationalid => "organisationalid_fk" },
|
||||
{ id => "organisationalid_fk" },
|
||||
{
|
||||
is_deferrable => 0,
|
||||
join_type => "LEFT",
|
||||
|
|
Reference in a new issue