When submitting a transaction for a new organisation catenate the values for easier later retrieval.
This commit is contained in:
parent
ed5bbda6db
commit
cf0940f5f3
2 changed files with 24 additions and 44 deletions
|
@ -80,7 +80,7 @@ post '/search' => sub {
|
||||||
$statementValidated->execute('%'.$searchName.'%');
|
$statementValidated->execute('%'.$searchName.'%');
|
||||||
|
|
||||||
while (my ($id, $name, $address, $postcode) = $statementValidated->fetchrow_array()) {
|
while (my ($id, $name, $address, $postcode) = $statementValidated->fetchrow_array()) {
|
||||||
push(@validatedOrgs, $self->create_hash_valid($id,$name,$address,$postcode));
|
push(@validatedOrgs, $self->create_hash($id,$name,$address,$postcode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,11 +88,11 @@ post '/search' => sub {
|
||||||
|
|
||||||
my @unvalidatedOrgs = ();
|
my @unvalidatedOrgs = ();
|
||||||
{
|
{
|
||||||
my $statementUnvalidated = $dbh->prepare("SELECT PendingOrganisationId, Name, StreetName, Town, Postcode FROM PendingOrganisations WHERE Name LIKE ? AND UserSubmitted_FK = ?");
|
my $statementUnvalidated = $dbh->prepare("SELECT PendingOrganisationId, Name, FullAddress, Postcode FROM PendingOrganisations WHERE Name LIKE ? AND UserSubmitted_FK = ?");
|
||||||
$statementUnvalidated->execute('%'.$searchName.'%', $userId);
|
$statementUnvalidated->execute('%'.$searchName.'%', $userId);
|
||||||
|
|
||||||
while (my ($id, $name, $streetName, $town, $postcode) = $statementUnvalidated->fetchrow_array()) {
|
while (my ($id, $name, $fullAddress, $postcode) = $statementUnvalidated->fetchrow_array()) {
|
||||||
push(@unvalidatedOrgs, $self->create_hash_unvalid($id, $name, $streetName, $town, $postcode));
|
push(@unvalidatedOrgs, $self->create_hash($id, $name, $fullAddress, $postcode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,8 +303,24 @@ post '/upload' => sub {
|
||||||
$unvalidatedOrganisationId = 1;
|
$unvalidatedOrganisationId = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $statement = $self->db->prepare("INSERT INTO PendingOrganisations (PendingOrganisationId, UserSubmitted_FK, TimeDateSubmitted, Name, StreetName, Town, Postcode) VALUES (?, ?, ?, ?, ?, ?, ?)");
|
my $fullAddress = "";
|
||||||
my $rowsAdded = $statement->execute($unvalidatedOrganisationId,$userId,time(),$organisationName,$streetName,$town,$postcode);
|
|
||||||
|
if ( defined $streetName && ! ($streetName =~ m/^\s*$/) ){
|
||||||
|
$fullAddress = $streetName;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( defined $town && ! ($town =~ m/^\s*$/) ){
|
||||||
|
if ($fullAddress eq ""){
|
||||||
|
$fullAddress = $town;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$fullAddress = $fullAddress . ", " . $town;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
my $statement = $self->db->prepare("INSERT INTO PendingOrganisations (PendingOrganisationId, UserSubmitted_FK, TimeDateSubmitted, Name, FullAddress, Postcode) VALUES (?, ?, ?, ?, ?, ?)");
|
||||||
|
my $rowsAdded = $statement->execute($unvalidatedOrganisationId,$userId,time(),$organisationName,$fullAddress,$postcode);
|
||||||
|
|
||||||
#TODO, untested. It could not be added for some reason. Most likely race conditions.
|
#TODO, untested. It could not be added for some reason. Most likely race conditions.
|
||||||
if ($rowsAdded == 0) {
|
if ($rowsAdded == 0) {
|
||||||
|
@ -783,7 +799,7 @@ post '/fetchuser' => sub {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
helper create_hash_valid => sub{
|
helper create_hash => sub{
|
||||||
my ($self, $id, $name, $fullAddress, $postcode) = @_;
|
my ($self, $id, $name, $fullAddress, $postcode) = @_;
|
||||||
|
|
||||||
my $hash = {};
|
my $hash = {};
|
||||||
|
@ -794,41 +810,6 @@ helper create_hash_valid => sub{
|
||||||
return $hash;
|
return $hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
helper create_hash_unvalid => sub{
|
|
||||||
my ($self, $id, $name, $streetName, $town, $postcode) = @_;
|
|
||||||
|
|
||||||
my $hash = {};
|
|
||||||
$hash->{'id'} = $id;
|
|
||||||
$hash->{'name'} = $name;
|
|
||||||
|
|
||||||
my $fullAddress = "";
|
|
||||||
|
|
||||||
if (defined $streetName && ! ($streetName =~ m/^\s+$/)){
|
|
||||||
$fullAddress = $streetName;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (defined $town && ! ($town =~ m/^\s+$/)){
|
|
||||||
if ($fullAddress eq ""){
|
|
||||||
$fullAddress = $town;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
$fullAddress = $fullAddress . ", " . $town;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (defined $postcode && ! ($postcode =~ m/^\s+$/)){
|
|
||||||
if ($fullAddress eq ""){
|
|
||||||
$fullAddress = $postcode;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
$fullAddress = $fullAddress . ", " . $postcode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$hash->{'fullAddress'} = $fullAddress;
|
|
||||||
|
|
||||||
return $hash;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
helper valid_username => sub {
|
helper valid_username => sub {
|
||||||
|
|
|
@ -64,8 +64,7 @@ CREATE TABLE PendingOrganisations (
|
||||||
UserSubmitted_FK INTEGER NOT NULL,
|
UserSubmitted_FK INTEGER NOT NULL,
|
||||||
TimeDateSubmitted INTEGER NOT NULL,
|
TimeDateSubmitted INTEGER NOT NULL,
|
||||||
Name TEXT NOT NULL COLLATE nocase,
|
Name TEXT NOT NULL COLLATE nocase,
|
||||||
StreetName TEXT COLLATE nocase,
|
FullAddress TEXT COLLATE nocase,
|
||||||
Town TEXT COLLATE nocase,
|
|
||||||
Postcode TEXT COLLATE nocase,
|
Postcode TEXT COLLATE nocase,
|
||||||
FOREIGN KEY (UserSubmitted_FK) REFERENCES Users (UserId)
|
FOREIGN KEY (UserSubmitted_FK) REFERENCES Users (UserId)
|
||||||
);
|
);
|
||||||
|
|
Reference in a new issue