Merge pull request #41 from Pear-Trading/TBSliver/Schema-Changes
Major schema changes
This commit is contained in:
commit
537048b506
116 changed files with 3167 additions and 1052 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,3 +7,4 @@ hypnotoad.pid
|
||||||
*.swp
|
*.swp
|
||||||
|
|
||||||
cover_db/
|
cover_db/
|
||||||
|
schema.png
|
||||||
|
|
5
cpanfile
5
cpanfile
|
@ -21,3 +21,8 @@ requires 'MooX::Options::Actions';
|
||||||
requires 'Module::Runtime';
|
requires 'Module::Runtime';
|
||||||
requires 'DBIx::Class::DeploymentHandler';
|
requires 'DBIx::Class::DeploymentHandler';
|
||||||
requires 'DBIx::Class::Fixtures';
|
requires 'DBIx::Class::Fixtures';
|
||||||
|
|
||||||
|
on 'schema-graph' => sub {
|
||||||
|
requires 'GraphViz';
|
||||||
|
requires 'SQL::Translator';
|
||||||
|
};
|
||||||
|
|
24
doc/Fixtures/Users.md
Normal file
24
doc/Fixtures/Users.md
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# Users Fixtures
|
||||||
|
|
||||||
|
* Fixture Name: `users`
|
||||||
|
|
||||||
|
## Users:
|
||||||
|
|
||||||
|
* Test User1
|
||||||
|
* email: test1@example.com
|
||||||
|
* password: abc123
|
||||||
|
* Test User2
|
||||||
|
* email: test2@example.com
|
||||||
|
* password: abc123
|
||||||
|
* Test User3
|
||||||
|
* email: test3@example.com
|
||||||
|
* password: abc123
|
||||||
|
* Test User4
|
||||||
|
* email: test4@example.com
|
||||||
|
* password: abc123
|
||||||
|
* Test Org
|
||||||
|
* email: test5@example.com
|
||||||
|
* password: abc123
|
||||||
|
* Test Admin
|
||||||
|
* email: admin@example.com
|
||||||
|
* password: abc123
|
|
@ -175,16 +175,12 @@ sub startup {
|
||||||
$admin_routes->get('/users/:id')->to('admin-users#read');
|
$admin_routes->get('/users/:id')->to('admin-users#read');
|
||||||
$admin_routes->post('/users/:id')->to('admin-users#update');
|
$admin_routes->post('/users/:id')->to('admin-users#update');
|
||||||
$admin_routes->post('/users/:id/delete')->to('admin-users#delete');
|
$admin_routes->post('/users/:id/delete')->to('admin-users#delete');
|
||||||
$admin_routes->post('/users/:id/edit')->to('admin-users#edit');
|
|
||||||
|
|
||||||
$admin_routes->get('/organisations')->to('admin-organisations#list');
|
$admin_routes->get('/organisations')->to('admin-organisations#list');
|
||||||
$admin_routes->get('/organisations/add')->to('admin-organisations#add_org');
|
$admin_routes->get('/organisations/add')->to('admin-organisations#add_org');
|
||||||
$admin_routes->post('/organisations/add/submit')->to('admin-organisations#add_org_submit');
|
$admin_routes->post('/organisations/add')->to('admin-organisations#add_org_submit');
|
||||||
$admin_routes->get('/organisations/valid/:id')->to('admin-organisations#valid_read');
|
$admin_routes->get('/organisations/:id')->to('admin-organisations#valid_read');
|
||||||
$admin_routes->post('/organisations/valid/:id/edit')->to('admin-organisations#valid_edit');
|
$admin_routes->post('/organisations/:id')->to('admin-organisations#valid_edit');
|
||||||
$admin_routes->get('/organisations/pending/:id')->to('admin-organisations#pending_read');
|
|
||||||
$admin_routes->post('/organisations/pending/:id/edit')->to('admin-organisations#pending_edit');
|
|
||||||
$admin_routes->get('/organisations/pending/:id/approve')->to('admin-organisations#pending_approve');
|
|
||||||
|
|
||||||
$admin_routes->get('/feedback')->to('admin-feedback#index');
|
$admin_routes->get('/feedback')->to('admin-feedback#index');
|
||||||
$admin_routes->get('/feedback/:id')->to('admin-feedback#read');
|
$admin_routes->get('/feedback/:id')->to('admin-feedback#read');
|
||||||
|
|
|
@ -5,10 +5,10 @@ sub under {
|
||||||
my $c = shift;
|
my $c = shift;
|
||||||
|
|
||||||
if ( $c->is_user_authenticated ) {
|
if ( $c->is_user_authenticated ) {
|
||||||
return 1 if defined $c->current_user->administrator;
|
return 1 if $c->current_user->is_admin;
|
||||||
}
|
}
|
||||||
$c->redirect_to('/');
|
$c->redirect_to('/');
|
||||||
return undef;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub home {
|
sub home {
|
||||||
|
@ -16,8 +16,8 @@ sub home {
|
||||||
|
|
||||||
my $user_rs = $c->schema->resultset('User');
|
my $user_rs = $c->schema->resultset('User');
|
||||||
my $token_rs = $c->schema->resultset('AccountToken');
|
my $token_rs = $c->schema->resultset('AccountToken');
|
||||||
my $pending_orgs_rs = $c->schema->resultset('PendingOrganisation');
|
my $pending_orgs_rs = $c->schema->resultset('Organisation')->search({ pending => 1 });
|
||||||
my $pending_transaction_rs = $c->schema->resultset('PendingTransaction');
|
my $pending_transaction_rs = $pending_orgs_rs->entity->sales;
|
||||||
$c->stash(
|
$c->stash(
|
||||||
user_count => $user_rs->count,
|
user_count => $user_rs->count,
|
||||||
tokens => {
|
tokens => {
|
||||||
|
|
|
@ -2,13 +2,12 @@ package Pear::LocalLoop::Controller::Admin::Organisations;
|
||||||
use Mojo::Base 'Mojolicious::Controller';
|
use Mojo::Base 'Mojolicious::Controller';
|
||||||
|
|
||||||
use Try::Tiny;
|
use Try::Tiny;
|
||||||
use Data::Dumper;
|
|
||||||
|
|
||||||
sub list {
|
sub list {
|
||||||
my $c = shift;
|
my $c = shift;
|
||||||
|
|
||||||
my $valid_orgs_rs = $c->schema->resultset('Organisation');
|
my $valid_orgs_rs = $c->schema->resultset('Organisation')->search({ pending => 0 });
|
||||||
my $pending_orgs_rs = $c->schema->resultset('PendingOrganisation');
|
my $pending_orgs_rs = $c->schema->resultset('Organisation')->search({ pending => 1 });
|
||||||
|
|
||||||
$c->stash(
|
$c->stash(
|
||||||
valid_orgs_rs => $valid_orgs_rs,
|
valid_orgs_rs => $valid_orgs_rs,
|
||||||
|
@ -30,38 +29,44 @@ sub add_org_submit {
|
||||||
$validation->required('town');
|
$validation->required('town');
|
||||||
$validation->optional('sector');
|
$validation->optional('sector');
|
||||||
$validation->optional('postcode')->postcode;
|
$validation->optional('postcode')->postcode;
|
||||||
|
$validation->optional('pending');
|
||||||
|
|
||||||
if ( $validation->has_error ) {
|
if ( $validation->has_error ) {
|
||||||
$c->flash( error => 'The validation has failed' );
|
$c->flash( error => 'The validation has failed' );
|
||||||
$c->app->log->warn(Dumper $validation);
|
return $c->redirect_to( '/admin/organisations/add' );
|
||||||
return $c->redirect_to( '/admin/organisations/add/' );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
my $organisation;
|
my $organisation;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$organisation = $c->schema->resultset('Organisation')->create({
|
my $entity = $c->schema->resultset('Entity')->create({
|
||||||
name => $validation->param('name'),
|
organisation => {
|
||||||
street_name => $validation->param('street_name'),
|
name => $validation->param('name'),
|
||||||
town => $validation->param('town'),
|
street_name => $validation->param('street_name'),
|
||||||
sector => $validation->param('sector'),
|
town => $validation->param('town'),
|
||||||
postcode => $validation->param('postcode'),
|
sector => $validation->param('sector'),
|
||||||
|
postcode => $validation->param('postcode'),
|
||||||
|
submitted_by_id => $c->current_user->id,
|
||||||
|
pending => defined $validation->param('pending') ? 0 : 1,
|
||||||
|
},
|
||||||
|
type => 'organisation',
|
||||||
});
|
});
|
||||||
|
$organisation = $entity->organisation;
|
||||||
} finally {
|
} finally {
|
||||||
if ( @_ ) {
|
if ( @_ ) {
|
||||||
$c->flash( error => 'Something went wrong Adding the Organisation' );
|
$c->flash( error => 'Something went wrong Adding the Organisation' );
|
||||||
$c->app->log->warn(Dumper @_);
|
$c->redirect_to( '/admin/organisations/add' );
|
||||||
} else {
|
} else {
|
||||||
$c->flash( success => 'Added Organisation' );
|
$c->flash( success => 'Added Organisation' );
|
||||||
|
$c->redirect_to( '/admin/organisations/' . $organisation->id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
$c->redirect_to( '/admin/organisations/add/' );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub valid_read {
|
sub valid_read {
|
||||||
my $c = shift;
|
my $c = shift;
|
||||||
my $valid_org = $c->schema->resultset('Organisation')->find( $c->param('id') );
|
my $valid_org = $c->schema->resultset('Organisation')->find( $c->param('id') );
|
||||||
my $transactions = $valid_org->transactions->search(
|
my $transactions = $valid_org->entity->sales->search(
|
||||||
undef, {
|
undef, {
|
||||||
page => $c->param('page') || 1,
|
page => $c->param('page') || 1,
|
||||||
rows => 10,
|
rows => 10,
|
||||||
|
@ -83,11 +88,11 @@ sub valid_edit {
|
||||||
$validation->required('town');
|
$validation->required('town');
|
||||||
$validation->optional('sector');
|
$validation->optional('sector');
|
||||||
$validation->required('postcode')->postcode;
|
$validation->required('postcode')->postcode;
|
||||||
|
$validation->optional('pending');
|
||||||
|
|
||||||
if ( $validation->has_error ) {
|
if ( $validation->has_error ) {
|
||||||
$c->flash( error => 'The validation has failed' );
|
$c->flash( error => 'The validation has failed' );
|
||||||
$c->app->log->warn(Dumper $validation);
|
return $c->redirect_to( '/admin/organisations/' . $c->param('id') );
|
||||||
return $c->redirect_to( '/admin/organisations/valid/' . $c->param('id') );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
my $valid_org = $c->schema->resultset('Organisation')->find( $c->param('id') );
|
my $valid_org = $c->schema->resultset('Organisation')->find( $c->param('id') );
|
||||||
|
@ -100,95 +105,17 @@ sub valid_edit {
|
||||||
town => $validation->param('town'),
|
town => $validation->param('town'),
|
||||||
sector => $validation->param('sector'),
|
sector => $validation->param('sector'),
|
||||||
postcode => $validation->param('postcode'),
|
postcode => $validation->param('postcode'),
|
||||||
|
pending => defined $validation->param('pending') ? 0 : 1,
|
||||||
});
|
});
|
||||||
} );
|
} );
|
||||||
} finally {
|
} finally {
|
||||||
if ( @_ ) {
|
if ( @_ ) {
|
||||||
$c->flash( error => 'Something went wrong Updating the Organisation' );
|
$c->flash( error => 'Something went wrong Updating the Organisation' );
|
||||||
$c->app->log->warn(Dumper @_);
|
|
||||||
} else {
|
} else {
|
||||||
$c->flash( success => 'Updated Organisation' );
|
$c->flash( success => 'Updated Organisation' );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
$c->redirect_to( '/admin/organisations/valid/' . $valid_org->id );
|
$c->redirect_to( '/admin/organisations/' . $valid_org->id );
|
||||||
}
|
|
||||||
|
|
||||||
sub pending_read {
|
|
||||||
my $c = shift;
|
|
||||||
my $pending_org = $c->schema->resultset('PendingOrganisation')->find( $c->param('id') );
|
|
||||||
my $transactions = $pending_org->transactions->search(
|
|
||||||
undef, {
|
|
||||||
page => $c->param('page') || 1,
|
|
||||||
rows => 10,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
$c->stash(
|
|
||||||
pending_org => $pending_org,
|
|
||||||
transactions => $transactions,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
sub pending_edit {
|
|
||||||
my $c = shift;
|
|
||||||
|
|
||||||
my $validation = $c->validation;
|
|
||||||
$validation->required('name');
|
|
||||||
$validation->required('street_name');
|
|
||||||
$validation->required('town');
|
|
||||||
$validation->required('postcode')->postcode;
|
|
||||||
|
|
||||||
if ( $validation->has_error ) {
|
|
||||||
$c->flash( error => 'The validation has failed' );
|
|
||||||
$c->app->log->warn(Dumper $validation);
|
|
||||||
return $c->redirect_to( '/admin/organisations/pending/' . $c->param('id') );
|
|
||||||
}
|
|
||||||
|
|
||||||
my $pending_org = $c->schema->resultset('PendingOrganisation')->find( $c->param('id') );
|
|
||||||
|
|
||||||
try {
|
|
||||||
$c->schema->storage->txn_do( sub {
|
|
||||||
$pending_org->update({
|
|
||||||
name => $validation->param('name'),
|
|
||||||
street_name => $validation->param('street_name'),
|
|
||||||
town => $validation->param('town'),
|
|
||||||
postcode => $validation->param('postcode'),
|
|
||||||
});
|
|
||||||
} );
|
|
||||||
} finally {
|
|
||||||
if ( @_ ) {
|
|
||||||
$c->flash( error => 'Something went wrong Updating the Organisation' );
|
|
||||||
$c->app->log->warn(Dumper @_);
|
|
||||||
} else {
|
|
||||||
$c->flash( success => 'Updated Organisation' );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
$c->redirect_to( '/admin/organisations/pending/' . $pending_org->id );
|
|
||||||
}
|
|
||||||
|
|
||||||
sub pending_approve {
|
|
||||||
my $c = shift;
|
|
||||||
my $pending_org = $c->schema->resultset('PendingOrganisation')->find( $c->param('id') );
|
|
||||||
|
|
||||||
my $valid_org;
|
|
||||||
try {
|
|
||||||
$c->schema->storage->txn_do( sub {
|
|
||||||
$valid_org = $c->schema->resultset('Organisation')->create({
|
|
||||||
name => $pending_org->name,
|
|
||||||
street_name => $pending_org->street_name,
|
|
||||||
town => $pending_org->town,
|
|
||||||
postcode => $pending_org->postcode,
|
|
||||||
});
|
|
||||||
$c->copy_transactions_and_delete( $pending_org, $valid_org );
|
|
||||||
} );
|
|
||||||
} finally {
|
|
||||||
if ( @_ ) {
|
|
||||||
$c->flash( error => 'Something went wrong Validating the Organisation' );
|
|
||||||
$c->redirect_to( '/admin/organisations/pending/' . $pending_org->id );
|
|
||||||
} else {
|
|
||||||
$c->flash( success => 'Validated Organisation' );
|
|
||||||
$c->redirect_to( '/admin/organisations/valid/' . $valid_org->id );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -40,7 +40,7 @@ sub read {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub edit {
|
sub update {
|
||||||
my $c = shift;
|
my $c = shift;
|
||||||
|
|
||||||
my $id = $c->param('id');
|
my $id = $c->param('id');
|
||||||
|
@ -61,10 +61,10 @@ sub edit {
|
||||||
$validation->required('postcode')->postcode;
|
$validation->required('postcode')->postcode;
|
||||||
$validation->optional('new_password');
|
$validation->optional('new_password');
|
||||||
|
|
||||||
if ( defined $user->customer_id ) {
|
if ( $user->type eq 'customer' ) {
|
||||||
$validation->required('display_name');
|
$validation->required('display_name');
|
||||||
$validation->required('full_name');
|
$validation->required('full_name');
|
||||||
} elsif ( defined $user->organisation_id ) {
|
} elsif ( $user->type eq 'organisation' ) {
|
||||||
$validation->required('name');
|
$validation->required('name');
|
||||||
$validation->required('street_name');
|
$validation->required('street_name');
|
||||||
$validation->required('town');
|
$validation->required('town');
|
||||||
|
@ -73,15 +73,14 @@ sub edit {
|
||||||
|
|
||||||
if ( $validation->has_error ) {
|
if ( $validation->has_error ) {
|
||||||
$c->flash( error => 'The validation has failed' );
|
$c->flash( error => 'The validation has failed' );
|
||||||
$c->app->log->warn(Dumper $validation);
|
|
||||||
return $c->redirect_to( '/admin/users/' . $id );
|
return $c->redirect_to( '/admin/users/' . $id );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( defined $user->customer_id ){
|
if ( $user->type eq 'customer' ){
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$c->schema->txn_do( sub {
|
$c->schema->txn_do( sub {
|
||||||
$user->customer->update({
|
$user->entity->customer->update({
|
||||||
full_name => $validation->param('full_name'),
|
full_name => $validation->param('full_name'),
|
||||||
display_name => $validation->param('display_name'),
|
display_name => $validation->param('display_name'),
|
||||||
postcode => $validation->param('postcode'),
|
postcode => $validation->param('postcode'),
|
||||||
|
@ -100,11 +99,11 @@ sub edit {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ( defined $user->organisation_id ) {
|
elsif ( $user->type eq 'organisation' ) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$c->schema->txn_do( sub {
|
$c->schema->txn_do( sub {
|
||||||
$user->organisation->update({
|
$user->entity->organisation->update({
|
||||||
name => $validation->param('name'),
|
name => $validation->param('name'),
|
||||||
street_name => $validation->param('street_name'),
|
street_name => $validation->param('street_name'),
|
||||||
town => $validation->param('town'),
|
town => $validation->param('town'),
|
||||||
|
@ -129,9 +128,4 @@ sub edit {
|
||||||
$c->redirect_to( '/admin/users/' . $id );
|
$c->redirect_to( '/admin/users/' . $id );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub update {
|
|
||||||
my $c = shift;
|
|
||||||
$c->redirect_to( '/admin/users' );
|
|
||||||
}
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -48,7 +48,7 @@ has error_messages => sub {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
sub post_register{
|
sub post_register {
|
||||||
my $c = shift;
|
my $c = shift;
|
||||||
|
|
||||||
my $validation = $c->validation;
|
my $validation = $c->validation;
|
||||||
|
@ -87,17 +87,19 @@ sub post_register{
|
||||||
name => $validation->param('token'),
|
name => $validation->param('token'),
|
||||||
used => 0,
|
used => 0,
|
||||||
})->update({ used => 1 });
|
})->update({ used => 1 });
|
||||||
# Create customer as a seperate step, so we dont leak data
|
|
||||||
my $customer = $c->schema->resultset('Customer')->create({
|
$c->schema->resultset('Entity')->create({
|
||||||
full_name => $validation->param('full_name'),
|
customer => {
|
||||||
display_name => $validation->param('display_name'),
|
full_name => $validation->param('full_name'),
|
||||||
year_of_birth => $validation->param('year_of_birth'),
|
display_name => $validation->param('display_name'),
|
||||||
postcode => $validation->param('postcode'),
|
year_of_birth => $validation->param('year_of_birth'),
|
||||||
});
|
postcode => $validation->param('postcode'),
|
||||||
$c->schema->resultset('User')->create({
|
},
|
||||||
customer => $customer,
|
user => {
|
||||||
email => $validation->param('email'),
|
email => $validation->param('email'),
|
||||||
password => $validation->param('password'),
|
password => $validation->param('password'),
|
||||||
|
},
|
||||||
|
type => 'customer',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -109,17 +111,19 @@ sub post_register{
|
||||||
name => $validation->param('token'),
|
name => $validation->param('token'),
|
||||||
used => 0,
|
used => 0,
|
||||||
})->update({ used => 1 });
|
})->update({ used => 1 });
|
||||||
my $organisation = $c->schema->resultset('Organisation')->create({
|
$c->schema->resultset('Entity')->create({
|
||||||
name => $validation->param('name'),
|
organisation => {
|
||||||
street_name => $validation->param('street_name'),
|
name => $validation->param('name'),
|
||||||
town => $validation->param('town'),
|
street_name => $validation->param('street_name'),
|
||||||
sector => $validation->param('sector'),
|
town => $validation->param('town'),
|
||||||
postcode => $validation->param('postcode'),
|
sector => $validation->param('sector'),
|
||||||
});
|
postcode => $validation->param('postcode'),
|
||||||
$c->schema->resultset('User')->create({
|
},
|
||||||
organisation => $organisation,
|
user => {
|
||||||
email => $validation->param('email'),
|
email => $validation->param('email'),
|
||||||
password => $validation->param('password'),
|
password => $validation->param('password'),
|
||||||
|
},
|
||||||
|
type => 'organisation',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,21 +15,21 @@ has error_messages => sub {
|
||||||
sub post_index {
|
sub post_index {
|
||||||
my $c = shift;
|
my $c = shift;
|
||||||
|
|
||||||
my $user = $c->stash->{api_user};
|
my $user = $c->stash->{api_user}->entity;
|
||||||
|
|
||||||
my $today_rs = $user->transactions->today_rs;
|
my $today_rs = $user->purchases->today_rs;
|
||||||
my $today_sum = $today_rs->get_column('value')->sum;
|
my $today_sum = $today_rs->get_column('value')->sum;
|
||||||
my $today_count = $today_rs->count;
|
my $today_count = $today_rs->count;
|
||||||
|
|
||||||
my $week_rs = $user->transactions->week_rs;
|
my $week_rs = $user->purchases->week_rs;
|
||||||
my $week_sum = $week_rs->get_column('value')->sum;
|
my $week_sum = $week_rs->get_column('value')->sum;
|
||||||
my $week_count = $week_rs->count;
|
my $week_count = $week_rs->count;
|
||||||
|
|
||||||
my $month_rs = $user->transactions->month_rs;
|
my $month_rs = $user->purchases->month_rs;
|
||||||
my $month_sum = $month_rs->get_column('value')->sum;
|
my $month_sum = $month_rs->get_column('value')->sum;
|
||||||
my $month_count = $month_rs->count;
|
my $month_count = $month_rs->count;
|
||||||
|
|
||||||
my $user_rs = $user->transactions;
|
my $user_rs = $user->purchases;
|
||||||
my $user_sum = $user_rs->get_column('value')->sum;
|
my $user_sum = $user_rs->get_column('value')->sum;
|
||||||
my $user_count = $user_rs->count;
|
my $user_count = $user_rs->count;
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ sub post_index {
|
||||||
my $leaderboard_rs = $c->schema->resultset('Leaderboard');
|
my $leaderboard_rs = $c->schema->resultset('Leaderboard');
|
||||||
my $monthly_board = $leaderboard_rs->get_latest( 'monthly_total' );
|
my $monthly_board = $leaderboard_rs->get_latest( 'monthly_total' );
|
||||||
my $monthly_values = $monthly_board->values;
|
my $monthly_values = $monthly_board->values;
|
||||||
my $current_user_position = $monthly_values ? $monthly_values->find({ user_id => $c->stash->{api_user}->id }) : undef;
|
my $current_user_position = $monthly_values ? $monthly_values->find({ entity_id => $user->id }) : undef;
|
||||||
|
|
||||||
return $c->render( json => {
|
return $c->render( json => {
|
||||||
success => Mojo::JSON->true,
|
success => Mojo::JSON->true,
|
||||||
|
@ -84,14 +84,14 @@ sub post_leaderboards {
|
||||||
/,
|
/,
|
||||||
{ display_name => 'customer.display_name' },
|
{ display_name => 'customer.display_name' },
|
||||||
],
|
],
|
||||||
join => { user => 'customer' },
|
join => { entity => 'customer' },
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
$today_values->result_class( 'DBIx::Class::ResultClass::HashRefInflator' );
|
$today_values->result_class( 'DBIx::Class::ResultClass::HashRefInflator' );
|
||||||
|
|
||||||
my @leaderboard_array = $today_values->all;
|
my @leaderboard_array = $today_values->all;
|
||||||
|
|
||||||
my $current_user_position = $today_values->find({ user_id => $c->stash->{api_user}->id });
|
my $current_user_position = $today_values->find({ entity_id => $c->stash->{api_user}->entity->id });
|
||||||
|
|
||||||
return $c->render( json => {
|
return $c->render( json => {
|
||||||
success => Mojo::JSON->true,
|
success => Mojo::JSON->true,
|
||||||
|
|
|
@ -112,7 +112,7 @@ sub post_upload {
|
||||||
|
|
||||||
if ( $type == 1 ) {
|
if ( $type == 1 ) {
|
||||||
# Validated Organisation
|
# Validated Organisation
|
||||||
my $valid_org_rs = $c->schema->resultset('Organisation');
|
my $valid_org_rs = $c->schema->resultset('Organisation')->search({ pending => 0 });
|
||||||
$validation->required('organisation_id')->number->in_resultset( 'id', $valid_org_rs );
|
$validation->required('organisation_id')->number->in_resultset( 'id', $valid_org_rs );
|
||||||
|
|
||||||
return $c->api_validation_error if $validation->has_error;
|
return $c->api_validation_error if $validation->has_error;
|
||||||
|
@ -121,7 +121,7 @@ sub post_upload {
|
||||||
|
|
||||||
} elsif ( $type == 2 ) {
|
} elsif ( $type == 2 ) {
|
||||||
# Unvalidated Organisation
|
# Unvalidated Organisation
|
||||||
my $valid_org_rs = $c->schema->resultset('PendingOrganisation')->search({ submitted_by_id => $user->id });
|
my $valid_org_rs = $c->schema->resultset('Organisation')->search({ submitted_by_id => $user->id, pending => 1 });
|
||||||
$validation->required('organisation_id')->number->in_resultset( 'id', $valid_org_rs );
|
$validation->required('organisation_id')->number->in_resultset( 'id', $valid_org_rs );
|
||||||
|
|
||||||
return $c->api_validation_error if $validation->has_error;
|
return $c->api_validation_error if $validation->has_error;
|
||||||
|
@ -137,14 +137,15 @@ sub post_upload {
|
||||||
|
|
||||||
return $c->api_validation_error if $validation->has_error;
|
return $c->api_validation_error if $validation->has_error;
|
||||||
|
|
||||||
$organisation = $c->schema->resultset('PendingOrganisation')->create({
|
my $entity = $c->schema->resultset('Entity')->create_org({
|
||||||
submitted_by => $user,
|
submitted_by_id => $user->id,
|
||||||
submitted_at => DateTime->now,
|
name => $validation->param('organisation_name'),
|
||||||
name => $validation->param('organisation_name'),
|
street_name => $validation->param('street_name'),
|
||||||
street_name => $validation->param('street_name'),
|
town => $validation->param('town'),
|
||||||
town => $validation->param('town'),
|
postcode => $validation->param('postcode'),
|
||||||
postcode => $validation->param('postcode'),
|
pending => \"1"
|
||||||
});
|
});
|
||||||
|
$organisation = $entity->organisation;
|
||||||
}
|
}
|
||||||
|
|
||||||
unless ( defined $organisation ) {
|
unless ( defined $organisation ) {
|
||||||
|
@ -164,12 +165,12 @@ sub post_upload {
|
||||||
$purchase_time ||= DateTime->now();
|
$purchase_time ||= DateTime->now();
|
||||||
my $file = defined $upload ? $c->store_file_from_upload( $upload ) : undef;
|
my $file = defined $upload ? $c->store_file_from_upload( $upload ) : undef;
|
||||||
|
|
||||||
my $new_transaction = $organisation->create_related(
|
my $new_transaction = $organisation->entity->create_related(
|
||||||
'transactions',
|
'sales',
|
||||||
{
|
{
|
||||||
buyer => $user,
|
buyer => $user->entity,
|
||||||
value => $transaction_value,
|
value => $transaction_value,
|
||||||
( defined $file ? ( proof_image => $file ) : ( proof_image => 'a' ) ),
|
( defined $file ? ( proof_image => $file ) : () ),
|
||||||
purchase_time => $c->format_db_datetime($purchase_time),
|
purchase_time => $c->format_db_datetime($purchase_time),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -209,11 +210,15 @@ sub post_search {
|
||||||
|
|
||||||
my $search_stmt = [ 'LOWER("name") LIKE ?', '%' . lc $search_name . '%' ];
|
my $search_stmt = [ 'LOWER("name") LIKE ?', '%' . lc $search_name . '%' ];
|
||||||
|
|
||||||
my $valid_orgs_rs = $c->schema->resultset('Organisation')->search(
|
my $org_rs = $c->schema->resultset('Organisation');
|
||||||
|
my $valid_orgs_rs = $org_rs->search({ pending => 0 })->search(
|
||||||
\$search_stmt,
|
\$search_stmt,
|
||||||
);
|
);
|
||||||
|
|
||||||
my $pending_orgs_rs = $c->stash->{api_user}->pending_organisations->search(
|
my $pending_orgs_rs = $org_rs->search({
|
||||||
|
pending => 1,
|
||||||
|
submitted_by_id => $c->stash->{api_user}->id,
|
||||||
|
})->search(
|
||||||
\$search_stmt,
|
\$search_stmt,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -65,12 +65,12 @@ sub post_account {
|
||||||
my $postcode;
|
my $postcode;
|
||||||
|
|
||||||
#Needs elsif added for trader page for this similar relevant entry
|
#Needs elsif added for trader page for this similar relevant entry
|
||||||
if ( defined $user_result->customer_id ) {
|
if ( $user_result->type eq 'customer' ) {
|
||||||
$full_name = $user_result->customer->full_name;
|
$full_name = $user_result->entity->customer->full_name;
|
||||||
$display_name = $user_result->customer->display_name;
|
$display_name = $user_result->entity->customer->display_name;
|
||||||
$postcode = $user_result->customer->postcode;
|
$postcode = $user_result->entity->customer->postcode;
|
||||||
} elsif ( defined $user_result->organisation_id ) {
|
} elsif ( $user_result->type eq 'organisation' ) {
|
||||||
$display_name = $user_result->organisation->name;
|
$display_name = $user_result->entity->organisation->name;
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -121,10 +121,10 @@ sub post_account_update {
|
||||||
$validation->required('postcode')->postcode;
|
$validation->required('postcode')->postcode;
|
||||||
$validation->optional('new_password');
|
$validation->optional('new_password');
|
||||||
|
|
||||||
if ( defined $user->customer_id ) {
|
if ( $user->type eq 'customer' ) {
|
||||||
$validation->required('display_name');
|
$validation->required('display_name');
|
||||||
$validation->required('full_name');
|
$validation->required('full_name');
|
||||||
} elsif ( defined $user->organisation_id ) {
|
} elsif ( $user->type eq 'organisation' ) {
|
||||||
$validation->required('name');
|
$validation->required('name');
|
||||||
$validation->required('street_name');
|
$validation->required('street_name');
|
||||||
$validation->required('town');
|
$validation->required('town');
|
||||||
|
@ -133,10 +133,10 @@ sub post_account_update {
|
||||||
|
|
||||||
return $c->api_validation_error if $validation->has_error;
|
return $c->api_validation_error if $validation->has_error;
|
||||||
|
|
||||||
if ( defined $user->customer_id ){
|
if ( $user->type eq 'customer' ){
|
||||||
|
|
||||||
$c->schema->txn_do( sub {
|
$c->schema->txn_do( sub {
|
||||||
$user->customer->update({
|
$user->entity->customer->update({
|
||||||
full_name => $validation->param('full_name'),
|
full_name => $validation->param('full_name'),
|
||||||
display_name => $validation->param('display_name'),
|
display_name => $validation->param('display_name'),
|
||||||
postcode => $validation->param('postcode'),
|
postcode => $validation->param('postcode'),
|
||||||
|
@ -148,10 +148,10 @@ sub post_account_update {
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
elsif ( defined $user->organisation_id ) {
|
elsif ( $user->type eq 'organisation' ) {
|
||||||
|
|
||||||
$c->schema->txn_do( sub {
|
$c->schema->txn_do( sub {
|
||||||
$user->organisation->update({
|
$user->entity->organisation->update({
|
||||||
name => $validation->param('name'),
|
name => $validation->param('name'),
|
||||||
street_name => $validation->param('street_name'),
|
street_name => $validation->param('street_name'),
|
||||||
town => $validation->param('town'),
|
town => $validation->param('town'),
|
||||||
|
|
|
@ -56,7 +56,7 @@ sub graph_customers_last_30_days {
|
||||||
sub _customers_last_duration {
|
sub _customers_last_duration {
|
||||||
my ( $c, $duration ) = @_;
|
my ( $c, $duration ) = @_;
|
||||||
|
|
||||||
my $org = $c->stash->{api_user}->organisation;
|
my $org = $c->stash->{api_user}->entity;
|
||||||
|
|
||||||
my $data = { day => [], count => [] };
|
my $data = { day => [], count => [] };
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ use warnings;
|
||||||
|
|
||||||
use base 'DBIx::Class::Schema';
|
use base 'DBIx::Class::Schema';
|
||||||
|
|
||||||
our $VERSION = 5;
|
our $VERSION = 6;
|
||||||
|
|
||||||
__PACKAGE__->load_namespaces;
|
__PACKAGE__->load_namespaces;
|
||||||
|
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
package Pear::LocalLoop::Schema::Result::Administrator;
|
|
||||||
|
|
||||||
use strict;
|
|
||||||
use warnings;
|
|
||||||
|
|
||||||
use base 'DBIx::Class::Core';
|
|
||||||
|
|
||||||
__PACKAGE__->table("administrators");
|
|
||||||
|
|
||||||
__PACKAGE__->add_columns(
|
|
||||||
"user_id",
|
|
||||||
{
|
|
||||||
data_type => "integer",
|
|
||||||
is_foreign_key => 1,
|
|
||||||
is_nullable => 0,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
__PACKAGE__->set_primary_key("user_id");
|
|
||||||
|
|
||||||
__PACKAGE__->belongs_to(
|
|
||||||
"user",
|
|
||||||
"Pear::LocalLoop::Schema::Result::User",
|
|
||||||
{ id => "user_id" },
|
|
||||||
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
|
|
||||||
);
|
|
||||||
|
|
||||||
1;
|
|
|
@ -13,6 +13,11 @@ __PACKAGE__->add_columns(
|
||||||
is_auto_increment => 1,
|
is_auto_increment => 1,
|
||||||
is_nullable => 0,
|
is_nullable => 0,
|
||||||
},
|
},
|
||||||
|
"entity_id" => {
|
||||||
|
data_type => "integer",
|
||||||
|
is_nullable => 0,
|
||||||
|
is_foreign_key => 1,
|
||||||
|
},
|
||||||
"display_name" => {
|
"display_name" => {
|
||||||
data_type => "varchar",
|
data_type => "varchar",
|
||||||
size => 255,
|
size => 255,
|
||||||
|
@ -36,11 +41,10 @@ __PACKAGE__->add_columns(
|
||||||
|
|
||||||
__PACKAGE__->set_primary_key("id");
|
__PACKAGE__->set_primary_key("id");
|
||||||
|
|
||||||
__PACKAGE__->might_have(
|
__PACKAGE__->belongs_to(
|
||||||
"user",
|
"entity",
|
||||||
"Pear::LocalLoop::Schema::Result::User",
|
"Pear::LocalLoop::Schema::Result::Entity",
|
||||||
{ "foreign.customer_id" => "self.id" },
|
"entity_id",
|
||||||
{ cascade_copy => 0, cascade_delete => 0 },
|
|
||||||
);
|
);
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
66
lib/Pear/LocalLoop/Schema/Result/Entity.pm
Normal file
66
lib/Pear/LocalLoop/Schema/Result/Entity.pm
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
package Pear::LocalLoop::Schema::Result::Entity;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use base 'DBIx::Class::Core';
|
||||||
|
|
||||||
|
__PACKAGE__->table("entities");
|
||||||
|
|
||||||
|
__PACKAGE__->add_columns(
|
||||||
|
"id" => {
|
||||||
|
data_type => "integer",
|
||||||
|
is_auto_increment => 1,
|
||||||
|
is_nullable => 0,
|
||||||
|
},
|
||||||
|
"type" => {
|
||||||
|
data_type => "varchar",
|
||||||
|
size => 255,
|
||||||
|
is_nullable => 0,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
__PACKAGE__->set_primary_key("id");
|
||||||
|
|
||||||
|
__PACKAGE__->might_have(
|
||||||
|
"customer",
|
||||||
|
"Pear::LocalLoop::Schema::Result::Customer" => "entity_id",
|
||||||
|
);
|
||||||
|
|
||||||
|
__PACKAGE__->might_have(
|
||||||
|
"organisation",
|
||||||
|
"Pear::LocalLoop::Schema::Result::Organisation" => "entity_id",
|
||||||
|
);
|
||||||
|
|
||||||
|
__PACKAGE__->might_have(
|
||||||
|
"user",
|
||||||
|
"Pear::LocalLoop::Schema::Result::User" => "entity_id",
|
||||||
|
);
|
||||||
|
|
||||||
|
__PACKAGE__->has_many(
|
||||||
|
"purchases",
|
||||||
|
"Pear::LocalLoop::Schema::Result::Transaction",
|
||||||
|
{ "foreign.buyer_id" => "self.id" },
|
||||||
|
{ cascade_copy => 0, cascade_delete => 0 },
|
||||||
|
);
|
||||||
|
|
||||||
|
__PACKAGE__->has_many(
|
||||||
|
"sales",
|
||||||
|
"Pear::LocalLoop::Schema::Result::Transaction",
|
||||||
|
{ "foreign.seller_id" => "self.id" },
|
||||||
|
{ cascade_copy => 0, cascade_delete => 0 },
|
||||||
|
);
|
||||||
|
|
||||||
|
sub name {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
if ( $self->type eq 'customer' ) {
|
||||||
|
return $self->customer->display_name;
|
||||||
|
} elsif ( $self->type eq 'organisation' ) {
|
||||||
|
return $self->organisation->name;
|
||||||
|
} else {
|
||||||
|
return "Unknown Name";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
|
@ -14,7 +14,11 @@ __PACKAGE__->load_components(qw/
|
||||||
|
|
||||||
__PACKAGE__->add_columns(
|
__PACKAGE__->add_columns(
|
||||||
"id",
|
"id",
|
||||||
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
|
{
|
||||||
|
data_type => "integer",
|
||||||
|
is_auto_increment => 1,
|
||||||
|
is_nullable => 0
|
||||||
|
},
|
||||||
"user_id" => {
|
"user_id" => {
|
||||||
data_type => "integer",
|
data_type => "integer",
|
||||||
is_foreign_key => 1,
|
is_foreign_key => 1,
|
||||||
|
|
|
@ -67,8 +67,8 @@ sub create_new {
|
||||||
|
|
||||||
sub _get_customer_rs {
|
sub _get_customer_rs {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return $self->result_source->schema->resultset('User')->search({
|
return $self->result_source->schema->resultset('Entity')->search({
|
||||||
organisation_id => undef,
|
type => 'customer',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ sub _set_position_and_trend {
|
||||||
my $previous_value;
|
my $previous_value;
|
||||||
|
|
||||||
if ( defined $previous_board ) {
|
if ( defined $previous_board ) {
|
||||||
$previous_value = $previous_board->find({ user_id => $lb_val->{user_id} });
|
$previous_value = $previous_board->find({ entity_id => $lb_val->{entity_id} });
|
||||||
}
|
}
|
||||||
|
|
||||||
my $trend;
|
my $trend;
|
||||||
|
@ -122,12 +122,12 @@ sub _create_total_set {
|
||||||
my @leaderboard;
|
my @leaderboard;
|
||||||
|
|
||||||
while ( my $user_result = $user_rs->next ) {
|
while ( my $user_result = $user_rs->next ) {
|
||||||
my $transaction_rs = $user_result->transactions->search_between( $start, $end );
|
my $transaction_rs = $user_result->purchases->search_between( $start, $end );
|
||||||
|
|
||||||
my $transaction_sum = $transaction_rs->get_column('value')->sum;
|
my $transaction_sum = $transaction_rs->get_column('value')->sum;
|
||||||
|
|
||||||
push @leaderboard, {
|
push @leaderboard, {
|
||||||
user_id => $user_result->id,
|
entity_id => $user_result->id,
|
||||||
value => $transaction_sum || 0,
|
value => $transaction_sum || 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -153,12 +153,12 @@ sub _create_count_set {
|
||||||
my @leaderboard;
|
my @leaderboard;
|
||||||
|
|
||||||
while ( my $user_result = $user_rs->next ) {
|
while ( my $user_result = $user_rs->next ) {
|
||||||
my $transaction_rs = $user_result->transactions->search_between( $start, $end );
|
my $transaction_rs = $user_result->purchases->search_between( $start, $end );
|
||||||
|
|
||||||
my $transaction_count = $transaction_rs->count;
|
my $transaction_count = $transaction_rs->count;
|
||||||
|
|
||||||
push @leaderboard, {
|
push @leaderboard, {
|
||||||
user_id => $user_result->id,
|
entity_id => $user_result->id,
|
||||||
value => $transaction_count || 0,
|
value => $transaction_count || 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -184,12 +184,12 @@ sub _create_total_all_time {
|
||||||
my @leaderboard;
|
my @leaderboard;
|
||||||
|
|
||||||
while ( my $user_result = $user_rs->next ) {
|
while ( my $user_result = $user_rs->next ) {
|
||||||
my $transaction_rs = $user_result->transactions->search_before( $end );
|
my $transaction_rs = $user_result->purchases->search_before( $end );
|
||||||
|
|
||||||
my $transaction_sum = $transaction_rs->get_column('value')->sum;
|
my $transaction_sum = $transaction_rs->get_column('value')->sum;
|
||||||
|
|
||||||
push @leaderboard, {
|
push @leaderboard, {
|
||||||
user_id => $user_result->id,
|
entity_id => $user_result->id,
|
||||||
value => $transaction_sum || 0,
|
value => $transaction_sum || 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -215,12 +215,12 @@ sub _create_count_all_time {
|
||||||
my @leaderboard;
|
my @leaderboard;
|
||||||
|
|
||||||
while ( my $user_result = $user_rs->next ) {
|
while ( my $user_result = $user_rs->next ) {
|
||||||
my $transaction_rs = $user_result->transactions->search_before( $end );
|
my $transaction_rs = $user_result->purchases->search_before( $end );
|
||||||
|
|
||||||
my $transaction_count = $transaction_rs->count;
|
my $transaction_count = $transaction_rs->count;
|
||||||
|
|
||||||
push @leaderboard, {
|
push @leaderboard, {
|
||||||
user_id => $user_result->id,
|
entity_id => $user_result->id,
|
||||||
value => $transaction_count || 0,
|
value => $transaction_count || 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ __PACKAGE__->add_columns(
|
||||||
is_auto_increment => 1,
|
is_auto_increment => 1,
|
||||||
is_nullable => 0,
|
is_nullable => 0,
|
||||||
},
|
},
|
||||||
"user_id" => {
|
"entity_id" => {
|
||||||
data_type => "integer",
|
data_type => "integer",
|
||||||
is_foreign_key => 1,
|
is_foreign_key => 1,
|
||||||
is_nullable => 0,
|
is_nullable => 0,
|
||||||
|
@ -40,7 +40,7 @@ __PACKAGE__->add_columns(
|
||||||
|
|
||||||
__PACKAGE__->set_primary_key("id");
|
__PACKAGE__->set_primary_key("id");
|
||||||
|
|
||||||
__PACKAGE__->add_unique_constraint([qw/ user_id set_id /]);
|
__PACKAGE__->add_unique_constraint([qw/ entity_id set_id /]);
|
||||||
|
|
||||||
__PACKAGE__->belongs_to(
|
__PACKAGE__->belongs_to(
|
||||||
"set",
|
"set",
|
||||||
|
@ -55,9 +55,9 @@ __PACKAGE__->belongs_to(
|
||||||
);
|
);
|
||||||
|
|
||||||
__PACKAGE__->belongs_to(
|
__PACKAGE__->belongs_to(
|
||||||
"user",
|
"entity",
|
||||||
"Pear::LocalLoop::Schema::Result::User",
|
"Pear::LocalLoop::Schema::Result::Entity",
|
||||||
{ "foreign.id" => "self.user_id" },
|
{ "foreign.id" => "self.entity_id" },
|
||||||
{
|
{
|
||||||
is_deferrable => 0,
|
is_deferrable => 0,
|
||||||
join_type => "LEFT",
|
join_type => "LEFT",
|
||||||
|
|
|
@ -15,6 +15,11 @@ __PACKAGE__->add_columns(
|
||||||
is_auto_increment => 1,
|
is_auto_increment => 1,
|
||||||
is_nullable => 0,
|
is_nullable => 0,
|
||||||
},
|
},
|
||||||
|
entity_id => {
|
||||||
|
data_type => 'integer',
|
||||||
|
is_nullable => 0,
|
||||||
|
is_foreign_key => 1,
|
||||||
|
},
|
||||||
name => {
|
name => {
|
||||||
data_type => 'varchar',
|
data_type => 'varchar',
|
||||||
size => 255,
|
size => 255,
|
||||||
|
@ -34,27 +39,33 @@ __PACKAGE__->add_columns(
|
||||||
size => 16,
|
size => 16,
|
||||||
is_nullable => 1,
|
is_nullable => 1,
|
||||||
},
|
},
|
||||||
|
country => {
|
||||||
|
data_type => 'varchar',
|
||||||
|
size => 255,
|
||||||
|
is_nullable => 1,
|
||||||
|
},
|
||||||
sector => {
|
sector => {
|
||||||
data_type => "varchar",
|
data_type => 'varchar',
|
||||||
size => 1,
|
size => 1,
|
||||||
is_nullable => 1,
|
is_nullable => 1,
|
||||||
},
|
},
|
||||||
|
pending => {
|
||||||
|
data_type => 'boolean',
|
||||||
|
default_value => \"0",
|
||||||
|
is_nullable => 0,
|
||||||
|
},
|
||||||
|
submitted_by_id => {
|
||||||
|
data_type => 'integer',
|
||||||
|
is_nullable => 1,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
__PACKAGE__->set_primary_key('id');
|
__PACKAGE__->set_primary_key('id');
|
||||||
|
|
||||||
__PACKAGE__->has_many(
|
__PACKAGE__->belongs_to(
|
||||||
"transactions",
|
"entity",
|
||||||
"Pear::LocalLoop::Schema::Result::Transaction",
|
"Pear::LocalLoop::Schema::Result::Entity",
|
||||||
{ "foreign.seller_id" => 'self.id' },
|
"entity_id",
|
||||||
{ cascade_copy => 0, cascade_delete => 0 },
|
|
||||||
);
|
|
||||||
|
|
||||||
__PACKAGE__->might_have(
|
|
||||||
"user",
|
|
||||||
"Pear::LocalLoop::Schema::Result::User",
|
|
||||||
{ "foreign.organisation_id" => 'self.id' },
|
|
||||||
{ cascade_copy => 0, cascade_delete => 0 },
|
|
||||||
);
|
);
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -1,70 +0,0 @@
|
||||||
package Pear::LocalLoop::Schema::Result::PendingOrganisation;
|
|
||||||
|
|
||||||
use strict;
|
|
||||||
use warnings;
|
|
||||||
|
|
||||||
use base 'DBIx::Class::Core';
|
|
||||||
|
|
||||||
__PACKAGE__->load_components( qw/
|
|
||||||
InflateColumn::DateTime
|
|
||||||
TimeStamp
|
|
||||||
/);
|
|
||||||
|
|
||||||
__PACKAGE__->table("pending_organisations");
|
|
||||||
|
|
||||||
__PACKAGE__->add_columns(
|
|
||||||
id => {
|
|
||||||
data_type => 'integer',
|
|
||||||
is_auto_increment => 1,
|
|
||||||
is_nullable => 0,
|
|
||||||
},
|
|
||||||
name => {
|
|
||||||
data_type => 'varchar',
|
|
||||||
size => 255,
|
|
||||||
is_nullable => 0,
|
|
||||||
},
|
|
||||||
street_name => {
|
|
||||||
data_type => 'text',
|
|
||||||
is_nullable => 1,
|
|
||||||
},
|
|
||||||
town => {
|
|
||||||
data_type => 'varchar',
|
|
||||||
size => 255,
|
|
||||||
is_nullable => 0,
|
|
||||||
},
|
|
||||||
postcode => {
|
|
||||||
data_type => 'varchar',
|
|
||||||
size => 16,
|
|
||||||
is_nullable => 1,
|
|
||||||
},
|
|
||||||
submitted_by_id => {
|
|
||||||
data_type => "integer",
|
|
||||||
is_foreign_key => 1,
|
|
||||||
is_nullable => 0,
|
|
||||||
},
|
|
||||||
submitted_at => {
|
|
||||||
data_type => "datetime",
|
|
||||||
is_nullable => 0,
|
|
||||||
set_on_create => 1,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
__PACKAGE__->set_primary_key('id');
|
|
||||||
|
|
||||||
__PACKAGE__->has_many(
|
|
||||||
"transactions",
|
|
||||||
"Pear::LocalLoop::Schema::Result::PendingTransaction",
|
|
||||||
{
|
|
||||||
"foreign.seller_id" => "self.id",
|
|
||||||
},
|
|
||||||
{ cascade_copy => 0, cascade_delete => 1 },
|
|
||||||
);
|
|
||||||
|
|
||||||
__PACKAGE__->belongs_to(
|
|
||||||
"submitted_by",
|
|
||||||
"Pear::LocalLoop::Schema::Result::User",
|
|
||||||
{ id => "submitted_by_id" },
|
|
||||||
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
|
|
||||||
);
|
|
||||||
|
|
||||||
1;
|
|
|
@ -1,69 +0,0 @@
|
||||||
package Pear::LocalLoop::Schema::Result::PendingTransaction;
|
|
||||||
|
|
||||||
use strict;
|
|
||||||
use warnings;
|
|
||||||
|
|
||||||
use base 'DBIx::Class::Core';
|
|
||||||
|
|
||||||
__PACKAGE__->load_components( qw/
|
|
||||||
InflateColumn::DateTime
|
|
||||||
TimeStamp
|
|
||||||
/);
|
|
||||||
|
|
||||||
__PACKAGE__->table("pending_transactions");
|
|
||||||
|
|
||||||
__PACKAGE__->add_columns(
|
|
||||||
"id" => {
|
|
||||||
data_type => "integer",
|
|
||||||
is_auto_increment => 1,
|
|
||||||
is_nullable => 0,
|
|
||||||
},
|
|
||||||
"buyer_id" => {
|
|
||||||
data_type => "integer",
|
|
||||||
is_foreign_key => 1,
|
|
||||||
is_nullable => 0,
|
|
||||||
},
|
|
||||||
"seller_id" => {
|
|
||||||
data_type => "integer",
|
|
||||||
is_foreign_key => 1,
|
|
||||||
is_nullable => 0,
|
|
||||||
},
|
|
||||||
"value" => {
|
|
||||||
data_type => "decimal",
|
|
||||||
size => [ 16, 2 ],
|
|
||||||
is_nullable => 0,
|
|
||||||
},
|
|
||||||
"proof_image" => {
|
|
||||||
data_type => "text",
|
|
||||||
is_nullable => 0,
|
|
||||||
},
|
|
||||||
"submitted_at" => {
|
|
||||||
data_type => "datetime",
|
|
||||||
is_nullable => 0,
|
|
||||||
set_on_create => 1,
|
|
||||||
},
|
|
||||||
"purchase_time" => {
|
|
||||||
data_type => "datetime",
|
|
||||||
timezone => "UTC",
|
|
||||||
is_nullable => 0,
|
|
||||||
set_on_create => 1,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
__PACKAGE__->set_primary_key("id");
|
|
||||||
|
|
||||||
__PACKAGE__->belongs_to(
|
|
||||||
"buyer",
|
|
||||||
"Pear::LocalLoop::Schema::Result::User",
|
|
||||||
{ id => "buyer_id" },
|
|
||||||
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
|
|
||||||
);
|
|
||||||
|
|
||||||
__PACKAGE__->belongs_to(
|
|
||||||
"seller",
|
|
||||||
"Pear::LocalLoop::Schema::Result::PendingOrganisation",
|
|
||||||
{ id => "seller_id" },
|
|
||||||
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
|
|
||||||
);
|
|
||||||
|
|
||||||
1;
|
|
|
@ -35,7 +35,7 @@ __PACKAGE__->add_columns(
|
||||||
},
|
},
|
||||||
"proof_image" => {
|
"proof_image" => {
|
||||||
data_type => "text",
|
data_type => "text",
|
||||||
is_nullable => 0,
|
is_nullable => 1,
|
||||||
},
|
},
|
||||||
"submitted_at" => {
|
"submitted_at" => {
|
||||||
data_type => "datetime",
|
data_type => "datetime",
|
||||||
|
@ -54,14 +54,14 @@ __PACKAGE__->set_primary_key("id");
|
||||||
|
|
||||||
__PACKAGE__->belongs_to(
|
__PACKAGE__->belongs_to(
|
||||||
"buyer",
|
"buyer",
|
||||||
"Pear::LocalLoop::Schema::Result::User",
|
"Pear::LocalLoop::Schema::Result::Entity",
|
||||||
{ id => "buyer_id" },
|
{ id => "buyer_id" },
|
||||||
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
|
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
|
||||||
);
|
);
|
||||||
|
|
||||||
__PACKAGE__->belongs_to(
|
__PACKAGE__->belongs_to(
|
||||||
"seller",
|
"seller",
|
||||||
"Pear::LocalLoop::Schema::Result::Organisation",
|
"Pear::LocalLoop::Schema::Result::Entity",
|
||||||
{ id => "seller_id" },
|
{ id => "seller_id" },
|
||||||
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
|
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
|
||||||
);
|
);
|
||||||
|
|
|
@ -21,15 +21,10 @@ __PACKAGE__->add_columns(
|
||||||
is_auto_increment => 1,
|
is_auto_increment => 1,
|
||||||
is_nullable => 0,
|
is_nullable => 0,
|
||||||
},
|
},
|
||||||
"customer_id" => {
|
"entity_id" => {
|
||||||
data_type => "integer",
|
data_type => "integer",
|
||||||
is_foreign_key => 1,
|
is_foreign_key => 1,
|
||||||
is_nullable => 1,
|
is_nullable => 0,
|
||||||
},
|
|
||||||
"organisation_id" => {
|
|
||||||
data_type => "integer",
|
|
||||||
is_foreign_key => 1,
|
|
||||||
is_nullable => 1,
|
|
||||||
},
|
},
|
||||||
"email" => {
|
"email" => {
|
||||||
data_type => "text",
|
data_type => "text",
|
||||||
|
@ -51,59 +46,21 @@ __PACKAGE__->add_columns(
|
||||||
},
|
},
|
||||||
passphrase_check_method => 'check_password',
|
passphrase_check_method => 'check_password',
|
||||||
},
|
},
|
||||||
|
"is_admin" => {
|
||||||
|
data_type => "boolean",
|
||||||
|
default_value => \"0",
|
||||||
|
is_nullable => 0,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
__PACKAGE__->set_primary_key("id");
|
__PACKAGE__->set_primary_key("id");
|
||||||
|
|
||||||
__PACKAGE__->add_unique_constraint(["customer_id"]);
|
|
||||||
|
|
||||||
__PACKAGE__->add_unique_constraint(["email"]);
|
__PACKAGE__->add_unique_constraint(["email"]);
|
||||||
|
|
||||||
__PACKAGE__->add_unique_constraint(["organisation_id"]);
|
|
||||||
|
|
||||||
__PACKAGE__->might_have(
|
|
||||||
"administrator",
|
|
||||||
"Pear::LocalLoop::Schema::Result::Administrator",
|
|
||||||
{ "foreign.user_id" => "self.id" },
|
|
||||||
{ cascade_copy => 0, cascade_delete => 0 },
|
|
||||||
);
|
|
||||||
|
|
||||||
__PACKAGE__->belongs_to(
|
__PACKAGE__->belongs_to(
|
||||||
"customer",
|
"entity",
|
||||||
"Pear::LocalLoop::Schema::Result::Customer",
|
"Pear::LocalLoop::Schema::Result::Entity",
|
||||||
{ "foreign.id" => "self.customer_id" },
|
"entity_id",
|
||||||
{
|
|
||||||
is_deferrable => 0,
|
|
||||||
join_type => "LEFT",
|
|
||||||
on_delete => "NO ACTION",
|
|
||||||
on_update => "NO ACTION",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
__PACKAGE__->belongs_to(
|
|
||||||
"organisation",
|
|
||||||
"Pear::LocalLoop::Schema::Result::Organisation",
|
|
||||||
{ "foreign.id" => "self.organisation_id" },
|
|
||||||
{
|
|
||||||
is_deferrable => 0,
|
|
||||||
join_type => "LEFT",
|
|
||||||
on_delete => "NO ACTION",
|
|
||||||
on_update => "NO ACTION",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
__PACKAGE__->has_many(
|
|
||||||
"pending_organisations",
|
|
||||||
"Pear::LocalLoop::Schema::Result::PendingOrganisation",
|
|
||||||
{ "foreign.submitted_by_id" => "self.id" },
|
|
||||||
{ cascade_copy => 0, cascade_delete => 0 },
|
|
||||||
);
|
|
||||||
|
|
||||||
__PACKAGE__->has_many(
|
|
||||||
"pending_transactions",
|
|
||||||
"Pear::LocalLoop::Schema::Result::PendingTransaction",
|
|
||||||
{ "foreign.buyer_id" => "self.id" },
|
|
||||||
{ cascade_copy => 0, cascade_delete => 0 },
|
|
||||||
);
|
);
|
||||||
|
|
||||||
__PACKAGE__->has_many(
|
__PACKAGE__->has_many(
|
||||||
|
@ -113,13 +70,6 @@ __PACKAGE__->has_many(
|
||||||
{ cascade_copy => 0, cascade_delete => 0 },
|
{ cascade_copy => 0, cascade_delete => 0 },
|
||||||
);
|
);
|
||||||
|
|
||||||
__PACKAGE__->has_many(
|
|
||||||
"transactions",
|
|
||||||
"Pear::LocalLoop::Schema::Result::Transaction",
|
|
||||||
{ "foreign.buyer_id" => "self.id" },
|
|
||||||
{ cascade_copy => 0, cascade_delete => 0 },
|
|
||||||
);
|
|
||||||
|
|
||||||
__PACKAGE__->has_many(
|
__PACKAGE__->has_many(
|
||||||
"feedback",
|
"feedback",
|
||||||
"Pear::LocalLoop::Schema::Result::Feedback",
|
"Pear::LocalLoop::Schema::Result::Feedback",
|
||||||
|
@ -144,22 +94,20 @@ sub generate_session {
|
||||||
sub name {
|
sub name {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
if ( defined $self->customer_id ) {
|
if ( defined $self->entity->customer ) {
|
||||||
return $self->customer->display_name;
|
return $self->entity->customer->display_name;
|
||||||
} elsif ( defined $self->organisation_id ) {
|
} elsif ( defined $self->entity->organisation ) {
|
||||||
return $self->organisation->name;
|
return $self->entity->organisation->name;
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# TODO Deprecate this sub?
|
||||||
sub type {
|
sub type {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
if ( defined $self->customer_id ) {
|
return $self->entity->type;
|
||||||
return "customer";
|
|
||||||
}
|
|
||||||
return "organisation";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
19
lib/Pear/LocalLoop/Schema/ResultSet/Entity.pm
Normal file
19
lib/Pear/LocalLoop/Schema/ResultSet/Entity.pm
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
package Pear::LocalLoop::Schema::ResultSet::Entity;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use base 'DBIx::Class::ResultSet';
|
||||||
|
|
||||||
|
sub sales { shift->search_related('sales', @_) }
|
||||||
|
|
||||||
|
sub create_org {
|
||||||
|
my ( $self, $org ) = @_;
|
||||||
|
|
||||||
|
return $self->create({
|
||||||
|
organisation => $org,
|
||||||
|
type => 'organisation',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
10
lib/Pear/LocalLoop/Schema/ResultSet/Organisation.pm
Normal file
10
lib/Pear/LocalLoop/Schema/ResultSet/Organisation.pm
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package Pear::LocalLoop::Schema::ResultSet::Organisation;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use base 'DBIx::Class::ResultSet';
|
||||||
|
|
||||||
|
sub entity { shift->search_related('entity', @_) }
|
||||||
|
|
||||||
|
1;
|
36
script/schema/graph.pl
Executable file
36
script/schema/graph.pl
Executable file
|
@ -0,0 +1,36 @@
|
||||||
|
#! /usr/bin/env perl
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use feature "say";
|
||||||
|
|
||||||
|
use FindBin qw/ $Bin /;
|
||||||
|
use lib "$Bin/../../lib";
|
||||||
|
|
||||||
|
use SQL::Translator;
|
||||||
|
use Pear::LocalLoop::Schema;
|
||||||
|
|
||||||
|
say "Setting up Translator and Schema";
|
||||||
|
|
||||||
|
my $schema = Pear::LocalLoop::Schema->connect;
|
||||||
|
my $tr = SQL::Translator->new(
|
||||||
|
from => "SQL::Translator::Parser::DBIx::Class",
|
||||||
|
to => 'GraphViz',
|
||||||
|
debug => 1,
|
||||||
|
trace => 1,
|
||||||
|
producer_args => {
|
||||||
|
out_file => "$Bin/../../schema.png",
|
||||||
|
output_type => 'png',
|
||||||
|
width => 0,
|
||||||
|
height => 0,
|
||||||
|
show_constraints => 1,
|
||||||
|
show_datatypes => 1,
|
||||||
|
show_sizes => 1,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
say "Translating Schema to image";
|
||||||
|
|
||||||
|
$tr->translate( data => $schema );
|
||||||
|
|
||||||
|
say "Finished";
|
18
share/ddl/PostgreSQL/deploy/6/001-auto-__VERSION.sql
Normal file
18
share/ddl/PostgreSQL/deploy/6/001-auto-__VERSION.sql
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
--
|
||||||
|
-- Created by SQL::Translator::Producer::PostgreSQL
|
||||||
|
-- Created on Fri Sep 1 15:14:28 2017
|
||||||
|
--
|
||||||
|
;
|
||||||
|
--
|
||||||
|
-- Table: dbix_class_deploymenthandler_versions
|
||||||
|
--
|
||||||
|
CREATE TABLE "dbix_class_deploymenthandler_versions" (
|
||||||
|
"id" serial NOT NULL,
|
||||||
|
"version" character varying(50) NOT NULL,
|
||||||
|
"ddl" text,
|
||||||
|
"upgrade_sql" text,
|
||||||
|
PRIMARY KEY ("id"),
|
||||||
|
CONSTRAINT "dbix_class_deploymenthandler_versions_version" UNIQUE ("version")
|
||||||
|
);
|
||||||
|
|
||||||
|
;
|
210
share/ddl/PostgreSQL/deploy/6/001-auto.sql
Normal file
210
share/ddl/PostgreSQL/deploy/6/001-auto.sql
Normal file
|
@ -0,0 +1,210 @@
|
||||||
|
--
|
||||||
|
-- Created by SQL::Translator::Producer::PostgreSQL
|
||||||
|
-- Created on Fri Sep 1 15:14:28 2017
|
||||||
|
--
|
||||||
|
;
|
||||||
|
--
|
||||||
|
-- Table: account_tokens
|
||||||
|
--
|
||||||
|
CREATE TABLE "account_tokens" (
|
||||||
|
"id" serial NOT NULL,
|
||||||
|
"name" text NOT NULL,
|
||||||
|
"used" integer DEFAULT 0 NOT NULL,
|
||||||
|
PRIMARY KEY ("id"),
|
||||||
|
CONSTRAINT "account_tokens_name" UNIQUE ("name")
|
||||||
|
);
|
||||||
|
|
||||||
|
;
|
||||||
|
--
|
||||||
|
-- Table: entities
|
||||||
|
--
|
||||||
|
CREATE TABLE "entities" (
|
||||||
|
"id" serial NOT NULL,
|
||||||
|
"type" character varying(255) NOT NULL,
|
||||||
|
PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
;
|
||||||
|
--
|
||||||
|
-- Table: leaderboards
|
||||||
|
--
|
||||||
|
CREATE TABLE "leaderboards" (
|
||||||
|
"id" serial NOT NULL,
|
||||||
|
"name" character varying(255) NOT NULL,
|
||||||
|
"type" character varying(255) NOT NULL,
|
||||||
|
PRIMARY KEY ("id"),
|
||||||
|
CONSTRAINT "leaderboards_type" UNIQUE ("type")
|
||||||
|
);
|
||||||
|
|
||||||
|
;
|
||||||
|
--
|
||||||
|
-- Table: customers
|
||||||
|
--
|
||||||
|
CREATE TABLE "customers" (
|
||||||
|
"id" serial NOT NULL,
|
||||||
|
"entity_id" integer NOT NULL,
|
||||||
|
"display_name" character varying(255) NOT NULL,
|
||||||
|
"full_name" character varying(255) NOT NULL,
|
||||||
|
"year_of_birth" integer NOT NULL,
|
||||||
|
"postcode" character varying(16) NOT NULL,
|
||||||
|
PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
CREATE INDEX "customers_idx_entity_id" on "customers" ("entity_id");
|
||||||
|
|
||||||
|
;
|
||||||
|
--
|
||||||
|
-- Table: leaderboard_sets
|
||||||
|
--
|
||||||
|
CREATE TABLE "leaderboard_sets" (
|
||||||
|
"id" serial NOT NULL,
|
||||||
|
"leaderboard_id" integer NOT NULL,
|
||||||
|
"date" timestamp NOT NULL,
|
||||||
|
PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
CREATE INDEX "leaderboard_sets_idx_leaderboard_id" on "leaderboard_sets" ("leaderboard_id");
|
||||||
|
|
||||||
|
;
|
||||||
|
--
|
||||||
|
-- Table: organisations
|
||||||
|
--
|
||||||
|
CREATE TABLE "organisations" (
|
||||||
|
"id" serial NOT NULL,
|
||||||
|
"entity_id" integer NOT NULL,
|
||||||
|
"name" character varying(255) NOT NULL,
|
||||||
|
"street_name" text,
|
||||||
|
"town" character varying(255) NOT NULL,
|
||||||
|
"postcode" character varying(16),
|
||||||
|
"country" character varying(255),
|
||||||
|
"sector" character varying(1),
|
||||||
|
"pending" boolean DEFAULT 0 NOT NULL,
|
||||||
|
"submitted_by_id" integer,
|
||||||
|
PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
CREATE INDEX "organisations_idx_entity_id" on "organisations" ("entity_id");
|
||||||
|
|
||||||
|
;
|
||||||
|
--
|
||||||
|
-- Table: transactions
|
||||||
|
--
|
||||||
|
CREATE TABLE "transactions" (
|
||||||
|
"id" serial NOT NULL,
|
||||||
|
"buyer_id" integer NOT NULL,
|
||||||
|
"seller_id" integer NOT NULL,
|
||||||
|
"value" numeric(16,2) NOT NULL,
|
||||||
|
"proof_image" text,
|
||||||
|
"submitted_at" timestamp NOT NULL,
|
||||||
|
"purchase_time" timestamp NOT NULL,
|
||||||
|
PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
CREATE INDEX "transactions_idx_buyer_id" on "transactions" ("buyer_id");
|
||||||
|
CREATE INDEX "transactions_idx_seller_id" on "transactions" ("seller_id");
|
||||||
|
|
||||||
|
;
|
||||||
|
--
|
||||||
|
-- Table: users
|
||||||
|
--
|
||||||
|
CREATE TABLE "users" (
|
||||||
|
"id" serial NOT NULL,
|
||||||
|
"entity_id" integer NOT NULL,
|
||||||
|
"email" text NOT NULL,
|
||||||
|
"join_date" timestamp NOT NULL,
|
||||||
|
"password" character varying(100) NOT NULL,
|
||||||
|
"is_admin" boolean DEFAULT 0 NOT NULL,
|
||||||
|
PRIMARY KEY ("id"),
|
||||||
|
CONSTRAINT "users_email" UNIQUE ("email")
|
||||||
|
);
|
||||||
|
CREATE INDEX "users_idx_entity_id" on "users" ("entity_id");
|
||||||
|
|
||||||
|
;
|
||||||
|
--
|
||||||
|
-- Table: feedback
|
||||||
|
--
|
||||||
|
CREATE TABLE "feedback" (
|
||||||
|
"id" serial NOT NULL,
|
||||||
|
"user_id" integer NOT NULL,
|
||||||
|
"submitted_at" timestamp NOT NULL,
|
||||||
|
"feedbacktext" text NOT NULL,
|
||||||
|
"app_name" character varying(255) NOT NULL,
|
||||||
|
"package_name" character varying(255) NOT NULL,
|
||||||
|
"version_code" character varying(255) NOT NULL,
|
||||||
|
"version_number" character varying(255) NOT NULL,
|
||||||
|
PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
CREATE INDEX "feedback_idx_user_id" on "feedback" ("user_id");
|
||||||
|
|
||||||
|
;
|
||||||
|
--
|
||||||
|
-- Table: session_tokens
|
||||||
|
--
|
||||||
|
CREATE TABLE "session_tokens" (
|
||||||
|
"id" serial NOT NULL,
|
||||||
|
"token" character varying(255) NOT NULL,
|
||||||
|
"user_id" integer NOT NULL,
|
||||||
|
PRIMARY KEY ("id"),
|
||||||
|
CONSTRAINT "session_tokens_token" UNIQUE ("token")
|
||||||
|
);
|
||||||
|
CREATE INDEX "session_tokens_idx_user_id" on "session_tokens" ("user_id");
|
||||||
|
|
||||||
|
;
|
||||||
|
--
|
||||||
|
-- Table: leaderboard_values
|
||||||
|
--
|
||||||
|
CREATE TABLE "leaderboard_values" (
|
||||||
|
"id" serial NOT NULL,
|
||||||
|
"entity_id" integer NOT NULL,
|
||||||
|
"set_id" integer NOT NULL,
|
||||||
|
"position" integer NOT NULL,
|
||||||
|
"value" numeric(16,2) NOT NULL,
|
||||||
|
"trend" integer DEFAULT 0 NOT NULL,
|
||||||
|
PRIMARY KEY ("id"),
|
||||||
|
CONSTRAINT "leaderboard_values_entity_id_set_id" UNIQUE ("entity_id", "set_id")
|
||||||
|
);
|
||||||
|
CREATE INDEX "leaderboard_values_idx_entity_id" on "leaderboard_values" ("entity_id");
|
||||||
|
CREATE INDEX "leaderboard_values_idx_set_id" on "leaderboard_values" ("set_id");
|
||||||
|
|
||||||
|
;
|
||||||
|
--
|
||||||
|
-- Foreign Key Definitions
|
||||||
|
--
|
||||||
|
|
||||||
|
;
|
||||||
|
ALTER TABLE "customers" ADD CONSTRAINT "customers_fk_entity_id" FOREIGN KEY ("entity_id")
|
||||||
|
REFERENCES "entities" ("id") ON DELETE CASCADE DEFERRABLE;
|
||||||
|
|
||||||
|
;
|
||||||
|
ALTER TABLE "leaderboard_sets" ADD CONSTRAINT "leaderboard_sets_fk_leaderboard_id" FOREIGN KEY ("leaderboard_id")
|
||||||
|
REFERENCES "leaderboards" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||||
|
|
||||||
|
;
|
||||||
|
ALTER TABLE "organisations" ADD CONSTRAINT "organisations_fk_entity_id" FOREIGN KEY ("entity_id")
|
||||||
|
REFERENCES "entities" ("id") ON DELETE CASCADE DEFERRABLE;
|
||||||
|
|
||||||
|
;
|
||||||
|
ALTER TABLE "transactions" ADD CONSTRAINT "transactions_fk_buyer_id" FOREIGN KEY ("buyer_id")
|
||||||
|
REFERENCES "entities" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||||
|
|
||||||
|
;
|
||||||
|
ALTER TABLE "transactions" ADD CONSTRAINT "transactions_fk_seller_id" FOREIGN KEY ("seller_id")
|
||||||
|
REFERENCES "entities" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||||
|
|
||||||
|
;
|
||||||
|
ALTER TABLE "users" ADD CONSTRAINT "users_fk_entity_id" FOREIGN KEY ("entity_id")
|
||||||
|
REFERENCES "entities" ("id") ON DELETE CASCADE DEFERRABLE;
|
||||||
|
|
||||||
|
;
|
||||||
|
ALTER TABLE "feedback" ADD CONSTRAINT "feedback_fk_user_id" FOREIGN KEY ("user_id")
|
||||||
|
REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||||
|
|
||||||
|
;
|
||||||
|
ALTER TABLE "session_tokens" ADD CONSTRAINT "session_tokens_fk_user_id" FOREIGN KEY ("user_id")
|
||||||
|
REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||||
|
|
||||||
|
;
|
||||||
|
ALTER TABLE "leaderboard_values" ADD CONSTRAINT "leaderboard_values_fk_entity_id" FOREIGN KEY ("entity_id")
|
||||||
|
REFERENCES "entities" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||||
|
|
||||||
|
;
|
||||||
|
ALTER TABLE "leaderboard_values" ADD CONSTRAINT "leaderboard_values_fk_set_id" FOREIGN KEY ("set_id")
|
||||||
|
REFERENCES "leaderboard_sets" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||||
|
|
||||||
|
;
|
85
share/ddl/PostgreSQL/upgrade/5-6/001-auto.sql
Normal file
85
share/ddl/PostgreSQL/upgrade/5-6/001-auto.sql
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
-- Convert schema 'share/ddl/_source/deploy/5/001-auto.yml' to 'share/ddl/_source/deploy/6/001-auto.yml':;
|
||||||
|
-- Customised for proper migration
|
||||||
|
|
||||||
|
BEGIN;
|
||||||
|
|
||||||
|
CREATE TABLE "entities" (
|
||||||
|
"id" serial NOT NULL,
|
||||||
|
"type" character varying(255) NOT NULL,
|
||||||
|
PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
ALTER TABLE customers RENAME TO customers_temp;
|
||||||
|
ALTER TABLE organisations RENAME TO organisations_temp;
|
||||||
|
ALTER TABLE transactions RENAME TO transactions_temp;
|
||||||
|
ALTER TABLE users RENAME TO users_temp;
|
||||||
|
|
||||||
|
CREATE TABLE "customers" (
|
||||||
|
"id" serial NOT NULL,
|
||||||
|
"entity_id" integer NOT NULL,
|
||||||
|
"display_name" character varying(255) NOT NULL,
|
||||||
|
"full_name" character varying(255) NOT NULL,
|
||||||
|
"year_of_birth" integer NOT NULL,
|
||||||
|
"postcode" character varying(16) NOT NULL,
|
||||||
|
PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
CREATE INDEX "customers_idx_entity_id" on "customers" ("entity_id");
|
||||||
|
|
||||||
|
CREATE TABLE "organisations" (
|
||||||
|
"id" serial NOT NULL,
|
||||||
|
"entity_id" integer NOT NULL,
|
||||||
|
"name" character varying(255) NOT NULL,
|
||||||
|
"street_name" text,
|
||||||
|
"town" character varying(255) NOT NULL,
|
||||||
|
"postcode" character varying(16),
|
||||||
|
"country" character varying(255),
|
||||||
|
"sector" character varying(1),
|
||||||
|
"pending" boolean DEFAULT 0 NOT NULL,
|
||||||
|
"submitted_by_id" integer,
|
||||||
|
PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
CREATE INDEX "organisations_idx_entity_id" on "organisations" ("entity_id");
|
||||||
|
|
||||||
|
CREATE TABLE "transactions" (
|
||||||
|
"id" serial NOT NULL,
|
||||||
|
"buyer_id" integer NOT NULL,
|
||||||
|
"seller_id" integer NOT NULL,
|
||||||
|
"value" numeric(16,2) NOT NULL,
|
||||||
|
"proof_image" text,
|
||||||
|
"submitted_at" timestamp NOT NULL,
|
||||||
|
"purchase_time" timestamp NOT NULL,
|
||||||
|
PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
CREATE INDEX "transactions_idx_buyer_id" on "transactions" ("buyer_id");
|
||||||
|
CREATE INDEX "transactions_idx_seller_id" on "transactions" ("seller_id");
|
||||||
|
|
||||||
|
CREATE TABLE "users" (
|
||||||
|
"id" serial NOT NULL,
|
||||||
|
"entity_id" integer NOT NULL,
|
||||||
|
"email" text NOT NULL,
|
||||||
|
"join_date" timestamp NOT NULL,
|
||||||
|
"password" character varying(100) NOT NULL,
|
||||||
|
"is_admin" boolean DEFAULT 0 NOT NULL,
|
||||||
|
PRIMARY KEY ("id"),
|
||||||
|
CONSTRAINT "users_email" UNIQUE ("email")
|
||||||
|
);
|
||||||
|
CREATE INDEX "users_idx_entity_id" on "users" ("entity_id");
|
||||||
|
|
||||||
|
DROP TABLE leaderboard_values;
|
||||||
|
TRUNCATE TABLE leaderboard_sets;
|
||||||
|
|
||||||
|
CREATE TABLE "leaderboard_values" (
|
||||||
|
"id" serial NOT NULL,
|
||||||
|
"entity_id" integer NOT NULL,
|
||||||
|
"set_id" integer NOT NULL,
|
||||||
|
"position" integer NOT NULL,
|
||||||
|
"value" numeric(16,2) NOT NULL,
|
||||||
|
"trend" integer DEFAULT 0 NOT NULL,
|
||||||
|
PRIMARY KEY ("id"),
|
||||||
|
CONSTRAINT "leaderboard_values_entity_id_set_id" UNIQUE ("entity_id", "set_id")
|
||||||
|
);
|
||||||
|
CREATE INDEX "leaderboard_values_idx_entity_id" on "leaderboard_values" ("entity_id");
|
||||||
|
CREATE INDEX "leaderboard_values_idx_set_id" on "leaderboard_values" ("set_id");
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
|
13
share/ddl/PostgreSQL/upgrade/5-6/003-remove-temps.sql
Normal file
13
share/ddl/PostgreSQL/upgrade/5-6/003-remove-temps.sql
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
-- Remove temporary tables created during migration
|
||||||
|
|
||||||
|
BEGIN;
|
||||||
|
|
||||||
|
DROP TABLE customers_temp;
|
||||||
|
DROP TABLE organisations_temp;
|
||||||
|
DROP TABLE transactions_temp;
|
||||||
|
DROP TABLE users_temp;
|
||||||
|
DROP TABLE pending_organisations;
|
||||||
|
DROP TABLE pending_transactions;
|
||||||
|
DROP TABLE administrators;
|
||||||
|
|
||||||
|
COMMIT;
|
18
share/ddl/SQLite/deploy/6/001-auto-__VERSION.sql
Normal file
18
share/ddl/SQLite/deploy/6/001-auto-__VERSION.sql
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
--
|
||||||
|
-- Created by SQL::Translator::Producer::SQLite
|
||||||
|
-- Created on Fri Sep 1 15:14:28 2017
|
||||||
|
--
|
||||||
|
|
||||||
|
;
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
--
|
||||||
|
-- Table: dbix_class_deploymenthandler_versions
|
||||||
|
--
|
||||||
|
CREATE TABLE dbix_class_deploymenthandler_versions (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
version varchar(50) NOT NULL,
|
||||||
|
ddl text,
|
||||||
|
upgrade_sql text
|
||||||
|
);
|
||||||
|
CREATE UNIQUE INDEX dbix_class_deploymenthandler_versions_version ON dbix_class_deploymenthandler_versions (version);
|
||||||
|
COMMIT;
|
145
share/ddl/SQLite/deploy/6/001-auto.sql
Normal file
145
share/ddl/SQLite/deploy/6/001-auto.sql
Normal file
|
@ -0,0 +1,145 @@
|
||||||
|
--
|
||||||
|
-- Created by SQL::Translator::Producer::SQLite
|
||||||
|
-- Created on Fri Sep 1 15:14:28 2017
|
||||||
|
--
|
||||||
|
|
||||||
|
;
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
--
|
||||||
|
-- Table: account_tokens
|
||||||
|
--
|
||||||
|
CREATE TABLE account_tokens (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
name text NOT NULL,
|
||||||
|
used integer NOT NULL DEFAULT 0
|
||||||
|
);
|
||||||
|
CREATE UNIQUE INDEX account_tokens_name ON account_tokens (name);
|
||||||
|
--
|
||||||
|
-- Table: entities
|
||||||
|
--
|
||||||
|
CREATE TABLE entities (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
type varchar(255) NOT NULL
|
||||||
|
);
|
||||||
|
--
|
||||||
|
-- Table: leaderboards
|
||||||
|
--
|
||||||
|
CREATE TABLE leaderboards (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
name varchar(255) NOT NULL,
|
||||||
|
type varchar(255) NOT NULL
|
||||||
|
);
|
||||||
|
CREATE UNIQUE INDEX leaderboards_type ON leaderboards (type);
|
||||||
|
--
|
||||||
|
-- Table: customers
|
||||||
|
--
|
||||||
|
CREATE TABLE customers (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
entity_id integer NOT NULL,
|
||||||
|
display_name varchar(255) NOT NULL,
|
||||||
|
full_name varchar(255) NOT NULL,
|
||||||
|
year_of_birth integer NOT NULL,
|
||||||
|
postcode varchar(16) NOT NULL,
|
||||||
|
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
CREATE INDEX customers_idx_entity_id ON customers (entity_id);
|
||||||
|
--
|
||||||
|
-- Table: leaderboard_sets
|
||||||
|
--
|
||||||
|
CREATE TABLE leaderboard_sets (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
leaderboard_id integer NOT NULL,
|
||||||
|
date datetime NOT NULL,
|
||||||
|
FOREIGN KEY (leaderboard_id) REFERENCES leaderboards(id) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
|
);
|
||||||
|
CREATE INDEX leaderboard_sets_idx_leaderboard_id ON leaderboard_sets (leaderboard_id);
|
||||||
|
--
|
||||||
|
-- Table: organisations
|
||||||
|
--
|
||||||
|
CREATE TABLE organisations (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
entity_id integer NOT NULL,
|
||||||
|
name varchar(255) NOT NULL,
|
||||||
|
street_name text,
|
||||||
|
town varchar(255) NOT NULL,
|
||||||
|
postcode varchar(16),
|
||||||
|
country varchar(255),
|
||||||
|
sector varchar(1),
|
||||||
|
pending boolean NOT NULL DEFAULT 0,
|
||||||
|
submitted_by_id integer,
|
||||||
|
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
CREATE INDEX organisations_idx_entity_id ON organisations (entity_id);
|
||||||
|
--
|
||||||
|
-- Table: transactions
|
||||||
|
--
|
||||||
|
CREATE TABLE transactions (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
buyer_id integer NOT NULL,
|
||||||
|
seller_id integer NOT NULL,
|
||||||
|
value decimal(16,2) NOT NULL,
|
||||||
|
proof_image text,
|
||||||
|
submitted_at datetime NOT NULL,
|
||||||
|
purchase_time datetime NOT NULL,
|
||||||
|
FOREIGN KEY (buyer_id) REFERENCES entities(id) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
|
FOREIGN KEY (seller_id) REFERENCES entities(id) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
|
);
|
||||||
|
CREATE INDEX transactions_idx_buyer_id ON transactions (buyer_id);
|
||||||
|
CREATE INDEX transactions_idx_seller_id ON transactions (seller_id);
|
||||||
|
--
|
||||||
|
-- Table: users
|
||||||
|
--
|
||||||
|
CREATE TABLE users (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
entity_id integer NOT NULL,
|
||||||
|
email text NOT NULL,
|
||||||
|
join_date datetime NOT NULL,
|
||||||
|
password varchar(100) NOT NULL,
|
||||||
|
is_admin boolean NOT NULL DEFAULT 0,
|
||||||
|
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
CREATE INDEX users_idx_entity_id ON users (entity_id);
|
||||||
|
CREATE UNIQUE INDEX users_email ON users (email);
|
||||||
|
--
|
||||||
|
-- Table: feedback
|
||||||
|
--
|
||||||
|
CREATE TABLE feedback (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
user_id integer NOT NULL,
|
||||||
|
submitted_at datetime NOT NULL,
|
||||||
|
feedbacktext text NOT NULL,
|
||||||
|
app_name varchar(255) NOT NULL,
|
||||||
|
package_name varchar(255) NOT NULL,
|
||||||
|
version_code varchar(255) NOT NULL,
|
||||||
|
version_number varchar(255) NOT NULL,
|
||||||
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
|
);
|
||||||
|
CREATE INDEX feedback_idx_user_id ON feedback (user_id);
|
||||||
|
--
|
||||||
|
-- Table: session_tokens
|
||||||
|
--
|
||||||
|
CREATE TABLE session_tokens (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
token varchar(255) NOT NULL,
|
||||||
|
user_id integer NOT NULL,
|
||||||
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
|
);
|
||||||
|
CREATE INDEX session_tokens_idx_user_id ON session_tokens (user_id);
|
||||||
|
CREATE UNIQUE INDEX session_tokens_token ON session_tokens (token);
|
||||||
|
--
|
||||||
|
-- Table: leaderboard_values
|
||||||
|
--
|
||||||
|
CREATE TABLE leaderboard_values (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
entity_id integer NOT NULL,
|
||||||
|
set_id integer NOT NULL,
|
||||||
|
position integer NOT NULL,
|
||||||
|
value decimal(16,2) NOT NULL,
|
||||||
|
trend integer NOT NULL DEFAULT 0,
|
||||||
|
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
|
FOREIGN KEY (set_id) REFERENCES leaderboard_sets(id) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
|
);
|
||||||
|
CREATE INDEX leaderboard_values_idx_entity_id ON leaderboard_values (entity_id);
|
||||||
|
CREATE INDEX leaderboard_values_idx_set_id ON leaderboard_values (set_id);
|
||||||
|
CREATE UNIQUE INDEX leaderboard_values_entity_id_set_id ON leaderboard_values (entity_id, set_id);
|
||||||
|
COMMIT;
|
90
share/ddl/SQLite/upgrade/5-6/001-auto.sql
Normal file
90
share/ddl/SQLite/upgrade/5-6/001-auto.sql
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
-- Convert schema 'share/ddl/_source/deploy/5/001-auto.yml' to 'share/ddl/_source/deploy/6/001-auto.yml':;
|
||||||
|
-- Customised for proper migration
|
||||||
|
|
||||||
|
BEGIN;
|
||||||
|
|
||||||
|
CREATE TABLE entities (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
type varchar(255) NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
ALTER TABLE customers RENAME TO customers_temp;
|
||||||
|
|
||||||
|
CREATE TABLE customers (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
entity_id integer NOT NULL,
|
||||||
|
display_name varchar(255) NOT NULL,
|
||||||
|
full_name varchar(255) NOT NULL,
|
||||||
|
year_of_birth integer NOT NULL,
|
||||||
|
postcode varchar(16) NOT NULL,
|
||||||
|
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
CREATE INDEX customers_idx_entity_id ON customers (entity_id);
|
||||||
|
|
||||||
|
-- Leaderboards must be regenerated, this saves trying to do this the hard way
|
||||||
|
DROP TABLE leaderboard_values;
|
||||||
|
DELETE FROM leaderboard_sets;
|
||||||
|
|
||||||
|
CREATE TABLE leaderboard_values (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
entity_id integer NOT NULL,
|
||||||
|
set_id integer NOT NULL,
|
||||||
|
position integer NOT NULL,
|
||||||
|
value decimal(16,2) NOT NULL,
|
||||||
|
trend integer NOT NULL DEFAULT 0,
|
||||||
|
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
|
FOREIGN KEY (set_id) REFERENCES leaderboard_sets(id) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
|
);
|
||||||
|
CREATE INDEX leaderboard_values_idx_entity_id ON leaderboard_values (entity_id);
|
||||||
|
CREATE INDEX leaderboard_values_idx_set_id ON leaderboard_values (set_id);
|
||||||
|
CREATE UNIQUE INDEX leaderboard_values_entity_id_set_id ON leaderboard_values (entity_id, set_id);
|
||||||
|
|
||||||
|
ALTER TABLE organisations RENAME TO organisations_temp;
|
||||||
|
|
||||||
|
CREATE TABLE organisations (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
entity_id integer NOT NULL,
|
||||||
|
name varchar(255) NOT NULL,
|
||||||
|
street_name text,
|
||||||
|
town varchar(255) NOT NULL,
|
||||||
|
postcode varchar(16),
|
||||||
|
country varchar(255),
|
||||||
|
sector varchar(1),
|
||||||
|
pending boolean NOT NULL DEFAULT 0,
|
||||||
|
submitted_by_id integer,
|
||||||
|
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
CREATE INDEX organisations_idx_entity_id ON organisations (entity_id);
|
||||||
|
|
||||||
|
ALTER TABLE transactions RENAME TO transactions_temp;
|
||||||
|
|
||||||
|
CREATE TABLE transactions (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
buyer_id integer NOT NULL,
|
||||||
|
seller_id integer NOT NULL,
|
||||||
|
value decimal(16,2) NOT NULL,
|
||||||
|
proof_image text,
|
||||||
|
submitted_at datetime NOT NULL,
|
||||||
|
purchase_time datetime NOT NULL,
|
||||||
|
FOREIGN KEY (buyer_id) REFERENCES entities(id) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
|
FOREIGN KEY (seller_id) REFERENCES entities(id) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
|
);
|
||||||
|
CREATE INDEX transactions_idx_buyer_id02 ON transactions (buyer_id);
|
||||||
|
CREATE INDEX transactions_idx_seller_id02 ON transactions (seller_id);
|
||||||
|
|
||||||
|
ALTER TABLE users RENAME TO users_temp;
|
||||||
|
|
||||||
|
CREATE TABLE users (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
entity_id integer NOT NULL,
|
||||||
|
email text NOT NULL,
|
||||||
|
join_date datetime NOT NULL,
|
||||||
|
password varchar(100) NOT NULL,
|
||||||
|
is_admin boolean NOT NULL DEFAULT 0,
|
||||||
|
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
CREATE INDEX users_idx_entity_id02 ON users (entity_id);
|
||||||
|
CREATE UNIQUE INDEX users_email02 ON users (email);
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
|
13
share/ddl/SQLite/upgrade/5-6/003-remove-temps.sql
Normal file
13
share/ddl/SQLite/upgrade/5-6/003-remove-temps.sql
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
-- Remove temporary tables created during migration
|
||||||
|
|
||||||
|
BEGIN;
|
||||||
|
|
||||||
|
DROP TABLE customers_temp;
|
||||||
|
DROP TABLE organisations_temp;
|
||||||
|
DROP TABLE transactions_temp;
|
||||||
|
DROP TABLE users_temp;
|
||||||
|
DROP TABLE pending_organisations;
|
||||||
|
DROP TABLE pending_transactions;
|
||||||
|
DROP TABLE administrators;
|
||||||
|
|
||||||
|
COMMIT;
|
111
share/ddl/_common/upgrade/5-6/002-entity-upgrade.pl
Normal file
111
share/ddl/_common/upgrade/5-6/002-entity-upgrade.pl
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
#! perl
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator::ScriptHelpers
|
||||||
|
'schema_from_schema_loader';
|
||||||
|
|
||||||
|
schema_from_schema_loader({ naming => 'v7' }, sub {
|
||||||
|
my $schema = shift;
|
||||||
|
|
||||||
|
my $user_rs = $schema->resultset('UsersTemp');
|
||||||
|
my $customer_rs = $schema->resultset('CustomersTemp');
|
||||||
|
my $organisation_rs = $schema->resultset('OrganisationsTemp');
|
||||||
|
my $transaction_rs = $schema->resultset('TransactionsTemp');
|
||||||
|
my $pending_org_rs = $schema->resultset('PendingOrganisation');
|
||||||
|
my $pending_trans_rs = $schema->resultset('PendingTransaction');
|
||||||
|
|
||||||
|
# Lookups used for converting transactions
|
||||||
|
my $org_lookup = {};
|
||||||
|
my $user_lookup = {};
|
||||||
|
|
||||||
|
# First migrate all customers, organisations, and pending organisations across to the entity table.
|
||||||
|
for my $customer_result ( $customer_rs->all ) {
|
||||||
|
my $user_result = $user_rs->find({ customer_id => $customer_result->id });
|
||||||
|
my $administrator = $schema->resultset('Administrator')->find({ user_id => $user_result->id });
|
||||||
|
my $new_entity = $schema->resultset('Entity')->create({ type => 'customer' });
|
||||||
|
|
||||||
|
my $new_customer = $schema->resultset('Customer')->create({
|
||||||
|
entity_id => $new_entity->id,
|
||||||
|
display_name => $customer_result->display_name,
|
||||||
|
full_name => $customer_result->full_name,
|
||||||
|
year_of_birth => $customer_result->year_of_birth,
|
||||||
|
postcode => $customer_result->postcode,
|
||||||
|
});
|
||||||
|
|
||||||
|
# In the old system, all customers were users
|
||||||
|
my $new_user = $schema->resultset('User')->create({
|
||||||
|
entity_id => $new_entity->id,
|
||||||
|
email => $user_result->email,
|
||||||
|
join_date => $user_result->join_date,
|
||||||
|
password => $user_result->password,
|
||||||
|
is_admin => defined $administrator ? 1 : 0,
|
||||||
|
});
|
||||||
|
$user_lookup->{$user_result->id} = $new_entity->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
for my $organisation_result ( $organisation_rs->all ) {
|
||||||
|
my $user_result = $user_rs->find({ organisation_id => $organisation_result->id });
|
||||||
|
my $new_entity = $schema->resultset('Entity')->create({ type => 'organisation' });
|
||||||
|
|
||||||
|
my $org = $schema->resultset('Organisation')->create({
|
||||||
|
entity_id => $new_entity->id,
|
||||||
|
name => $organisation_result->name,
|
||||||
|
street_name => $organisation_result->street_name,
|
||||||
|
town => $organisation_result->town,
|
||||||
|
postcode => $organisation_result->postcode,
|
||||||
|
});
|
||||||
|
|
||||||
|
# In the old system, not all organisations were users - but could have still been an admin?
|
||||||
|
if ( defined $user_result ) {
|
||||||
|
my $administrator = $schema->resultset('Administrator')->find({ user_id => $user_result->id });
|
||||||
|
my $new_user = $schema->resultset('User')->create({
|
||||||
|
entity_id => $new_entity->id,
|
||||||
|
email => $user_result->email,
|
||||||
|
join_date => $user_result->join_date,
|
||||||
|
password => $user_result->password,
|
||||||
|
is_admin => defined $administrator ? 1 : 0,
|
||||||
|
});
|
||||||
|
$user_lookup->{$user_result->id} = $new_entity->id;
|
||||||
|
}
|
||||||
|
$org_lookup->{$organisation_result->id} = $new_entity->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
for my $transaction_result ( $transaction_rs->all ) {
|
||||||
|
my $new_transaction = $schema->resultset('Transaction')->create({
|
||||||
|
buyer_id => $user_lookup->{ $transaction_result->buyer_id },
|
||||||
|
seller_id => $org_lookup->{ $transaction_result->seller_id },
|
||||||
|
value => $transaction_result->value,
|
||||||
|
proof_image => $transaction_result->proof_image,
|
||||||
|
submitted_at => $transaction_result->submitted_at,
|
||||||
|
purchase_time => $transaction_result->purchase_time,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for my $pending_result ( $pending_org_rs->all ) {
|
||||||
|
my $entity = $schema->resultset('Entity')->create({ type => 'organisation' });
|
||||||
|
my $org = $schema->resultset('Organisation')->create({
|
||||||
|
entity_id => $entity->id,
|
||||||
|
name => $pending_result->name,
|
||||||
|
street_name => $pending_result->street_name,
|
||||||
|
town => $pending_result->town,
|
||||||
|
postcode => $pending_result->postcode,
|
||||||
|
submitted_by_id => $user_lookup->{ $pending_result->submitted_by_id },
|
||||||
|
pending => 1,
|
||||||
|
});
|
||||||
|
my $pending_trans_set_rs = $pending_trans_rs->search({
|
||||||
|
seller_id => $pending_result->id,
|
||||||
|
});
|
||||||
|
for my $trans_result ( $pending_trans_set_rs->all ) {
|
||||||
|
$schema->resultset('Transaction')->create({
|
||||||
|
buyer_id => $user_lookup->{ $trans_result->buyer_id },
|
||||||
|
seller_id => $entity->id,
|
||||||
|
value => $trans_result->value,
|
||||||
|
proof_image => $trans_result->proof_image,
|
||||||
|
submitted_at => $trans_result->submitted_at,
|
||||||
|
purchase_time => $trans_result->purchase_time,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
91
share/ddl/_source/deploy/6/001-auto-__VERSION.yml
Normal file
91
share/ddl/_source/deploy/6/001-auto-__VERSION.yml
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
---
|
||||||
|
schema:
|
||||||
|
procedures: {}
|
||||||
|
tables:
|
||||||
|
dbix_class_deploymenthandler_versions:
|
||||||
|
constraints:
|
||||||
|
- deferrable: 1
|
||||||
|
expression: ''
|
||||||
|
fields:
|
||||||
|
- id
|
||||||
|
match_type: ''
|
||||||
|
name: ''
|
||||||
|
on_delete: ''
|
||||||
|
on_update: ''
|
||||||
|
options: []
|
||||||
|
reference_fields: []
|
||||||
|
reference_table: ''
|
||||||
|
type: PRIMARY KEY
|
||||||
|
- deferrable: 1
|
||||||
|
expression: ''
|
||||||
|
fields:
|
||||||
|
- version
|
||||||
|
match_type: ''
|
||||||
|
name: dbix_class_deploymenthandler_versions_version
|
||||||
|
on_delete: ''
|
||||||
|
on_update: ''
|
||||||
|
options: []
|
||||||
|
reference_fields: []
|
||||||
|
reference_table: ''
|
||||||
|
type: UNIQUE
|
||||||
|
fields:
|
||||||
|
ddl:
|
||||||
|
data_type: text
|
||||||
|
default_value: ~
|
||||||
|
is_nullable: 1
|
||||||
|
is_primary_key: 0
|
||||||
|
is_unique: 0
|
||||||
|
name: ddl
|
||||||
|
order: 3
|
||||||
|
size:
|
||||||
|
- 0
|
||||||
|
id:
|
||||||
|
data_type: int
|
||||||
|
default_value: ~
|
||||||
|
is_auto_increment: 1
|
||||||
|
is_nullable: 0
|
||||||
|
is_primary_key: 1
|
||||||
|
is_unique: 0
|
||||||
|
name: id
|
||||||
|
order: 1
|
||||||
|
size:
|
||||||
|
- 0
|
||||||
|
upgrade_sql:
|
||||||
|
data_type: text
|
||||||
|
default_value: ~
|
||||||
|
is_nullable: 1
|
||||||
|
is_primary_key: 0
|
||||||
|
is_unique: 0
|
||||||
|
name: upgrade_sql
|
||||||
|
order: 4
|
||||||
|
size:
|
||||||
|
- 0
|
||||||
|
version:
|
||||||
|
data_type: varchar
|
||||||
|
default_value: ~
|
||||||
|
is_nullable: 0
|
||||||
|
is_primary_key: 0
|
||||||
|
is_unique: 1
|
||||||
|
name: version
|
||||||
|
order: 2
|
||||||
|
size:
|
||||||
|
- 50
|
||||||
|
indices: []
|
||||||
|
name: dbix_class_deploymenthandler_versions
|
||||||
|
options: []
|
||||||
|
order: 1
|
||||||
|
triggers: {}
|
||||||
|
views: {}
|
||||||
|
translator:
|
||||||
|
add_drop_table: 0
|
||||||
|
filename: ~
|
||||||
|
no_comments: 0
|
||||||
|
parser_args:
|
||||||
|
sources:
|
||||||
|
- __VERSION
|
||||||
|
parser_type: SQL::Translator::Parser::DBIx::Class
|
||||||
|
producer_args: {}
|
||||||
|
producer_type: SQL::Translator::Producer::YAML
|
||||||
|
show_warnings: 0
|
||||||
|
trace: 0
|
||||||
|
version: 0.11021
|
1064
share/ddl/_source/deploy/6/001-auto.yml
Normal file
1064
share/ddl/_source/deploy/6/001-auto.yml
Normal file
File diff suppressed because it is too large
Load diff
BIN
share/schema_graphs/schema-v005.png
Normal file
BIN
share/schema_graphs/schema-v005.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 153 KiB |
BIN
share/schema_graphs/schema-v006.png
Normal file
BIN
share/schema_graphs/schema-v006.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 120 KiB |
|
@ -1,27 +1,18 @@
|
||||||
use Mojo::Base -strict;
|
use Mojo::Base -strict;
|
||||||
|
|
||||||
|
use FindBin qw/ $Bin /;
|
||||||
|
|
||||||
use Test::More;
|
use Test::More;
|
||||||
use Mojo::JSON;
|
|
||||||
use Test::Pear::LocalLoop;
|
use Test::Pear::LocalLoop;
|
||||||
|
|
||||||
my $framework = Test::Pear::LocalLoop->new;
|
my $framework = Test::Pear::LocalLoop->new(
|
||||||
|
etc_dir => "$Bin/../etc",
|
||||||
|
);
|
||||||
|
$framework->install_fixtures('users');
|
||||||
|
|
||||||
my $t = $framework->framework;
|
my $t = $framework->framework;
|
||||||
my $schema = $t->app->schema;
|
my $schema = $t->app->schema;
|
||||||
|
|
||||||
$schema->resultset('User')->create({
|
|
||||||
email => 'admin@example.com',
|
|
||||||
password => 'abc123',
|
|
||||||
administrator => {},
|
|
||||||
});
|
|
||||||
|
|
||||||
$schema->resultset('User')->create({
|
|
||||||
email => 'user@example.com',
|
|
||||||
password => 'abc123',
|
|
||||||
});
|
|
||||||
|
|
||||||
is $schema->resultset('User')->count, 2, 'Users Created';
|
|
||||||
is $schema->resultset('Administrator')->count, 1, 'Admin Created';
|
|
||||||
|
|
||||||
my $location_is = sub {
|
my $location_is = sub {
|
||||||
my ($t, $value, $desc) = @_;
|
my ($t, $value, $desc) = @_;
|
||||||
$desc ||= "Location: $value";
|
$desc ||= "Location: $value";
|
||||||
|
@ -34,7 +25,7 @@ $t->get_ok('/admin')
|
||||||
|
|
||||||
$t->ua->max_redirects(10);
|
$t->ua->max_redirects(10);
|
||||||
$t->post_ok('/admin', form => {
|
$t->post_ok('/admin', form => {
|
||||||
email => 'user@example.com',
|
email => 'test1@example.com',
|
||||||
password => 'abc123',
|
password => 'abc123',
|
||||||
})->status_is(200);
|
})->status_is(200);
|
||||||
|
|
||||||
|
|
|
@ -1,38 +1,42 @@
|
||||||
use Mojo::Base -strict;
|
use Mojo::Base -strict;
|
||||||
|
|
||||||
|
use FindBin qw/ $Bin /;
|
||||||
|
|
||||||
use Test::More;
|
use Test::More;
|
||||||
use Mojo::JSON;
|
|
||||||
use Test::Pear::LocalLoop;
|
use Test::Pear::LocalLoop;
|
||||||
|
|
||||||
my $framework = Test::Pear::LocalLoop->new;
|
my $framework = Test::Pear::LocalLoop->new(
|
||||||
|
etc_dir => "$Bin/../etc",
|
||||||
|
);
|
||||||
|
$framework->install_fixtures('users');
|
||||||
my $t = $framework->framework;
|
my $t = $framework->framework;
|
||||||
my $schema = $t->app->schema;
|
my $schema = $t->app->schema;
|
||||||
|
|
||||||
my $user = $schema->resultset('User')->create({
|
my $valid_entity = $schema->resultset('Entity')->create({
|
||||||
email => 'admin@example.com',
|
organisation => {
|
||||||
password => 'abc123',
|
name => 'Shinra Electric Power Company',
|
||||||
administrator => {},
|
street_name => 'Sector 0, Midgar, Eastern Continent',
|
||||||
|
town => 'Gaia',
|
||||||
|
sector => 'A',
|
||||||
|
postcode => 'WC1E 6AD',
|
||||||
|
},
|
||||||
|
type => "organisation",
|
||||||
});
|
});
|
||||||
|
|
||||||
is $schema->resultset('Administrator')->count, 1, 'Admin Created';
|
my $pending_entity = $schema->resultset('Entity')->create({
|
||||||
|
organisation => {
|
||||||
$schema->resultset('Organisation')->create({
|
name => '7th Heaven',
|
||||||
id => 1,
|
street_name => 'Slums, Sector 7',
|
||||||
name => 'Shinra Electric Power Company',
|
town => 'Midgar',
|
||||||
street_name => 'Sector 0, Midgar, Eastern Continent',
|
sector => 'A',
|
||||||
town => 'Gaia',
|
postcode => 'WC1E 6AD',
|
||||||
sector => 'A',
|
pending => \"1",
|
||||||
postcode => 'WC1E 6AD',
|
},
|
||||||
|
type => "organisation",
|
||||||
});
|
});
|
||||||
|
|
||||||
$schema->resultset('PendingOrganisation')->create({
|
my $valid_id = $valid_entity->organisation->id;
|
||||||
id => 2,
|
my $pending_id = $pending_entity->organisation->id;
|
||||||
name => '7th Heaven',
|
|
||||||
street_name => 'Slums, Sector 7',
|
|
||||||
town => 'Midgar',
|
|
||||||
postcode => 'WC1E 6AD',
|
|
||||||
submitted_by_id => $user->id,
|
|
||||||
});
|
|
||||||
|
|
||||||
#login to admin
|
#login to admin
|
||||||
$t->ua->max_redirects(10);
|
$t->ua->max_redirects(10);
|
||||||
|
@ -42,15 +46,15 @@ $t->post_ok('/admin', form => {
|
||||||
})->status_is(200);
|
})->status_is(200);
|
||||||
|
|
||||||
#Read approved organisation
|
#Read approved organisation
|
||||||
$t->get_ok('/admin/organisations/valid/1/')
|
$t->get_ok("/admin/organisations/$valid_id")
|
||||||
->status_is(200);
|
->status_is(200)->or($framework->dump_error);
|
||||||
|
|
||||||
#Read pending organisation
|
#Read pending organisation
|
||||||
$t->get_ok('/admin/organisations/pending/2/')
|
$t->get_ok("/admin/organisations/$pending_id")
|
||||||
->status_is(200);
|
->status_is(200)->or($framework->dump_error);
|
||||||
|
|
||||||
#Valid approved organisation update
|
#Valid approved organisation update
|
||||||
$t->post_ok('/admin/organisations/valid/1/edit', form => {
|
$t->post_ok("/admin/organisations/$valid_id", form => {
|
||||||
name => 'Shinra Electric Power Company',
|
name => 'Shinra Electric Power Company',
|
||||||
street_name => 'Sector 0, Midgar, Eastern Continent',
|
street_name => 'Sector 0, Midgar, Eastern Continent',
|
||||||
town => 'Gaia',
|
town => 'Gaia',
|
||||||
|
@ -59,7 +63,7 @@ $t->post_ok('/admin/organisations/valid/1/edit', form => {
|
||||||
})->status_is(200)->content_like(qr/Updated Organisation/);
|
})->status_is(200)->content_like(qr/Updated Organisation/);
|
||||||
|
|
||||||
#Failed validation on approved organisation
|
#Failed validation on approved organisation
|
||||||
$t->post_ok('/admin/organisations/valid/1/edit', form => {
|
$t->post_ok("/admin/organisations/$valid_id", form => {
|
||||||
name => 'Shinra Electric Power Company',
|
name => 'Shinra Electric Power Company',
|
||||||
street_name => 'Sector 0, Midgar, Eastern Continent',
|
street_name => 'Sector 0, Midgar, Eastern Continent',
|
||||||
sector => 'A',
|
sector => 'A',
|
||||||
|
@ -67,7 +71,7 @@ $t->post_ok('/admin/organisations/valid/1/edit', form => {
|
||||||
})->content_like(qr/The validation has failed/);
|
})->content_like(qr/The validation has failed/);
|
||||||
|
|
||||||
#Valid pending organisation update
|
#Valid pending organisation update
|
||||||
$t->post_ok('/admin/organisations/pending/2/edit', form => {
|
$t->post_ok("/admin/organisations/$pending_id", form => {
|
||||||
name => '7th Heaven',
|
name => '7th Heaven',
|
||||||
street_name => 'Slums, Sector 7',
|
street_name => 'Slums, Sector 7',
|
||||||
town => 'Midgar',
|
town => 'Midgar',
|
||||||
|
@ -75,14 +79,14 @@ $t->post_ok('/admin/organisations/pending/2/edit', form => {
|
||||||
})->status_is(200)->content_like(qr/Updated Organisation/);
|
})->status_is(200)->content_like(qr/Updated Organisation/);
|
||||||
|
|
||||||
#Failed validation on pending organisation
|
#Failed validation on pending organisation
|
||||||
$t->post_ok('/admin/organisations/pending/2/edit', form => {
|
$t->post_ok("/admin/organisations/$pending_id", form => {
|
||||||
name => '7th Heaven',
|
name => '7th Heaven',
|
||||||
street_name => 'Slums, Sector 7',
|
street_name => 'Slums, Sector 7',
|
||||||
postcode => 'WC1E 6AD',
|
postcode => 'WC1E 6AD',
|
||||||
})->content_like(qr/The validation has failed/);
|
})->content_like(qr/The validation has failed/);
|
||||||
|
|
||||||
#Valid adding organisation
|
#Valid adding organisation
|
||||||
$t->post_ok('/admin/organisations/add/submit', form => {
|
$t->post_ok('/admin/organisations/add', form => {
|
||||||
name => 'Wall Market',
|
name => 'Wall Market',
|
||||||
street_name => 'Slums, Sector 6',
|
street_name => 'Slums, Sector 6',
|
||||||
town => 'Midgar',
|
town => 'Midgar',
|
||||||
|
@ -91,7 +95,7 @@ $t->post_ok('/admin/organisations/add/submit', form => {
|
||||||
})->status_is(200)->content_like(qr/Added Organisation/);
|
})->status_is(200)->content_like(qr/Added Organisation/);
|
||||||
|
|
||||||
#Failed validation on adding organisation
|
#Failed validation on adding organisation
|
||||||
$t->post_ok('/admin/organisations/add/submit', form => {
|
$t->post_ok('/admin/organisations/add', form => {
|
||||||
name => 'Wall Market',
|
name => 'Wall Market',
|
||||||
street_name => 'Slums, Sector 6',
|
street_name => 'Slums, Sector 6',
|
||||||
postcode => 'TN35 5AQ',
|
postcode => 'TN35 5AQ',
|
||||||
|
|
|
@ -1,49 +1,17 @@
|
||||||
use Mojo::Base -strict;
|
use Mojo::Base -strict;
|
||||||
|
|
||||||
|
use FindBin qw/ $Bin /;
|
||||||
|
|
||||||
use Test::More;
|
use Test::More;
|
||||||
use Mojo::JSON;
|
|
||||||
use Test::Pear::LocalLoop;
|
use Test::Pear::LocalLoop;
|
||||||
|
|
||||||
my $framework = Test::Pear::LocalLoop->new;
|
my $framework = Test::Pear::LocalLoop->new(
|
||||||
|
etc_dir => "$Bin/../etc",
|
||||||
|
);
|
||||||
|
$framework->install_fixtures('users');
|
||||||
my $t = $framework->framework;
|
my $t = $framework->framework;
|
||||||
my $schema = $t->app->schema;
|
my $schema = $t->app->schema;
|
||||||
|
|
||||||
my $user = $schema->resultset('User')->create({
|
|
||||||
email => 'admin@example.com',
|
|
||||||
password => 'abc123',
|
|
||||||
administrator => {},
|
|
||||||
});
|
|
||||||
|
|
||||||
is $schema->resultset('Administrator')->count, 1, 'Admin Created';
|
|
||||||
|
|
||||||
my $user1 = {
|
|
||||||
token => 'a',
|
|
||||||
full_name => 'Test User1',
|
|
||||||
display_name => 'Test User1',
|
|
||||||
email => 'test1@example.com',
|
|
||||||
postcode => 'LA1 1AA',
|
|
||||||
password => 'abc123',
|
|
||||||
year_of_birth => 2006,
|
|
||||||
};
|
|
||||||
|
|
||||||
my $org = {
|
|
||||||
token => 'e',
|
|
||||||
email => 'test50@example.com',
|
|
||||||
name => '7th Heaven',
|
|
||||||
street_name => 'Slums, Sector 7',
|
|
||||||
town => 'Midgar',
|
|
||||||
sector => 'A',
|
|
||||||
postcode => 'WC1E 6AD',
|
|
||||||
password => 'abc123',
|
|
||||||
};
|
|
||||||
|
|
||||||
$schema->resultset('AccountToken')->create({ name => $_->{token} })
|
|
||||||
for ( $user1, $org );
|
|
||||||
|
|
||||||
$framework->register_customer($user1);
|
|
||||||
|
|
||||||
$framework->register_organisation($org);
|
|
||||||
|
|
||||||
#login to admin
|
#login to admin
|
||||||
$t->ua->max_redirects(10);
|
$t->ua->max_redirects(10);
|
||||||
$t->post_ok('/admin', form => {
|
$t->post_ok('/admin', form => {
|
||||||
|
@ -51,27 +19,36 @@ $t->post_ok('/admin', form => {
|
||||||
password => 'abc123',
|
password => 'abc123',
|
||||||
})->status_is(200);
|
})->status_is(200);
|
||||||
|
|
||||||
|
$t->get_ok('/admin/users')
|
||||||
|
->status_is(200)
|
||||||
|
->or($framework->dump_error);
|
||||||
|
|
||||||
#Read customer user
|
#Read customer user
|
||||||
$t->get_ok('/admin/users/2/')
|
$t->get_ok('/admin/users/1')
|
||||||
->status_is(200);
|
->status_is(200);
|
||||||
|
|
||||||
#Read organisation user
|
#Read organisation user
|
||||||
$t->get_ok('/admin/users/3/')
|
$t->get_ok('/admin/users/5')
|
||||||
->status_is(200);
|
->status_is(200);
|
||||||
|
|
||||||
#Valid customer user update
|
#Valid customer user update
|
||||||
$t->post_ok('/admin/users/2/edit', form => {
|
$t->post_ok(
|
||||||
email => 'test12@example.com',
|
'/admin/users/1',
|
||||||
new_password => 'abc123',
|
form => {
|
||||||
full_name => 'Test User1',
|
email => 'test12@example.com',
|
||||||
display_name => 'Test User1',
|
new_password => 'abc123',
|
||||||
town => 'Midgar',
|
full_name => 'Test User1',
|
||||||
sector => 'A',
|
display_name => 'Test User1',
|
||||||
postcode => 'WC1E 6AD',
|
town => 'Midgar',
|
||||||
})->status_is(200)->content_like(qr/Updated User/);
|
sector => 'A',
|
||||||
|
postcode => 'WC1E 6AD',
|
||||||
|
})
|
||||||
|
->status_is(200)
|
||||||
|
->or($framework->dump_error)
|
||||||
|
->content_like(qr/Updated User/);
|
||||||
|
|
||||||
#Failed validation on customer user from no postcode
|
#Failed validation on customer user from no postcode
|
||||||
$t->post_ok('/admin/users/2/edit', form => {
|
$t->post_ok('/admin/users/2', form => {
|
||||||
email => 'test12@example.com',
|
email => 'test12@example.com',
|
||||||
new_password => 'abc123',
|
new_password => 'abc123',
|
||||||
full_name => 'Test User1',
|
full_name => 'Test User1',
|
||||||
|
@ -81,7 +58,7 @@ $t->post_ok('/admin/users/2/edit', form => {
|
||||||
})->content_like(qr/The validation has failed/);
|
})->content_like(qr/The validation has failed/);
|
||||||
|
|
||||||
#Failed validation on customer user from no display name
|
#Failed validation on customer user from no display name
|
||||||
$t->post_ok('/admin/users/2/edit', form => {
|
$t->post_ok('/admin/users/2', form => {
|
||||||
email => 'test12@example.com',
|
email => 'test12@example.com',
|
||||||
new_password => 'abc123',
|
new_password => 'abc123',
|
||||||
full_name => 'Test User1',
|
full_name => 'Test User1',
|
||||||
|
@ -91,7 +68,7 @@ $t->post_ok('/admin/users/2/edit', form => {
|
||||||
})->content_like(qr/The validation has failed/);
|
})->content_like(qr/The validation has failed/);
|
||||||
|
|
||||||
#Valid organisation user update
|
#Valid organisation user update
|
||||||
$t->post_ok('/admin/users/3/edit', form => {
|
$t->post_ok('/admin/users/5', form => {
|
||||||
email => 'test51@example.com',
|
email => 'test51@example.com',
|
||||||
new_password => 'abc123',
|
new_password => 'abc123',
|
||||||
name => '7th Heaven',
|
name => '7th Heaven',
|
||||||
|
@ -102,7 +79,7 @@ $t->post_ok('/admin/users/3/edit', form => {
|
||||||
})->status_is(200)->content_like(qr/Updated User/);
|
})->status_is(200)->content_like(qr/Updated User/);
|
||||||
|
|
||||||
#Failed validation on organisation user from no postcode
|
#Failed validation on organisation user from no postcode
|
||||||
$t->post_ok('/admin/users/3/edit', form => {
|
$t->post_ok('/admin/users/5', form => {
|
||||||
email => 'test50@example.com',
|
email => 'test50@example.com',
|
||||||
new_password => 'abc123',
|
new_password => 'abc123',
|
||||||
name => '7th Heaven',
|
name => '7th Heaven',
|
||||||
|
@ -112,7 +89,7 @@ $t->post_ok('/admin/users/3/edit', form => {
|
||||||
})->content_like(qr/The validation has failed/);
|
})->content_like(qr/The validation has failed/);
|
||||||
|
|
||||||
#Failed validation on organisation user from no street name
|
#Failed validation on organisation user from no street name
|
||||||
$t->post_ok('/admin/users/3/edit', form => {
|
$t->post_ok('/admin/users/5', form => {
|
||||||
email => 'test50@example.com',
|
email => 'test50@example.com',
|
||||||
new_password => 'abc123',
|
new_password => 'abc123',
|
||||||
name => '7th Heaven',
|
name => '7th Heaven',
|
||||||
|
|
166
t/api/search.t
166
t/api/search.t
|
@ -1,122 +1,46 @@
|
||||||
use Mojo::Base -strict;
|
use Mojo::Base -strict;
|
||||||
|
|
||||||
|
use FindBin qw/ $Bin /;
|
||||||
|
|
||||||
use Test::More;
|
use Test::More;
|
||||||
use Mojo::JSON;
|
use Mojo::JSON;
|
||||||
use Test::Pear::LocalLoop;
|
use Test::Pear::LocalLoop;
|
||||||
|
|
||||||
my $framework = Test::Pear::LocalLoop->new;
|
my $framework = Test::Pear::LocalLoop->new(
|
||||||
|
etc_dir => "$Bin/../etc",
|
||||||
|
);
|
||||||
|
$framework->install_fixtures('search');
|
||||||
|
|
||||||
my $t = $framework->framework;
|
my $t = $framework->framework;
|
||||||
my $schema = $t->app->schema;
|
my $schema = $t->app->schema;
|
||||||
my $dump_error = sub { diag $t->tx->res->to_string };
|
|
||||||
|
|
||||||
my @account_tokens = ('a', 'b');
|
#Login as customer
|
||||||
$schema->resultset('AccountToken')->populate([
|
my $session_key = $framework->login({
|
||||||
[ qw/ name / ],
|
'email' => 'test1@example.com',
|
||||||
map { [ $_ ] } @account_tokens,
|
'password' => 'abc123',
|
||||||
]);
|
});
|
||||||
|
|
||||||
$schema->resultset('Organisation')->populate([
|
my $json;
|
||||||
[ qw/ name street_name town postcode / ],
|
my $upload;
|
||||||
[ "Avanti Bar & Restaurant", "57 Main St", "Kirkby Lonsdale", "LA6 2AH" ],
|
|
||||||
[ "Full House Noodle Bar", "21 Common Garden St", "Lancaster", "LA1 1XD" ],
|
|
||||||
[ "The Quay's Fishbar", "1 Adcliffe Rd", "Lancaster", "LA1 1SS" ],
|
|
||||||
[ "Dan's Fishop", "56 North Rd", "Lancaster", "LA1 1LT" ],
|
|
||||||
[ "Hodgeson's Chippy", "96 Prospect St", "Lancaster", "LA1 3BH" ],
|
|
||||||
]);
|
|
||||||
|
|
||||||
#test with a customer.
|
$t->post_ok( '/api/upload', form => {
|
||||||
print "test 1 - Create customer user account (Rufus)\n";
|
json => Mojo::JSON::encode_json({
|
||||||
my $emailRufus = 'rufus@shinra.energy';
|
transaction_value => 10,
|
||||||
my $passwordRufus = 'MakoGold';
|
transaction_type => 3,
|
||||||
my $testJson = {
|
organisation_name => 'Shoreway Fisheries',
|
||||||
'usertype' => 'customer',
|
street_name => "2 James St",
|
||||||
'token' => shift(@account_tokens),
|
town => "Lancaster",
|
||||||
'full_name' => 'RufusShinra',
|
postcode => "LA1 1UP",
|
||||||
'display_name' => 'RufusShinra',
|
purchase_time => "2017-08-14T11:29:07.965+01:00",
|
||||||
'email' => $emailRufus,
|
session_key => $session_key,
|
||||||
'postcode' => 'RG26 5NU',
|
}),
|
||||||
'password' => $passwordRufus,
|
file => { file => './t/test.jpg' },
|
||||||
'year_of_birth' => 2006
|
})
|
||||||
};
|
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
|
||||||
->status_is(200)->or($framework->dump_error)
|
|
||||||
->json_is('/success', Mojo::JSON->true);
|
|
||||||
|
|
||||||
#test with an organisation.
|
|
||||||
print "test 2 - Create organisation user account (Choco Billy)\n";
|
|
||||||
my $emailBilly = 'choco.billy@chocofarm.org';
|
|
||||||
my $passwordBilly = 'Choco';
|
|
||||||
$testJson = {
|
|
||||||
'usertype' => 'organisation',
|
|
||||||
'token' => shift(@account_tokens),
|
|
||||||
'name' => 'ChocoBillysGreens',
|
|
||||||
'email' => $emailBilly,
|
|
||||||
'postcode' => 'LA1 1HT',
|
|
||||||
'password' => $passwordBilly,
|
|
||||||
'street_name' => 'Market St',
|
|
||||||
'town' => 'Lancaster',
|
|
||||||
'sector' => 'A',
|
|
||||||
};
|
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
|
->or($framework->dump_error)
|
||||||
->json_is('/success', Mojo::JSON->true);
|
->json_is('/success', Mojo::JSON->true);
|
||||||
|
|
||||||
my $session_key;
|
$framework->logout( $session_key );
|
||||||
|
|
||||||
sub login_rufus {
|
|
||||||
$testJson = {
|
|
||||||
'email' => $emailRufus,
|
|
||||||
'password' => $passwordRufus,
|
|
||||||
};
|
|
||||||
$t->post_ok('/api/login' => json => $testJson)
|
|
||||||
->status_is(200)
|
|
||||||
->json_is('/success', Mojo::JSON->true);
|
|
||||||
$session_key = $t->tx->res->json('/session_key');
|
|
||||||
};
|
|
||||||
|
|
||||||
sub login_billy {
|
|
||||||
$testJson = {
|
|
||||||
'email' => $emailBilly,
|
|
||||||
'password' => $passwordBilly,
|
|
||||||
};
|
|
||||||
$t->post_ok('/api/login' => json => $testJson)
|
|
||||||
->status_is(200)
|
|
||||||
->json_is('/success', Mojo::JSON->true);
|
|
||||||
$session_key = $t->tx->res->json('/session_key');
|
|
||||||
};
|
|
||||||
|
|
||||||
sub log_out{
|
|
||||||
$t->post_ok('/api/logout', json => { session_key => $session_key })
|
|
||||||
->status_is(200)
|
|
||||||
->json_is('/success', Mojo::JSON->true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
######################################################
|
|
||||||
|
|
||||||
#Login as Rufus (customer)
|
|
||||||
|
|
||||||
print "test 3 - Login - Rufus (cookies, customer)\n";
|
|
||||||
login_rufus();
|
|
||||||
|
|
||||||
print "test 4 - Added something containing 'fish'\n";
|
|
||||||
my $json = {
|
|
||||||
transaction_value => 10,
|
|
||||||
transaction_type => 3,
|
|
||||||
organisation_name => 'Shoreway Fisheries',
|
|
||||||
street_name => "2 James St",
|
|
||||||
town => "Lancaster",
|
|
||||||
postcode => "LA1 1UP",
|
|
||||||
purchase_time => "2017-08-14T11:29:07.965+01:00",
|
|
||||||
session_key => $session_key,
|
|
||||||
};
|
|
||||||
my $upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
|
||||||
$t->post_ok('/api/upload' => form => $upload )
|
|
||||||
->status_is(200)
|
|
||||||
->json_is('/success', Mojo::JSON->true);
|
|
||||||
|
|
||||||
print "test 5 - Logout Rufus \n";
|
|
||||||
log_out();
|
|
||||||
|
|
||||||
#End of Rufus (customer)
|
#End of Rufus (customer)
|
||||||
|
|
||||||
|
@ -125,7 +49,10 @@ log_out();
|
||||||
#Login as Choco billy (organisation)
|
#Login as Choco billy (organisation)
|
||||||
|
|
||||||
print "test 6 - Login - Choco billy (cookies, organisation)\n";
|
print "test 6 - Login - Choco billy (cookies, organisation)\n";
|
||||||
login_billy();
|
$session_key = $framework->login({
|
||||||
|
'email' => 'org@example.com',
|
||||||
|
'password' => 'abc123',
|
||||||
|
});
|
||||||
|
|
||||||
print "test 7 - Added something containing 'bar'\n";
|
print "test 7 - Added something containing 'bar'\n";
|
||||||
$json = {
|
$json = {
|
||||||
|
@ -160,16 +87,12 @@ $t->post_ok('/api/upload' => form => $upload )
|
||||||
->json_is('/success', Mojo::JSON->true);
|
->json_is('/success', Mojo::JSON->true);
|
||||||
|
|
||||||
print "test 9 - Logout Choco billy \n";
|
print "test 9 - Logout Choco billy \n";
|
||||||
log_out();
|
$framework->logout( $session_key );
|
||||||
|
|
||||||
#End of Choco billy (organisation)
|
$session_key = $framework->login({
|
||||||
|
'email' => 'test1@example.com',
|
||||||
######################################################
|
'password' => 'abc123',
|
||||||
|
});
|
||||||
#Login as Rufus (customer)
|
|
||||||
|
|
||||||
print "test 10 - Login - Rufus (cookies, customer)\n";
|
|
||||||
login_rufus();
|
|
||||||
|
|
||||||
sub check_vars{
|
sub check_vars{
|
||||||
my ($searchTerm, $numValidated, $numUnvalidated) = @_;
|
my ($searchTerm, $numValidated, $numUnvalidated) = @_;
|
||||||
|
@ -179,6 +102,7 @@ sub check_vars{
|
||||||
session_key => $session_key,
|
session_key => $session_key,
|
||||||
})
|
})
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
|
->or($framework->dump_error)
|
||||||
->json_is('/success', Mojo::JSON->true)
|
->json_is('/success', Mojo::JSON->true)
|
||||||
->json_has("unvalidated")
|
->json_has("unvalidated")
|
||||||
->json_has("validated");
|
->json_has("validated");
|
||||||
|
@ -196,7 +120,7 @@ sub check_vars{
|
||||||
};
|
};
|
||||||
|
|
||||||
print "test 11 - search blank\n";
|
print "test 11 - search blank\n";
|
||||||
check_vars(" ", 5, 1);
|
check_vars(" ", 6, 1);
|
||||||
|
|
||||||
print "test 12 - Testing expected values with 'booths'\n";
|
print "test 12 - Testing expected values with 'booths'\n";
|
||||||
#Expect 0 validated and 0 unvalidated with "booths".
|
#Expect 0 validated and 0 unvalidated with "booths".
|
||||||
|
@ -215,7 +139,7 @@ print "test 15 - Testing expected values with 'bar'\n";
|
||||||
check_vars("bar", 3, 0);
|
check_vars("bar", 3, 0);
|
||||||
|
|
||||||
print "test 16 - Logout Rufus \n";
|
print "test 16 - Logout Rufus \n";
|
||||||
log_out();
|
$framework->logout( $session_key );
|
||||||
|
|
||||||
#End of Rufus (customer)
|
#End of Rufus (customer)
|
||||||
|
|
||||||
|
@ -224,7 +148,10 @@ log_out();
|
||||||
#Login as Choco billy (organisation)
|
#Login as Choco billy (organisation)
|
||||||
|
|
||||||
print "test 17 - Login - Choco billy (cookies, organisation)\n";
|
print "test 17 - Login - Choco billy (cookies, organisation)\n";
|
||||||
login_billy();
|
$session_key = $framework->login({
|
||||||
|
'email' => 'org@example.com',
|
||||||
|
'password' => 'abc123',
|
||||||
|
});
|
||||||
|
|
||||||
print "test 18 - Testing expected values with 'booths'\n";
|
print "test 18 - Testing expected values with 'booths'\n";
|
||||||
#Expect 0 validated and 0 unvalidated with "booths".
|
#Expect 0 validated and 0 unvalidated with "booths".
|
||||||
|
@ -243,7 +170,6 @@ print "test 21 - Testing expected values with 'bar', with two unvalidated organi
|
||||||
check_vars("bar", 3, 2);
|
check_vars("bar", 3, 2);
|
||||||
|
|
||||||
print "test 22 - Logout Choco billy \n";
|
print "test 22 - Logout Choco billy \n";
|
||||||
log_out();
|
$framework->logout( $session_key );
|
||||||
|
|
||||||
|
|
||||||
done_testing();
|
done_testing();
|
||||||
|
|
|
@ -1,54 +1,33 @@
|
||||||
use Mojo::Base -strict;
|
use Mojo::Base -strict;
|
||||||
|
|
||||||
|
use FindBin qw/ $Bin /;
|
||||||
|
|
||||||
use Test::More;
|
use Test::More;
|
||||||
use Mojo::JSON;
|
use Mojo::JSON;
|
||||||
use Test::Pear::LocalLoop;
|
use Test::Pear::LocalLoop;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
|
||||||
my $framework = Test::Pear::LocalLoop->new;
|
my $framework = Test::Pear::LocalLoop->new(
|
||||||
|
etc_dir => "$Bin/../etc",
|
||||||
|
);
|
||||||
|
$framework->install_fixtures('users');
|
||||||
|
|
||||||
my $t = $framework->framework;
|
my $t = $framework->framework;
|
||||||
my $schema = $t->app->schema;
|
my $schema = $t->app->schema;
|
||||||
my $dtf = $schema->storage->datetime_parser;
|
my $dtf = $schema->storage->datetime_parser;
|
||||||
|
|
||||||
my $user = {
|
my $org_result = $schema->resultset('Organisation')->find({ name => 'Test Org' })->entity;
|
||||||
token => 'a',
|
my $user_result = $schema->resultset('User')->find({ email => 'test1@example.com' })->entity;
|
||||||
full_name => 'Test User',
|
|
||||||
display_name => 'Test User',
|
|
||||||
email => 'test@example.com',
|
|
||||||
postcode => 'LA1 1AA',
|
|
||||||
password => 'abc123',
|
|
||||||
year_of_birth => 2006,
|
|
||||||
};
|
|
||||||
|
|
||||||
my $org = {
|
|
||||||
token => 'b',
|
|
||||||
email => 'test2@example.com',
|
|
||||||
name => 'Test Org',
|
|
||||||
street_name => 'Test Street',
|
|
||||||
town => 'Lancaster',
|
|
||||||
postcode => 'LA1 1AA',
|
|
||||||
password => 'abc123',
|
|
||||||
sector => 'A',
|
|
||||||
};
|
|
||||||
|
|
||||||
$schema->resultset('AccountToken')->create({ name => $user->{token} });
|
|
||||||
$schema->resultset('AccountToken')->create({ name => $org->{token} });
|
|
||||||
|
|
||||||
$framework->register_customer($user);
|
|
||||||
$framework->register_organisation($org);
|
|
||||||
|
|
||||||
my $org_result = $schema->resultset('Organisation')->find({ name => $org->{name} });
|
|
||||||
my $user_result = $schema->resultset('User')->find({ email => $user->{email} });
|
|
||||||
|
|
||||||
my $session_key = $framework->login({
|
my $session_key = $framework->login({
|
||||||
email => $user->{email},
|
email => 'test1@example.com',
|
||||||
password => $user->{password},
|
password => 'abc123',
|
||||||
});
|
});
|
||||||
|
|
||||||
$t->app->schema->resultset('Leaderboard')->create_new( 'monthly_total', DateTime->now->truncate(to => 'month' )->subtract( months => 1) );
|
$t->app->schema->resultset('Leaderboard')->create_new( 'monthly_total', DateTime->now->truncate(to => 'month' )->subtract( months => 1) );
|
||||||
|
|
||||||
$t->post_ok('/api/stats' => json => { session_key => $session_key } )
|
$t->post_ok('/api/stats' => json => { session_key => $session_key } )
|
||||||
->status_is(200)
|
->status_is(200)->or($framework->dump_error)
|
||||||
->json_is('/success', Mojo::JSON->true)
|
->json_is('/success', Mojo::JSON->true)
|
||||||
->json_is('/today_sum', 0)
|
->json_is('/today_sum', 0)
|
||||||
->json_is('/today_count', 0)
|
->json_is('/today_count', 0)
|
||||||
|
@ -62,7 +41,7 @@ $t->post_ok('/api/stats' => json => { session_key => $session_key } )
|
||||||
->json_is('/global_count', 0);
|
->json_is('/global_count', 0);
|
||||||
|
|
||||||
for ( 1 .. 10 ) {
|
for ( 1 .. 10 ) {
|
||||||
$user_result->create_related( 'transactions', {
|
$user_result->create_related( 'purchases', {
|
||||||
seller_id => $org_result->id,
|
seller_id => $org_result->id,
|
||||||
value => $_,
|
value => $_,
|
||||||
proof_image => 'a',
|
proof_image => 'a',
|
||||||
|
@ -70,7 +49,7 @@ for ( 1 .. 10 ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( 11 .. 20 ) {
|
for ( 11 .. 20 ) {
|
||||||
$user_result->create_related( 'transactions', {
|
$user_result->create_related( 'purchases', {
|
||||||
seller_id => $org_result->id,
|
seller_id => $org_result->id,
|
||||||
value => $_,
|
value => $_,
|
||||||
proof_image => 'a',
|
proof_image => 'a',
|
||||||
|
@ -79,7 +58,7 @@ for ( 11 .. 20 ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( 21 .. 30 ) {
|
for ( 21 .. 30 ) {
|
||||||
$user_result->create_related( 'transactions', {
|
$user_result->create_related( 'purchases', {
|
||||||
seller_id => $org_result->id,
|
seller_id => $org_result->id,
|
||||||
value => $_,
|
value => $_,
|
||||||
proof_image => 'a',
|
proof_image => 'a',
|
||||||
|
@ -88,7 +67,7 @@ for ( 21 .. 30 ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( 31 .. 40 ) {
|
for ( 31 .. 40 ) {
|
||||||
$user_result->create_related( 'transactions', {
|
$user_result->create_related( 'purchases', {
|
||||||
seller_id => $org_result->id,
|
seller_id => $org_result->id,
|
||||||
value => $_,
|
value => $_,
|
||||||
proof_image => 'a',
|
proof_image => 'a',
|
||||||
|
@ -97,7 +76,7 @@ for ( 31 .. 40 ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( 41 .. 50 ) {
|
for ( 41 .. 50 ) {
|
||||||
$org_result->user->create_related( 'transactions', {
|
$org_result->create_related( 'purchases', {
|
||||||
seller_id => $org_result->id,
|
seller_id => $org_result->id,
|
||||||
value => $_,
|
value => $_,
|
||||||
proof_image => 'a',
|
proof_image => 'a',
|
||||||
|
@ -105,7 +84,7 @@ for ( 41 .. 50 ) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
is $user_result->transactions->search({
|
is $user_result->purchases->search({
|
||||||
purchase_time => {
|
purchase_time => {
|
||||||
-between => [
|
-between => [
|
||||||
$dtf->format_datetime(DateTime->today()),
|
$dtf->format_datetime(DateTime->today()),
|
||||||
|
@ -113,7 +92,7 @@ is $user_result->transactions->search({
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
})->get_column('value')->sum, 55, 'Got correct sum';
|
})->get_column('value')->sum, 55, 'Got correct sum';
|
||||||
is $user_result->transactions->today_rs->get_column('value')->sum, 55, 'Got correct sum through rs';
|
is $user_result->purchases->today_rs->get_column('value')->sum, 55, 'Got correct sum through rs';
|
||||||
|
|
||||||
$t->post_ok('/api/stats' => json => { session_key => $session_key } )
|
$t->post_ok('/api/stats' => json => { session_key => $session_key } )
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
|
|
|
@ -69,22 +69,22 @@ $framework->register_customer($_)
|
||||||
|
|
||||||
$framework->register_organisation($org);
|
$framework->register_organisation($org);
|
||||||
|
|
||||||
my $org_result = $schema->resultset('Organisation')->find({ name => $org->{name} });
|
my $org_result = $schema->resultset('Organisation')->find({ name => $org->{name} })->entity;
|
||||||
|
|
||||||
my $tweak = 0;
|
my $tweak = 0;
|
||||||
|
|
||||||
my $now = DateTime->today();
|
my $now = DateTime->today();
|
||||||
|
|
||||||
{
|
{
|
||||||
my $user_result = $schema->resultset('User')->find({ email => $user1->{email} });
|
my $user_result = $schema->resultset('User')->find({ email => $user1->{email} })->entity;
|
||||||
|
|
||||||
$user_result->create_related( 'transactions', {
|
$user_result->create_related( 'purchases', {
|
||||||
seller_id => $org_result->id,
|
seller_id => $org_result->id,
|
||||||
value => 1,
|
value => 1,
|
||||||
proof_image => 'a',
|
proof_image => 'a',
|
||||||
});
|
});
|
||||||
|
|
||||||
$user_result->create_related( 'transactions', {
|
$user_result->create_related( 'purchases', {
|
||||||
seller_id => $org_result->id,
|
seller_id => $org_result->id,
|
||||||
value => 9,
|
value => 9,
|
||||||
proof_image => 'a',
|
proof_image => 'a',
|
||||||
|
@ -93,15 +93,15 @@ my $now = DateTime->today();
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
my $user_result = $schema->resultset('User')->find({ email => $user2->{email} });
|
my $user_result = $schema->resultset('User')->find({ email => $user2->{email} })->entity;
|
||||||
|
|
||||||
$user_result->create_related( 'transactions', {
|
$user_result->create_related( 'purchases', {
|
||||||
seller_id => $org_result->id,
|
seller_id => $org_result->id,
|
||||||
value => 3,
|
value => 3,
|
||||||
proof_image => 'a',
|
proof_image => 'a',
|
||||||
});
|
});
|
||||||
|
|
||||||
$user_result->create_related( 'transactions', {
|
$user_result->create_related( 'purchases', {
|
||||||
seller_id => $org_result->id,
|
seller_id => $org_result->id,
|
||||||
value => 1,
|
value => 1,
|
||||||
proof_image => 'a',
|
proof_image => 'a',
|
||||||
|
@ -110,15 +110,15 @@ my $now = DateTime->today();
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
my $user_result = $schema->resultset('User')->find({ email => $user3->{email} });
|
my $user_result = $schema->resultset('User')->find({ email => $user3->{email} })->entity;
|
||||||
|
|
||||||
$user_result->create_related( 'transactions', {
|
$user_result->create_related( 'purchases', {
|
||||||
seller_id => $org_result->id,
|
seller_id => $org_result->id,
|
||||||
value => 5,
|
value => 5,
|
||||||
proof_image => 'a',
|
proof_image => 'a',
|
||||||
});
|
});
|
||||||
|
|
||||||
$user_result->create_related( 'transactions', {
|
$user_result->create_related( 'purchases', {
|
||||||
seller_id => $org_result->id,
|
seller_id => $org_result->id,
|
||||||
value => 5,
|
value => 5,
|
||||||
proof_image => 'a',
|
proof_image => 'a',
|
||||||
|
@ -127,15 +127,15 @@ my $now = DateTime->today();
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
my $user_result = $schema->resultset('User')->find({ email => $user4->{email} });
|
my $user_result = $schema->resultset('User')->find({ email => $user4->{email} })->entity;
|
||||||
|
|
||||||
$user_result->create_related( 'transactions', {
|
$user_result->create_related( 'purchases', {
|
||||||
seller_id => $org_result->id,
|
seller_id => $org_result->id,
|
||||||
value => 9,
|
value => 9,
|
||||||
proof_image => 'a',
|
proof_image => 'a',
|
||||||
});
|
});
|
||||||
|
|
||||||
$user_result->create_related( 'transactions', {
|
$user_result->create_related( 'purchases', {
|
||||||
seller_id => $org_result->id,
|
seller_id => $org_result->id,
|
||||||
value => 3,
|
value => 3,
|
||||||
proof_image => 'a',
|
proof_image => 'a',
|
||||||
|
|
|
@ -20,24 +20,25 @@ $schema->resultset('AccountToken')->populate([
|
||||||
my $test_purchase_time = "2017-08-14T11:29:07.965+01:00";
|
my $test_purchase_time = "2017-08-14T11:29:07.965+01:00";
|
||||||
|
|
||||||
#Add one company that we've apparently authenticated but does not have an account.
|
#Add one company that we've apparently authenticated but does not have an account.
|
||||||
my $org_id_shinra = 1;
|
|
||||||
|
|
||||||
my $org_rs = $schema->resultset('Organisation');
|
my $org_rs = $schema->resultset('Organisation');
|
||||||
|
|
||||||
is $org_rs->count, 0, "No organisations";
|
is $org_rs->count, 0, "No organisations";
|
||||||
$org_rs->create({
|
my $shinra_entity = $schema->resultset('Entity')->create_org({
|
||||||
id => $org_id_shinra,
|
|
||||||
name => 'Shinra Electric Power Company',
|
name => 'Shinra Electric Power Company',
|
||||||
street_name => 'Sector 0, Midgar, Eastern Continent',
|
street_name => 'Sector 0, Midgar, Eastern Continent',
|
||||||
town => 'Gaia',
|
town => 'Gaia',
|
||||||
postcode => 'E1 M00',
|
postcode => 'E1 M00',
|
||||||
|
submitted_by_id => 1,
|
||||||
});
|
});
|
||||||
is $org_rs->count, 1, "1 testing organisation";
|
is $org_rs->count, 1, "1 testing organisation";
|
||||||
|
|
||||||
|
my $org_id_shinra = $shinra_entity->organisation->id;
|
||||||
|
|
||||||
#Valid customer, this also tests that redirects are disabled for register.
|
#Valid customer, this also tests that redirects are disabled for register.
|
||||||
print "test 1 - Create customer user account (Rufus)\n";
|
print "test 1 - Create customer user account (Rufus)\n";
|
||||||
my $emailRufus = 'rufus@shinra.energy';
|
my $emailRufus = 'test1@example.com';
|
||||||
my $passwordRufus = 'MakoGold';
|
my $passwordRufus = 'abc123';
|
||||||
my $testJson = {
|
my $testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@account_tokens),
|
'token' => shift(@account_tokens),
|
||||||
|
@ -203,6 +204,7 @@ $json = {
|
||||||
$upload = {json => Mojo::JSON::encode_json($json)};
|
$upload = {json => Mojo::JSON::encode_json($json)};
|
||||||
$t->post_ok('/api/upload' => form => $upload )
|
$t->post_ok('/api/upload' => form => $upload )
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
|
->or($framework->dump_error)
|
||||||
->json_is('/success', Mojo::JSON->true)
|
->json_is('/success', Mojo::JSON->true)
|
||||||
->json_like('/message', qr/Upload Successful/);
|
->json_like('/message', qr/Upload Successful/);
|
||||||
is $schema->resultset('Transaction')->count, 1, "1 transaction";
|
is $schema->resultset('Transaction')->count, 1, "1 transaction";
|
||||||
|
@ -270,8 +272,8 @@ $t->post_ok('/api/upload' => form => $upload )
|
||||||
->content_like(qr/organisation_name is missing/i);
|
->content_like(qr/organisation_name is missing/i);
|
||||||
|
|
||||||
print "test 17 - add valid transaction (type 3: new organisation)\n";
|
print "test 17 - add valid transaction (type 3: new organisation)\n";
|
||||||
is $schema->resultset('PendingOrganisation')->count, 0, "No pending organisations";
|
is $schema->resultset('Organisation')->search({ pending => 1 })->count, 0, "No pending organisations";
|
||||||
is $schema->resultset('PendingTransaction')->count, 0, "No pending transactions";
|
is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 0, "No pending transactions";
|
||||||
|
|
||||||
$json = {
|
$json = {
|
||||||
transaction_value => 10,
|
transaction_value => 10,
|
||||||
|
@ -288,8 +290,8 @@ $t->post_ok('/api/upload' => form => $upload )
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
->json_is('/success', Mojo::JSON->true)
|
->json_is('/success', Mojo::JSON->true)
|
||||||
->json_like('/message', qr/Upload Successful/);
|
->json_like('/message', qr/Upload Successful/);
|
||||||
is $schema->resultset('PendingOrganisation')->count, 1, "1 pending organisations";
|
is $schema->resultset('Organisation')->search({ pending => 1 })->count, 1, "1 pending organisations";
|
||||||
is $schema->resultset('PendingTransaction')->count, 1, "1 pending transactions";
|
is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 1, "1 pending transactions";
|
||||||
|
|
||||||
# Add type 2 (unverified organisation) checking.
|
# Add type 2 (unverified organisation) checking.
|
||||||
|
|
||||||
|
@ -303,6 +305,7 @@ $json = {
|
||||||
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
||||||
$t->post_ok('/api/upload' => form => $upload )
|
$t->post_ok('/api/upload' => form => $upload )
|
||||||
->status_is(400)
|
->status_is(400)
|
||||||
|
->or($framework->dump_error)
|
||||||
->json_is('/success', Mojo::JSON->false)
|
->json_is('/success', Mojo::JSON->false)
|
||||||
->content_like(qr/organisation_id is missing/i);
|
->content_like(qr/organisation_id is missing/i);
|
||||||
|
|
||||||
|
@ -335,10 +338,10 @@ $t->post_ok('/api/upload' => form => $upload )
|
||||||
->content_like(qr/organisation_id does not exist in the database/i);
|
->content_like(qr/organisation_id does not exist in the database/i);
|
||||||
|
|
||||||
print "test 21 - purchase_time is missing\n";
|
print "test 21 - purchase_time is missing\n";
|
||||||
is $schema->resultset('PendingTransaction')->count, 1, "1 pending transactions";
|
is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 1, "1 pending transactions";
|
||||||
$json = {
|
$json = {
|
||||||
transaction_value => 10,
|
transaction_value => 10,
|
||||||
transaction_type => 2,
|
transaction_type => 1,
|
||||||
organisation_id => $org_id_shinra,
|
organisation_id => $org_id_shinra,
|
||||||
session_key => $session_key,
|
session_key => $session_key,
|
||||||
};
|
};
|
||||||
|
@ -369,9 +372,9 @@ $t->post_ok('/api/login' => json => $testJson)
|
||||||
$session_key = $t->tx->res->json('/session_key');
|
$session_key = $t->tx->res->json('/session_key');
|
||||||
|
|
||||||
print "test 24 - add valid transaction but for with account (type 2: existing organisation)\n";
|
print "test 24 - add valid transaction but for with account (type 2: existing organisation)\n";
|
||||||
my $org_result = $schema->resultset('PendingOrganisation')->find({ name => '7th Heaven' });
|
my $org_result = $schema->resultset('Organisation')->find({ name => '7th Heaven' });
|
||||||
my $unvalidatedOrganisationId = $org_result->id;
|
my $unvalidatedOrganisationId = $org_result->id;
|
||||||
is $schema->resultset('PendingTransaction')->count, 2, "2 pending transactions";
|
is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 1, "1 pending transactions";
|
||||||
$json = {
|
$json = {
|
||||||
transaction_value => 10,
|
transaction_value => 10,
|
||||||
transaction_type => 2,
|
transaction_type => 2,
|
||||||
|
@ -384,7 +387,7 @@ $t->post_ok('/api/upload' => form => $upload )
|
||||||
->status_is(400)
|
->status_is(400)
|
||||||
->json_is('/success', Mojo::JSON->false)
|
->json_is('/success', Mojo::JSON->false)
|
||||||
->content_like(qr/organisation_id does not exist in the database/i);
|
->content_like(qr/organisation_id does not exist in the database/i);
|
||||||
is $schema->resultset('PendingTransaction')->count, 2, "2 pending transactions";
|
is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 1, "1 pending transactions";
|
||||||
|
|
||||||
print "test 25 - Logout Hojo\n";
|
print "test 25 - Logout Hojo\n";
|
||||||
$t->post_ok('/api/logout', json => { session_key => $session_key } )
|
$t->post_ok('/api/logout', json => { session_key => $session_key } )
|
||||||
|
@ -408,7 +411,7 @@ $t->post_ok('/api/login' => json => $testJson)
|
||||||
$session_key = $t->tx->res->json('/session_key');
|
$session_key = $t->tx->res->json('/session_key');
|
||||||
|
|
||||||
print "test 27 - add valid transaction (type 2: existing organisation)\n";
|
print "test 27 - add valid transaction (type 2: existing organisation)\n";
|
||||||
is $schema->resultset('PendingTransaction')->count, 2, "2 pending transactions";
|
is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 1, "1 pending transactions";
|
||||||
$json = {
|
$json = {
|
||||||
transaction_value => 10,
|
transaction_value => 10,
|
||||||
transaction_type => 2,
|
transaction_type => 2,
|
||||||
|
@ -421,7 +424,7 @@ $t->post_ok('/api/upload' => form => $upload )
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
->json_is('/success', Mojo::JSON->true)
|
->json_is('/success', Mojo::JSON->true)
|
||||||
->json_like('/message', qr/Upload Successful/);
|
->json_like('/message', qr/Upload Successful/);
|
||||||
is $schema->resultset('PendingTransaction')->count, 3, "3 pending transactions";
|
is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 2, "2 pending transactions";
|
||||||
|
|
||||||
|
|
||||||
print "test 28 - Logout Rufus\n";
|
print "test 28 - Logout Rufus\n";
|
||||||
|
@ -446,7 +449,7 @@ $t->post_ok('/api/login' => json => $testJson)
|
||||||
$session_key = $t->tx->res->json('/session_key');
|
$session_key = $t->tx->res->json('/session_key');
|
||||||
|
|
||||||
print "test 30 - organisation buy from another organisation\n";
|
print "test 30 - organisation buy from another organisation\n";
|
||||||
is $schema->resultset('Transaction')->count, 2, "2 transaction";
|
is $schema->resultset('Transaction')->count, 5, "5 transaction";
|
||||||
$json = {
|
$json = {
|
||||||
transaction_value => 100000,
|
transaction_value => 100000,
|
||||||
transaction_type => 1,
|
transaction_type => 1,
|
||||||
|
@ -459,6 +462,6 @@ $t->post_ok('/api/upload' => form => $upload )
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
->json_is('/success', Mojo::JSON->true)
|
->json_is('/success', Mojo::JSON->true)
|
||||||
->json_like('/message', qr/Upload Successful/);
|
->json_like('/message', qr/Upload Successful/);
|
||||||
is $schema->resultset('Transaction')->count, 3, "3 transaction";
|
is $schema->resultset('Transaction')->count, 6, "6 transaction";
|
||||||
|
|
||||||
done_testing();
|
done_testing();
|
||||||
|
|
|
@ -77,9 +77,11 @@ sub create_random_transaction {
|
||||||
my $buyer = shift;
|
my $buyer = shift;
|
||||||
my $time = shift;
|
my $time = shift;
|
||||||
|
|
||||||
|
my $buyer_result = $schema->resultset('User')->find({ email => $buyer })->entity;
|
||||||
|
my $seller_result = $schema->resultset('Organisation')->find({ name => 'Test Org' })->entity;
|
||||||
$schema->resultset('Transaction')->create({
|
$schema->resultset('Transaction')->create({
|
||||||
buyer => { email => $buyer },
|
buyer => $buyer_result,
|
||||||
seller => { name => 'Test Org' },
|
seller => $seller_result,
|
||||||
value => ( int( rand( 10000 ) ) / 100 ),
|
value => ( int( rand( 10000 ) ) / 100 ),
|
||||||
proof_image => 'a',
|
proof_image => 'a',
|
||||||
purchase_time => $time,
|
purchase_time => $time,
|
||||||
|
|
17
t/basic.t
17
t/basic.t
|
@ -1,15 +1,16 @@
|
||||||
use Mojo::Base -strict;
|
use Mojo::Base -strict;
|
||||||
|
|
||||||
|
use FindBin qw/ $Bin /;
|
||||||
|
|
||||||
use Test::More;
|
use Test::More;
|
||||||
use Test::Mojo;
|
use Test::Pear::LocalLoop;
|
||||||
|
|
||||||
use FindBin;
|
my $framework = Test::Pear::LocalLoop->new(
|
||||||
|
etc_dir => "$Bin/etc",
|
||||||
|
);
|
||||||
|
$framework->install_fixtures('users');
|
||||||
|
|
||||||
BEGIN {
|
my $t = $framework->framework;
|
||||||
$ENV{MOJO_MODE} = 'testing';
|
|
||||||
$ENV{MOJO_LOG_LEVEL} = 'debug';
|
|
||||||
}
|
|
||||||
|
|
||||||
my $t = Test::Mojo->new("Pear::LocalLoop");
|
|
||||||
$t->get_ok('/')->status_is(200);
|
$t->get_ok('/')->status_is(200);
|
||||||
|
|
||||||
done_testing();
|
done_testing();
|
||||||
|
|
88
t/etc/fixtures/config/search.pl
Normal file
88
t/etc/fixtures/config/search.pl
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
#! /usr/bin/env perl
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use DBIx::Class::Fixtures;
|
||||||
|
use FindBin qw/ $Bin /;
|
||||||
|
use lib "$Bin/../../../../lib";
|
||||||
|
use Pear::LocalLoop::Schema;
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
|
my $fixtures = DBIx::Class::Fixtures->new({
|
||||||
|
config_dir => "$Bin",
|
||||||
|
});
|
||||||
|
|
||||||
|
my $schema = Pear::LocalLoop::Schema->connect('dbi:SQLite::memory:');
|
||||||
|
|
||||||
|
$schema->deploy;
|
||||||
|
|
||||||
|
$fixtures->populate({
|
||||||
|
directory => "$Bin/../data/users",
|
||||||
|
no_deploy => 1,
|
||||||
|
schema => $schema,
|
||||||
|
});
|
||||||
|
|
||||||
|
my @orgs = (
|
||||||
|
{
|
||||||
|
organisation => {
|
||||||
|
name => 'Avanti Bar & Restaurant',
|
||||||
|
street_name => '57 Main St',
|
||||||
|
town => 'Kirkby Lonsdale',
|
||||||
|
postcode => 'LA6 2AH',
|
||||||
|
sector => 'I',
|
||||||
|
},
|
||||||
|
type => "organisation",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
organisation => {
|
||||||
|
name => 'Full House Noodle Bar',
|
||||||
|
street_name => '21 Common Garden St',
|
||||||
|
town => 'Lancaster',
|
||||||
|
postcode => 'LA1 1XD',
|
||||||
|
sector => 'I',
|
||||||
|
},
|
||||||
|
type => "organisation",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
organisation => {
|
||||||
|
name => 'The Quay\'s Fishbar',
|
||||||
|
street_name => '1 Adcliffe Rd',
|
||||||
|
town => 'Lancaster',
|
||||||
|
postcode => 'LA1 1SS',
|
||||||
|
sector => 'I',
|
||||||
|
},
|
||||||
|
type => "organisation",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
organisation => {
|
||||||
|
name => 'Dan\'s Fishop',
|
||||||
|
street_name => '56 North Rd',
|
||||||
|
town => 'Lancaster',
|
||||||
|
postcode => 'LA1 1LT',
|
||||||
|
sector => 'I',
|
||||||
|
},
|
||||||
|
type => "organisation",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
organisation => {
|
||||||
|
name => 'Hodgeson\'s Chippy',
|
||||||
|
street_name => '96 Prospect St',
|
||||||
|
town => 'Lancaster',
|
||||||
|
postcode => 'LA1 3BH',
|
||||||
|
sector => 'I',
|
||||||
|
},
|
||||||
|
type => "organisation",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
$schema->resultset('Entity')->create( $_ ) for @orgs;
|
||||||
|
|
||||||
|
my $data_set = 'search';
|
||||||
|
|
||||||
|
$fixtures->dump({
|
||||||
|
all => 1,
|
||||||
|
schema => $schema,
|
||||||
|
directory => "$Bin/../data/" . $data_set,
|
||||||
|
});
|
||||||
|
|
|
@ -29,63 +29,93 @@ $schema->resultset('Leaderboard')->populate([
|
||||||
[ 'All Time Count', 'all_time_count' ],
|
[ 'All Time Count', 'all_time_count' ],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
my $user1 = {
|
my $entity1 = {
|
||||||
customer => {
|
customer => {
|
||||||
full_name => 'Test User1',
|
full_name => 'Test User1',
|
||||||
display_name => 'Test User1',
|
display_name => 'Test User1',
|
||||||
postcode => 'LA1 1AA',
|
postcode => 'LA1 1AA',
|
||||||
year_of_birth => 2006,
|
year_of_birth => 2006,
|
||||||
},
|
},
|
||||||
email => 'test1@example.com',
|
user => {
|
||||||
password => 'abc123',
|
email => 'test1@example.com',
|
||||||
|
password => 'abc123',
|
||||||
|
},
|
||||||
|
type => "customer",
|
||||||
};
|
};
|
||||||
|
|
||||||
my $user2 = {
|
my $entity2 = {
|
||||||
customer => {
|
customer => {
|
||||||
full_name => 'Test User2',
|
full_name => 'Test User2',
|
||||||
display_name => 'Test User2',
|
display_name => 'Test User2',
|
||||||
postcode => 'LA1 1AA',
|
postcode => 'LA1 1AA',
|
||||||
year_of_birth => 2006,
|
year_of_birth => 2006,
|
||||||
},
|
},
|
||||||
email => 'test2@example.com',
|
user => {
|
||||||
password => 'abc123',
|
email => 'test2@example.com',
|
||||||
|
password => 'abc123',
|
||||||
|
},
|
||||||
|
type => "customer",
|
||||||
};
|
};
|
||||||
|
|
||||||
my $user3 = {
|
my $entity3 = {
|
||||||
customer => {
|
customer => {
|
||||||
full_name => 'Test User3',
|
full_name => 'Test User3',
|
||||||
display_name => 'Test User3',
|
display_name => 'Test User3',
|
||||||
postcode => 'LA1 1AA',
|
postcode => 'LA1 1AA',
|
||||||
year_of_birth => 2006,
|
year_of_birth => 2006,
|
||||||
},
|
},
|
||||||
email => 'test3@example.com',
|
user => {
|
||||||
password => 'abc123',
|
email => 'test3@example.com',
|
||||||
|
password => 'abc123',
|
||||||
|
},
|
||||||
|
type => "customer",
|
||||||
};
|
};
|
||||||
|
|
||||||
my $user4 = {
|
my $entity4 = {
|
||||||
customer => {
|
customer => {
|
||||||
full_name => 'Test User4',
|
full_name => 'Test User4',
|
||||||
display_name => 'Test User4',
|
display_name => 'Test User4',
|
||||||
postcode => 'LA1 1AA',
|
postcode => 'LA1 1AA',
|
||||||
year_of_birth => 2006,
|
year_of_birth => 2006,
|
||||||
},
|
},
|
||||||
email => 'test4@example.com',
|
user => {
|
||||||
password => 'abc123',
|
email => 'test4@example.com',
|
||||||
|
password => 'abc123',
|
||||||
|
},
|
||||||
|
type => "customer",
|
||||||
};
|
};
|
||||||
|
|
||||||
my $org = {
|
my $entity5 = {
|
||||||
organisation => {
|
organisation => {
|
||||||
name => 'Test Org',
|
name => 'Test Org',
|
||||||
street_name => 'Test Street',
|
street_name => 'Test Street',
|
||||||
town => 'Lancaster',
|
town => 'Lancaster',
|
||||||
postcode => 'LA1 1AA',
|
postcode => 'LA1 1AA',
|
||||||
},
|
},
|
||||||
email => 'org@example.com',
|
user => {
|
||||||
password => 'abc123',
|
email => 'org@example.com',
|
||||||
|
password => 'abc123',
|
||||||
|
},
|
||||||
|
type => "organisation",
|
||||||
};
|
};
|
||||||
|
|
||||||
$schema->resultset('User')->create( $_ )
|
my $entity6 = {
|
||||||
for ( $user1, $user2, $user3, $user4, $org );
|
customer => {
|
||||||
|
full_name => 'Test Admin',
|
||||||
|
display_name => 'Test Admin',
|
||||||
|
postcode => 'LA1 1AA',
|
||||||
|
year_of_birth => 2006,
|
||||||
|
},
|
||||||
|
user => {
|
||||||
|
email => 'admin@example.com',
|
||||||
|
password => 'abc123',
|
||||||
|
is_admin => \"1",
|
||||||
|
},
|
||||||
|
type => "customer",
|
||||||
|
};
|
||||||
|
|
||||||
|
$schema->resultset('Entity')->create( $_ )
|
||||||
|
for ( $entity1, $entity2, $entity3, $entity4, $entity5, $entity6 );
|
||||||
|
|
||||||
my $data_set = 'users';
|
my $data_set = 'users';
|
||||||
|
|
||||||
|
|
57
t/etc/fixtures/data/search/_config_set
Normal file
57
t/etc/fixtures/data/search/_config_set
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
$VAR1 = {
|
||||||
|
'has_many' => {
|
||||||
|
'fetch' => 0
|
||||||
|
},
|
||||||
|
'sets' => [
|
||||||
|
{
|
||||||
|
'class' => 'Feedback',
|
||||||
|
'quantity' => 'all'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'quantity' => 'all',
|
||||||
|
'class' => 'Transaction'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'quantity' => 'all',
|
||||||
|
'class' => 'User'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'quantity' => 'all',
|
||||||
|
'class' => 'LeaderboardSet'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'class' => 'Customer',
|
||||||
|
'quantity' => 'all'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'quantity' => 'all',
|
||||||
|
'class' => 'Organisation'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'quantity' => 'all',
|
||||||
|
'class' => 'LeaderboardValue'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'class' => 'Entity',
|
||||||
|
'quantity' => 'all'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'quantity' => 'all',
|
||||||
|
'class' => 'Leaderboard'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'class' => 'SessionToken',
|
||||||
|
'quantity' => 'all'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'quantity' => 'all',
|
||||||
|
'class' => 'AccountToken'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
'might_have' => {
|
||||||
|
'fetch' => 0
|
||||||
|
},
|
||||||
|
'belongs_to' => {
|
||||||
|
'fetch' => 0
|
||||||
|
}
|
||||||
|
};
|
1
t/etc/fixtures/data/search/_dumper_version
Normal file
1
t/etc/fixtures/data/search/_dumper_version
Normal file
|
@ -0,0 +1 @@
|
||||||
|
1.001036
|
8
t/etc/fixtures/data/search/customers/1.fix
Normal file
8
t/etc/fixtures/data/search/customers/1.fix
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
$HASH1 = {
|
||||||
|
display_name => 'Test User1',
|
||||||
|
entity_id => 1,
|
||||||
|
full_name => 'Test User1',
|
||||||
|
id => 1,
|
||||||
|
postcode => 'LA1 1AA',
|
||||||
|
year_of_birth => 2006
|
||||||
|
};
|
8
t/etc/fixtures/data/search/customers/2.fix
Normal file
8
t/etc/fixtures/data/search/customers/2.fix
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
$HASH1 = {
|
||||||
|
display_name => 'Test User2',
|
||||||
|
entity_id => 2,
|
||||||
|
full_name => 'Test User2',
|
||||||
|
id => 2,
|
||||||
|
postcode => 'LA1 1AA',
|
||||||
|
year_of_birth => 2006
|
||||||
|
};
|
8
t/etc/fixtures/data/search/customers/3.fix
Normal file
8
t/etc/fixtures/data/search/customers/3.fix
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
$HASH1 = {
|
||||||
|
display_name => 'Test User3',
|
||||||
|
entity_id => 3,
|
||||||
|
full_name => 'Test User3',
|
||||||
|
id => 3,
|
||||||
|
postcode => 'LA1 1AA',
|
||||||
|
year_of_birth => 2006
|
||||||
|
};
|
8
t/etc/fixtures/data/search/customers/4.fix
Normal file
8
t/etc/fixtures/data/search/customers/4.fix
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
$HASH1 = {
|
||||||
|
display_name => 'Test User4',
|
||||||
|
entity_id => 4,
|
||||||
|
full_name => 'Test User4',
|
||||||
|
id => 4,
|
||||||
|
postcode => 'LA1 1AA',
|
||||||
|
year_of_birth => 2006
|
||||||
|
};
|
8
t/etc/fixtures/data/search/customers/5.fix
Normal file
8
t/etc/fixtures/data/search/customers/5.fix
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
$HASH1 = {
|
||||||
|
display_name => 'Test Admin',
|
||||||
|
entity_id => 6,
|
||||||
|
full_name => 'Test Admin',
|
||||||
|
id => 5,
|
||||||
|
postcode => 'LA1 1AA',
|
||||||
|
year_of_birth => 2006
|
||||||
|
};
|
4
t/etc/fixtures/data/search/entities/1.fix
Normal file
4
t/etc/fixtures/data/search/entities/1.fix
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 1,
|
||||||
|
type => 'customer'
|
||||||
|
};
|
4
t/etc/fixtures/data/search/entities/10.fix
Normal file
4
t/etc/fixtures/data/search/entities/10.fix
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 10,
|
||||||
|
type => 'organisation'
|
||||||
|
};
|
4
t/etc/fixtures/data/search/entities/11.fix
Normal file
4
t/etc/fixtures/data/search/entities/11.fix
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 11,
|
||||||
|
type => 'organisation'
|
||||||
|
};
|
4
t/etc/fixtures/data/search/entities/2.fix
Normal file
4
t/etc/fixtures/data/search/entities/2.fix
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 2,
|
||||||
|
type => 'customer'
|
||||||
|
};
|
4
t/etc/fixtures/data/search/entities/3.fix
Normal file
4
t/etc/fixtures/data/search/entities/3.fix
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 3,
|
||||||
|
type => 'customer'
|
||||||
|
};
|
4
t/etc/fixtures/data/search/entities/4.fix
Normal file
4
t/etc/fixtures/data/search/entities/4.fix
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 4,
|
||||||
|
type => 'customer'
|
||||||
|
};
|
4
t/etc/fixtures/data/search/entities/5.fix
Normal file
4
t/etc/fixtures/data/search/entities/5.fix
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 5,
|
||||||
|
type => 'organisation'
|
||||||
|
};
|
4
t/etc/fixtures/data/search/entities/6.fix
Normal file
4
t/etc/fixtures/data/search/entities/6.fix
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 6,
|
||||||
|
type => 'customer'
|
||||||
|
};
|
4
t/etc/fixtures/data/search/entities/7.fix
Normal file
4
t/etc/fixtures/data/search/entities/7.fix
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 7,
|
||||||
|
type => 'organisation'
|
||||||
|
};
|
4
t/etc/fixtures/data/search/entities/8.fix
Normal file
4
t/etc/fixtures/data/search/entities/8.fix
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 8,
|
||||||
|
type => 'organisation'
|
||||||
|
};
|
4
t/etc/fixtures/data/search/entities/9.fix
Normal file
4
t/etc/fixtures/data/search/entities/9.fix
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 9,
|
||||||
|
type => 'organisation'
|
||||||
|
};
|
5
t/etc/fixtures/data/search/leaderboards/1.fix
Normal file
5
t/etc/fixtures/data/search/leaderboards/1.fix
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 1,
|
||||||
|
name => 'Daily Total',
|
||||||
|
type => 'daily_total'
|
||||||
|
};
|
5
t/etc/fixtures/data/search/leaderboards/2.fix
Normal file
5
t/etc/fixtures/data/search/leaderboards/2.fix
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 2,
|
||||||
|
name => 'Daily Count',
|
||||||
|
type => 'daily_count'
|
||||||
|
};
|
5
t/etc/fixtures/data/search/leaderboards/3.fix
Normal file
5
t/etc/fixtures/data/search/leaderboards/3.fix
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 3,
|
||||||
|
name => 'Weekly Total',
|
||||||
|
type => 'weekly_total'
|
||||||
|
};
|
5
t/etc/fixtures/data/search/leaderboards/4.fix
Normal file
5
t/etc/fixtures/data/search/leaderboards/4.fix
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 4,
|
||||||
|
name => 'Weekly Count',
|
||||||
|
type => 'weekly_count'
|
||||||
|
};
|
5
t/etc/fixtures/data/search/leaderboards/5.fix
Normal file
5
t/etc/fixtures/data/search/leaderboards/5.fix
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 5,
|
||||||
|
name => 'Monthly Total',
|
||||||
|
type => 'monthly_total'
|
||||||
|
};
|
5
t/etc/fixtures/data/search/leaderboards/6.fix
Normal file
5
t/etc/fixtures/data/search/leaderboards/6.fix
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 6,
|
||||||
|
name => 'Monthly Count',
|
||||||
|
type => 'monthly_count'
|
||||||
|
};
|
5
t/etc/fixtures/data/search/leaderboards/7.fix
Normal file
5
t/etc/fixtures/data/search/leaderboards/7.fix
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 7,
|
||||||
|
name => 'All Time Total',
|
||||||
|
type => 'all_time_total'
|
||||||
|
};
|
5
t/etc/fixtures/data/search/leaderboards/8.fix
Normal file
5
t/etc/fixtures/data/search/leaderboards/8.fix
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 8,
|
||||||
|
name => 'All Time Count',
|
||||||
|
type => 'all_time_count'
|
||||||
|
};
|
16
t/etc/fixtures/data/search/organisations/1.fix
Normal file
16
t/etc/fixtures/data/search/organisations/1.fix
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
$HASH1 = {
|
||||||
|
country => undef,
|
||||||
|
entity_id
|
||||||
|
=> 5,
|
||||||
|
id => 1,
|
||||||
|
name => 'Test Org',
|
||||||
|
pending => 0,
|
||||||
|
postcode
|
||||||
|
=> 'LA1 1AA',
|
||||||
|
sector => undef,
|
||||||
|
street_name
|
||||||
|
=> 'Test Street',
|
||||||
|
submitted_by_id
|
||||||
|
=> undef,
|
||||||
|
town => 'Lancaster'
|
||||||
|
};
|
16
t/etc/fixtures/data/search/organisations/2.fix
Normal file
16
t/etc/fixtures/data/search/organisations/2.fix
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
$HASH1 = {
|
||||||
|
country => undef,
|
||||||
|
entity_id
|
||||||
|
=> 7,
|
||||||
|
id => 2,
|
||||||
|
name => 'Avanti Bar & Restaurant',
|
||||||
|
pending => 0,
|
||||||
|
postcode
|
||||||
|
=> 'LA6 2AH',
|
||||||
|
sector => 'I',
|
||||||
|
street_name
|
||||||
|
=> '57 Main St',
|
||||||
|
submitted_by_id
|
||||||
|
=> undef,
|
||||||
|
town => 'Kirkby Lonsdale'
|
||||||
|
};
|
16
t/etc/fixtures/data/search/organisations/3.fix
Normal file
16
t/etc/fixtures/data/search/organisations/3.fix
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
$HASH1 = {
|
||||||
|
country => undef,
|
||||||
|
entity_id
|
||||||
|
=> 8,
|
||||||
|
id => 3,
|
||||||
|
name => 'Full House Noodle Bar',
|
||||||
|
pending => 0,
|
||||||
|
postcode
|
||||||
|
=> 'LA1 1XD',
|
||||||
|
sector => 'I',
|
||||||
|
street_name
|
||||||
|
=> '21 Common Garden St',
|
||||||
|
submitted_by_id
|
||||||
|
=> undef,
|
||||||
|
town => 'Lancaster'
|
||||||
|
};
|
16
t/etc/fixtures/data/search/organisations/4.fix
Normal file
16
t/etc/fixtures/data/search/organisations/4.fix
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
$HASH1 = {
|
||||||
|
country => undef,
|
||||||
|
entity_id
|
||||||
|
=> 9,
|
||||||
|
id => 4,
|
||||||
|
name => 'The Quay\'s Fishbar',
|
||||||
|
pending => 0,
|
||||||
|
postcode
|
||||||
|
=> 'LA1 1SS',
|
||||||
|
sector => 'I',
|
||||||
|
street_name
|
||||||
|
=> '1 Adcliffe Rd',
|
||||||
|
submitted_by_id
|
||||||
|
=> undef,
|
||||||
|
town => 'Lancaster'
|
||||||
|
};
|
16
t/etc/fixtures/data/search/organisations/5.fix
Normal file
16
t/etc/fixtures/data/search/organisations/5.fix
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
$HASH1 = {
|
||||||
|
country => undef,
|
||||||
|
entity_id
|
||||||
|
=> 10,
|
||||||
|
id => 5,
|
||||||
|
name => 'Dan\'s Fishop',
|
||||||
|
pending => 0,
|
||||||
|
postcode
|
||||||
|
=> 'LA1 1LT',
|
||||||
|
sector => 'I',
|
||||||
|
street_name
|
||||||
|
=> '56 North Rd',
|
||||||
|
submitted_by_id
|
||||||
|
=> undef,
|
||||||
|
town => 'Lancaster'
|
||||||
|
};
|
16
t/etc/fixtures/data/search/organisations/6.fix
Normal file
16
t/etc/fixtures/data/search/organisations/6.fix
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
$HASH1 = {
|
||||||
|
country => undef,
|
||||||
|
entity_id
|
||||||
|
=> 11,
|
||||||
|
id => 6,
|
||||||
|
name => 'Hodgeson\'s Chippy',
|
||||||
|
pending => 0,
|
||||||
|
postcode
|
||||||
|
=> 'LA1 3BH',
|
||||||
|
sector => 'I',
|
||||||
|
street_name
|
||||||
|
=> '96 Prospect St',
|
||||||
|
submitted_by_id
|
||||||
|
=> undef,
|
||||||
|
town => 'Lancaster'
|
||||||
|
};
|
8
t/etc/fixtures/data/search/users/1.fix
Normal file
8
t/etc/fixtures/data/search/users/1.fix
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
$HASH1 = {
|
||||||
|
email => 'test1@example.com',
|
||||||
|
entity_id => 1,
|
||||||
|
id => 1,
|
||||||
|
is_admin => 0,
|
||||||
|
join_date => '2017-08-31 12:17:25',
|
||||||
|
password => '$2a$08$HSuznDeSU1fuONwKhp2/S.TX/X4p4g0dHtz20kVXxprm8hIg5QQma'
|
||||||
|
};
|
8
t/etc/fixtures/data/search/users/2.fix
Normal file
8
t/etc/fixtures/data/search/users/2.fix
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
$HASH1 = {
|
||||||
|
email => 'test2@example.com',
|
||||||
|
entity_id => 2,
|
||||||
|
id => 2,
|
||||||
|
is_admin => 0,
|
||||||
|
join_date => '2017-08-31 12:17:25',
|
||||||
|
password => '$2a$08$5XYLWPJvVGuWUvfSWj9cIOg4/tyB4fZ3knzwgw5UnBSKFBFIKOiFC'
|
||||||
|
};
|
8
t/etc/fixtures/data/search/users/3.fix
Normal file
8
t/etc/fixtures/data/search/users/3.fix
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
$HASH1 = {
|
||||||
|
email => 'test3@example.com',
|
||||||
|
entity_id => 3,
|
||||||
|
id => 3,
|
||||||
|
is_admin => 0,
|
||||||
|
join_date => '2017-08-31 12:17:25',
|
||||||
|
password => '$2a$08$p5VU4leHetEvuz2P3uMfYuuPTkDGg8wsM7QuSVKkXR.s3B9T2JaVW'
|
||||||
|
};
|
8
t/etc/fixtures/data/search/users/4.fix
Normal file
8
t/etc/fixtures/data/search/users/4.fix
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
$HASH1 = {
|
||||||
|
email => 'test4@example.com',
|
||||||
|
entity_id => 4,
|
||||||
|
id => 4,
|
||||||
|
is_admin => 0,
|
||||||
|
join_date => '2017-08-31 12:17:25',
|
||||||
|
password => '$2a$08$fkkTUYA9zvt32iBbN7aOcOnmiHzOkbMEjN31PB9CsitGrE.KF7cAG'
|
||||||
|
};
|
8
t/etc/fixtures/data/search/users/5.fix
Normal file
8
t/etc/fixtures/data/search/users/5.fix
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
$HASH1 = {
|
||||||
|
email => 'org@example.com',
|
||||||
|
entity_id => 5,
|
||||||
|
id => 5,
|
||||||
|
is_admin => 0,
|
||||||
|
join_date => '2017-08-31 12:17:25',
|
||||||
|
password => '$2a$08$MWC45.w1AnLPNNHiS96ICOHfNlTrIqB0.7OPzy5qB.z0pZB0theo.'
|
||||||
|
};
|
8
t/etc/fixtures/data/search/users/6.fix
Normal file
8
t/etc/fixtures/data/search/users/6.fix
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
$HASH1 = {
|
||||||
|
email => 'admin@example.com',
|
||||||
|
entity_id => 6,
|
||||||
|
id => 6,
|
||||||
|
is_admin => 1,
|
||||||
|
join_date => '2017-08-31 12:17:25',
|
||||||
|
password => '$2a$08$1sPcPB9GnoNgzhBAk2bHSOqEmv6.Y6YLrAa2DJ6TR2WefzTYZQ92G'
|
||||||
|
};
|
|
@ -5,20 +5,21 @@ $VAR1 = {
|
||||||
'belongs_to' => {
|
'belongs_to' => {
|
||||||
'fetch' => 0
|
'fetch' => 0
|
||||||
},
|
},
|
||||||
'might_have' => {
|
|
||||||
'fetch' => 0
|
|
||||||
},
|
|
||||||
'sets' => [
|
'sets' => [
|
||||||
{
|
{
|
||||||
'class' => 'Leaderboard',
|
'class' => 'Feedback',
|
||||||
'quantity' => 'all'
|
'quantity' => 'all'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'class' => 'AccountToken',
|
'quantity' => 'all',
|
||||||
|
'class' => 'LeaderboardSet'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'class' => 'Transaction',
|
||||||
'quantity' => 'all'
|
'quantity' => 'all'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'class' => 'LeaderboardValue',
|
'class' => 'Entity',
|
||||||
'quantity' => 'all'
|
'quantity' => 'all'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -26,40 +27,31 @@ $VAR1 = {
|
||||||
'class' => 'SessionToken'
|
'class' => 'SessionToken'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'class' => 'Administrator',
|
'class' => 'AccountToken',
|
||||||
'quantity' => 'all'
|
'quantity' => 'all'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'class' => 'LeaderboardSet',
|
'class' => 'Organisation',
|
||||||
'quantity' => 'all'
|
'quantity' => 'all'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'quantity' => 'all',
|
'quantity' => 'all',
|
||||||
'class' => 'Feedback'
|
'class' => 'User'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'class' => 'PendingOrganisation',
|
'class' => 'Customer',
|
||||||
'quantity' => 'all'
|
'quantity' => 'all'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'class' => 'User',
|
'class' => 'Leaderboard',
|
||||||
'quantity' => 'all'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'class' => 'Transaction',
|
|
||||||
'quantity' => 'all'
|
'quantity' => 'all'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'quantity' => 'all',
|
'quantity' => 'all',
|
||||||
'class' => 'Organisation'
|
'class' => 'LeaderboardValue'
|
||||||
},
|
|
||||||
{
|
|
||||||
'quantity' => 'all',
|
|
||||||
'class' => 'Customer'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'quantity' => 'all',
|
|
||||||
'class' => 'PendingTransaction'
|
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
'might_have' => {
|
||||||
|
'fetch' => 0
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
$HASH1 = {
|
$HASH1 = {
|
||||||
display_name => 'Test User1',
|
display_name => 'Test User1',
|
||||||
|
entity_id => 1,
|
||||||
full_name => 'Test User1',
|
full_name => 'Test User1',
|
||||||
id => 1,
|
id => 1,
|
||||||
postcode => 'LA1 1AA',
|
postcode => 'LA1 1AA',
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
$HASH1 = {
|
$HASH1 = {
|
||||||
display_name => 'Test User2',
|
display_name => 'Test User2',
|
||||||
|
entity_id => 2,
|
||||||
full_name => 'Test User2',
|
full_name => 'Test User2',
|
||||||
id => 2,
|
id => 2,
|
||||||
postcode => 'LA1 1AA',
|
postcode => 'LA1 1AA',
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
$HASH1 = {
|
$HASH1 = {
|
||||||
display_name => 'Test User3',
|
display_name => 'Test User3',
|
||||||
|
entity_id => 3,
|
||||||
full_name => 'Test User3',
|
full_name => 'Test User3',
|
||||||
id => 3,
|
id => 3,
|
||||||
postcode => 'LA1 1AA',
|
postcode => 'LA1 1AA',
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
$HASH1 = {
|
$HASH1 = {
|
||||||
display_name => 'Test User4',
|
display_name => 'Test User4',
|
||||||
|
entity_id => 4,
|
||||||
full_name => 'Test User4',
|
full_name => 'Test User4',
|
||||||
id => 4,
|
id => 4,
|
||||||
postcode => 'LA1 1AA',
|
postcode => 'LA1 1AA',
|
||||||
|
|
8
t/etc/fixtures/data/users/customers/5.fix
Normal file
8
t/etc/fixtures/data/users/customers/5.fix
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
$HASH1 = {
|
||||||
|
display_name => 'Test Admin',
|
||||||
|
entity_id => 6,
|
||||||
|
full_name => 'Test Admin',
|
||||||
|
id => 5,
|
||||||
|
postcode => 'LA1 1AA',
|
||||||
|
year_of_birth => 2006
|
||||||
|
};
|
4
t/etc/fixtures/data/users/entities/1.fix
Normal file
4
t/etc/fixtures/data/users/entities/1.fix
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 1,
|
||||||
|
type => 'customer'
|
||||||
|
};
|
4
t/etc/fixtures/data/users/entities/2.fix
Normal file
4
t/etc/fixtures/data/users/entities/2.fix
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 2,
|
||||||
|
type => 'customer'
|
||||||
|
};
|
4
t/etc/fixtures/data/users/entities/3.fix
Normal file
4
t/etc/fixtures/data/users/entities/3.fix
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 3,
|
||||||
|
type => 'customer'
|
||||||
|
};
|
4
t/etc/fixtures/data/users/entities/4.fix
Normal file
4
t/etc/fixtures/data/users/entities/4.fix
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 4,
|
||||||
|
type => 'customer'
|
||||||
|
};
|
4
t/etc/fixtures/data/users/entities/5.fix
Normal file
4
t/etc/fixtures/data/users/entities/5.fix
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
$HASH1 = {
|
||||||
|
id => 5,
|
||||||
|
type => 'organisation'
|
||||||
|
};
|
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue