Skip to content

Commit 4bbcb3a

Browse files
authored
Merge pull request #58 from pstaabp/create-model-class
Create model class
2 parents 6cf3c93 + 58fc52c commit 4bbcb3a

File tree

90 files changed

+7193
-3391
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+7193
-3391
lines changed

.eslintrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ module.exports = {
4646
__statics: 'readonly',
4747
process: 'readonly'
4848
},
49-
5049
rules: baseRules,
5150

5251
overrides: [{
@@ -81,7 +80,8 @@ module.exports = {
8180

8281
// TypeScript
8382
'@typescript-eslint/explicit-function-return-type': 'off',
84-
'@typescript-eslint/explicit-module-boundary-types': 'off'
83+
'@typescript-eslint/explicit-module-boundary-types': 'off',
84+
'@typescript-eslint/restrict-template-expressions': ['error', {allowBoolean: true, allNumbers: true }],
8585
}
8686

8787
}],

.github/workflows/linter.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ jobs:
5656
# Run Linter against code base #
5757
################################
5858
- name: Super-Linter
59-
# Note that this actually uses super-linter version 4.6.0 which is the desired version.
60-
# See https://github.com/github/super-linter/issues/1839.
61-
# It seems that version 4.6.1 has a bug with perlcritic, so we actually want 4.6.0.
62-
uses: github/[email protected]
59+
uses: github/[email protected]
6360

6461
env:
6562
VALIDATE_ALL_CODEBASE: false
@@ -72,7 +69,7 @@ jobs:
7269
CSS_FILE_NAME: .stylelintrc.js
7370
VALIDATE_TYPESCRIPT_STANDARD: false
7471
VALIDATE_JAVASCRIPT_STANDARD: false
75-
FILTER_REGEX_EXCLUDE: .*/we_b_wor_k3.yml
72+
FILTER_REGEX_EXCLUDE: (.*/we_b_wor_k3.yml|.*.csv)
7673

7774
perltidy:
7875
name: Run perltidy on Perl Files

.github/workflows/unit-tests.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
container: drgrice1/webwork3
1414
steps:
1515
- uses: actions/checkout@v2
16-
- name: Run unit tests
16+
- name: Run perl unit tests
1717
env:
1818
HARNESS_PERL_SWITCHES: -MDevel::Cover
1919
run: |
@@ -32,3 +32,13 @@ jobs:
3232
env:
3333
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
3434
run: cover -report codecov
35+
36+
# Install node (for npm) and use it to install eslint and stylelint dependencies.
37+
- name: Use Node.js
38+
uses: actions/setup-node@v2
39+
with:
40+
node-version: '16'
41+
- name: Install Dependencies
42+
run: npm ci
43+
- name: Run typescript (client-side) tests
44+
run: npm run test

conf/ww3-dev.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
secrets:
3+
- 3cdf63327fcf77deaed1d200df4b9fee66af2326
4+
webwork3_home: /opt/webwork/webwork3
5+
6+
# Database settings
7+
8+
# These settings are used for running unit_tests. You should choose a database
9+
# that is separate from any either production or other testing database. The
10+
# sqlite one is recommended. If you choose another full-featured DB, select a
11+
# database that is different than others.
12+
13+
# For the sqlite database
14+
test_database_dsn: dbi:SQLite:/opt/webwork/webwork3/t/db/sample_db.sqlite
15+
# For mysql or mariadb
16+
# note: choose a database
17+
#test_database_dsn: dbi:mysql:dbname=webwork3_test
18+
19+
# Database credentials for mysql or mariadb.
20+
# These are ignored if the 'sqlite' database is used.
21+
test_database_user: webworkWrite
22+
test_database_password: password
23+
24+
# If ignore_permissions is set to true, all routes can be executed.
25+
# This should only be used in development.
26+
ignore_permissions: true
27+
28+

jest.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-env node */
2+
3+
module.exports = {
4+
preset: 'ts-jest',
5+
testEnvironment: 'node',
6+
globals: {
7+
'ts-jest': {
8+
'tsconfig': 'tsconfig.json',
9+
'diagnostics': true
10+
}
11+
},
12+
moduleNameMapper: {
13+
'^src/(.*)$': '<rootDir>/src/$1',
14+
'^app/(.*)$': '<rootDir>/$1',
15+
'^components/(.*)$': '<rootDir>/src/components/$1',
16+
'^layouts/(.*)$': '<rootDir>/src/layouts/$1',
17+
'^pages/(.*)$': '<rootDir>/src/pages/$1',
18+
'^assets/(.*)$': '<rootDir>/src/assets/$1',
19+
'^boot/(.*)$': '<rootDir>/src/boot/$1'
20+
},
21+
testRegex: '(/tests/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
22+
};

lib/DB/Schema/Result/ProblemSet.pm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,17 @@ __PACKAGE__->add_columns(
100100
default_value => 1,
101101
is_nullable => 0
102102
},
103-
dates => { # store dates as a JSON object
103+
# store dates as a JSON object
104+
set_dates => {
104105
data_type => 'text',
105106
size => 256,
106107
is_nullable => 0,
107108
default_value => '{}',
108109
serializer_class => 'JSON',
109110
serializer_options => { utf8 => 1 }
110111
},
111-
params => { # store params as a JSON object
112+
# store params as a JSON object
113+
set_params => {
112114
data_type => 'text',
113115
size => 256,
114116
is_nullable => 0,

lib/DB/Schema/Result/UserSet.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ __PACKAGE__->add_columns(
102102
is_nullable => 0,
103103
default_value => 1,
104104
},
105-
dates => { # store dates as a JSON object
105+
set_dates => { # store dates as a JSON object
106106
data_type => 'text',
107107
size => 256,
108108
is_nullable => 0,
109109
default_value => '{}',
110110
serializer_class => 'JSON',
111111
serializer_options => { utf8 => 1 }
112112
},
113-
params => { # store params as a JSON object
113+
set_params => { # store params as a JSON object
114114
data_type => 'text',
115115
size => 256,
116116
is_nullable => 0,

lib/DB/Schema/ResultSet/Problem.pm

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ use strict;
33
use warnings;
44
use base 'DBIx::Class::ResultSet';
55

6-
use Carp;
7-
use Data::Dump qw/dd dump/;
8-
96
# use List::Util qw/first/;
107

118
use DB::Utils qw/getCourseInfo getSetInfo getProblemInfo/;
@@ -160,8 +157,11 @@ sub addSetProblem {
160157
# set the problem number to one more than the set's largest
161158
$new_problem_params->{problem_number} = 1 + ($problem_set->problems->get_column('problem_number')->max // 0);
162159

163-
$self->new($new_problem_params)->validParams();
160+
my $problem_to_add = $self->new($new_problem_params);
161+
$problem_to_add->validParams(undef, 'params');
162+
164163
my $added_problem = $problem_set->add_to_problems($new_problem_params);
164+
return $as_result_set ? $added_problem : { $added_problem->get_inflated_columns };
165165

166166
return $as_result_set ? $added_problem : { $added_problem->get_inflated_columns };
167167
}
@@ -197,10 +197,6 @@ sub deleteSetProblem {
197197

198198
}
199199

200-
# sub addPoolProblem {
201-
# my ( $self, $course_set_info, $new_set_params, $as_result_set ) = @_;
202-
# }
203-
204200
=head2 deleteSetProblem
205201
206202
This deletes the problem with given course and set

lib/DB/Schema/ResultSet/ProblemPool.pm

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ use strict;
33
use warnings;
44
use base 'DBIx::Class::ResultSet';
55

6-
use Carp;
7-
use Data::Dump qw/dd dump/;
8-
use Scalar::Util qw/reftype/;
96
use Try::Tiny;
107

118
use DB::Utils qw/getCourseInfo getPoolInfo getPoolProblemInfo/;
@@ -174,8 +171,7 @@ sub deleteProblemPool {
174171

175172
my $deleted_pool = $pool->delete();
176173

177-
return $deleted_pool if $as_result_set;
178-
return { $deleted_pool->get_columns };
174+
return $as_result_set ? $deleted_pool : { $deleted_pool->get_columns };
179175
}
180176

181177
#####
@@ -227,12 +223,10 @@ sub getPoolProblem {
227223
my @pool_problems = $problem_pool->search_related("pool_problems", $pool_problem_info)->all;
228224

229225
if (scalar(@pool_problems) == 1) {
230-
return $pool_problems[0] if $as_result_set;
231-
return { $pool_problems[0]->get_columns };
226+
return $as_result_set ? $pool_problems[0] : { $pool_problems[0]->get_inflated_columns };
232227
} else { # pick a random problem.
233228
my $prob = $pool_problems[ rand @pool_problems ];
234-
return $prob if $as_result_set;
235-
return { $prob->get_inflated_columns };
229+
return $as_result_set ? $prob : { $prob->get_inflated_columns };
236230
}
237231
}
238232

lib/DB/Schema/ResultSet/ProblemSet.pm

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use base 'DBIx::Class::ResultSet';
55

66
use Carp;
77
use Clone qw/clone/;
8-
use Data::Dump qw/dd dump/;
98

109
use DB::Utils qw/getCourseInfo getUserInfo getSetInfo updateAllFields/;
1110

@@ -175,12 +174,8 @@ sub addProblemSet {
175174
if defined($problem_set);
176175
my $set_obj = $self->new($set_params);
177176

178-
# dd {$set_obj->get_inflated_columns};
179-
180-
## check the parameters are valid.
181-
# $set_obj->setParamsAndDates;
182-
$set_obj->validDates();
183-
$set_obj->validParams();
177+
$set_obj->validDates(undef, 'set_dates');
178+
$set_obj->validParams(undef, 'set_params');
184179

185180
my $new_set = $course->add_to_problem_sets($set_params, 1);
186181

@@ -212,8 +207,8 @@ sub updateProblemSet {
212207
my $set_obj = $self->new($params2);
213208

214209
## check the parameters are valid.
215-
$set_obj->validDates();
216-
$set_obj->validParams();
210+
$set_obj->validDates(undef, 'set_dates');
211+
$set_obj->validParams(undef, 'set_params');
217212
my $updated_set = $problem_set->update({ $set_obj->get_inflated_columns });
218213
return $updated_set if $as_result_set;
219214
my $set = { $updated_set->get_inflated_columns, set_type => $updated_set->set_type };

0 commit comments

Comments
 (0)