Skip to content

Commit e4c7604

Browse files
authored
Merge branch 'main' into refactor
2 parents 5f8948d + dde1ede commit e4c7604

17 files changed

+121
-155
lines changed

WPOrderProcessor.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const {
44
helpers: {
5-
SlugHelper
5+
StringHelper
66
},
77
constants
88
} = require(global.__lib);
@@ -21,8 +21,8 @@ class WPOrderProcessor {
2121
async getContact(order) {
2222
const contact = {
2323
Email: order.billing.email,
24-
FirstName: order.billing.first_name,
25-
Surname: order.billing.last_name,
24+
FirstName: StringHelper.toTitleCase(order.billing.first_name),
25+
Surname: StringHelper.toTitleCase(order.billing.last_name),
2626
IsActive: true,
2727
IsAdmin: false,
2828
Password: `BYBA@${this.#season.Identifier}`
@@ -47,9 +47,9 @@ class WPOrderProcessor {
4747
}
4848

4949
async getOrganisation(orgName) {
50-
const slug = SlugHelper.formatSlug(orgName);
50+
const slug = StringHelper.formatSlug(orgName);
5151
const org = {
52-
Name: orgName,
52+
Name: StringHelper.toTitleCase(orgName),
5353
Slug: slug,
5454
Description: '',
5555
OrganisationTypeId: constants.ORGANISATION_TYPE.BAND

config/db.sample.json

+3-21
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,9 @@
11
{
2-
"development": {
32
"username": "root",
43
"password": null,
54
"database": "database_development",
65
"host": "127.0.0.1",
76
"dialect": "mariadb",
8-
"sync": true
9-
},
10-
"test": {
11-
"username": "root",
12-
"password": null,
13-
"database": "database_test",
14-
"host": "127.0.0.1",
15-
"dialect": "mariadb",
16-
"sync": true
17-
},
18-
"production": {
19-
"username": "root",
20-
"password": null,
21-
"database": "database_production",
22-
"host": "127.0.0.1",
23-
"dialect": "mariadb",
24-
"logging": false,
25-
"sync": true
26-
}
27-
}
7+
"sync": false,
8+
"logging": true
9+
}

config/server.sample.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
{
22
"port": 5000,
3-
"noAuthRequired": [],
4-
"uploadPath":"/web/uploads/-org-",
5-
"uploadURL": "",
6-
"serveUploads": true,
3+
"noAuthRequired": ["/"],
74
"logging": true,
85
"uploadServer": "",
96
"uploadSecret": ""

config/site.sample.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"title": "Website Name",
3-
"frameworkURL": null,
43
"adminName": "Admin Team",
54
"adminEmail": "[email protected]",
6-
"version": "1.0.0"
5+
"version": "1.0.1b"
76
}

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"homepage": "https://github.com/BritishYouthBandAssociation/OrgAdmin#readme",
2020
"devDependencies": {
2121
"@byba/eslint-config": "^1.4.0",
22-
"eslint": "^8.26.0",
22+
"eslint": "^8.32.0",
2323
"husky": "^8.0.1",
2424
"lint-staged": "^13.0.3"
2525
},
@@ -29,17 +29,17 @@
2929
"chalk": "4",
3030
"connect-session-sequelize": "^7.1.4",
3131
"del": "6",
32-
"express": "^4.18.1",
33-
"express-form-data": "^2.0.18",
32+
"express": "^4.18.2",
33+
"express-form-data": "^2.0.19",
3434
"express-handlebars": "^6.0.6",
3535
"express-session": "^1.17.3",
3636
"gulp": "^4.0.2",
3737
"gulp-rename": "^2.0.0",
3838
"jimp": "^0.16.2",
39-
"joi": "^17.6.2",
39+
"joi": "^17.7.0",
4040
"morgan": "^1.10.0",
4141
"prompt-sync": "^4.2.0",
42-
"sequelize": "^6.25.3",
42+
"sequelize": "^6.28.0",
4343
"serve-favicon": "^2.5.0"
4444
},
4545
"lint-staged": {

routes/config.js

+25-20
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ router.post('/event-type', checkAdmin,
181181
})),
182182
async (req, res, next) => {
183183
await Promise.all(req.body.type.map((_, i) => {
184-
return (async function(){
184+
return (async function() {
185185
const details = {
186186
Name: req.body.type[i],
187187
EntryCost: req.body.cost[i],
@@ -207,27 +207,29 @@ router.post('/event-type', checkAdmin,
207207
}
208208
});
209209

210-
await Promise.all(req.body.discountAfter[i].map((_, d) => {
211-
return (async function() {
212-
const allPos = (req.body.membershipType[i][d] ?? []).indexOf(-1);
213-
if (allPos > -1) {
214-
req.body.membershipType[i][d].splice(allPos, 1);
215-
}
210+
if (req.body.discountAfter && req.body.discountAfter.length > i) {
211+
await Promise.all(req.body.discountAfter[i].map((_, d) => {
212+
return (async function() {
213+
const allPos = (req.body.membershipType[i][d] ?? []).indexOf(-1);
214+
if (allPos > -1) {
215+
req.body.membershipType[i][d].splice(allPos, 1);
216+
}
216217

217-
const discountDetails = {
218-
DiscountAfter: req.body.discountAfter[i][d],
219-
DiscountMultiplier: req.body.multiplier[i][d],
220-
MembersOnly: req.body.membersOnly[i][d],
221-
AllMembers: allPos > -1
222-
};
218+
const discountDetails = {
219+
DiscountAfter: req.body.discountAfter[i][d],
220+
DiscountMultiplier: req.body.multiplier[i][d],
221+
MembersOnly: req.body.membersOnly[i][d],
222+
AllMembers: allPos > -1
223+
};
223224

224-
const discount = await type.createEventTypeDiscount(discountDetails);
225+
const discount = await type.createEventTypeDiscount(discountDetails);
225226

226-
if (discount.MembersOnly) {
227-
await discount.addMembershipTypes(req.body.membershipType[i][d]);
228-
}
229-
})();
230-
}));
227+
if (discount.MembersOnly) {
228+
await discount.addMembershipTypes(req.body.membershipType[i][d]);
229+
}
230+
})();
231+
}));
232+
}
231233
})();
232234
}));
233235

@@ -429,7 +431,10 @@ router.get('/season', checkAdmin, validator.query(Joi.object({
429431
id: {
430432
[Op.not]: season?.id ?? 0
431433
}
432-
}
434+
},
435+
order: [
436+
['Start', 'DESC']
437+
]
433438
});
434439

435440
return res.render('config/season.hbs', {

routes/event.js

+9-43
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const Joi = require('joi');
77

88
const validator = require('@byba/express-validator');
99

10-
const { helpers: { SlugHelper: { formatSlug } } } = require(__lib);
10+
const { helpers: { StringHelper: { formatSlug } , SortHelper }} = require(__lib);
1111

1212
const router = express.Router();
1313

@@ -84,43 +84,6 @@ async function recalculateEntryFees(db, season, typeID, org) {
8484
}
8585
}
8686

87-
function shuffleArray(array) {
88-
for (let i = array.length - 1; i > 0; i--) {
89-
const j = Math.floor(Math.random() * (i + 1));
90-
[array[i], array[j]] = [array[j], array[i]];
91-
}
92-
93-
return array;
94-
}
95-
96-
function leagueSort(entries) {
97-
entries.sort((a, b) => {
98-
const aMember = a.Organisation.OrganisationMemberships;
99-
const aScore = aMember.length == 0 ? 0 : aMember[0].LeagueScore;
100-
101-
const bMember = b.Organisation.OrganisationMemberships;
102-
const bScore = bMember.length == 0 ? 0 : bMember[0].LeagueScore;
103-
104-
return aScore - bScore;
105-
});
106-
107-
return entries;
108-
}
109-
110-
function entrySort(array, direction) {
111-
array.sort((a, b) => {
112-
const d1 = new Date(a.EntryDate), d2 = new Date(b.EntryDate);
113-
114-
if (direction === 'asc') {
115-
return d1 - d2;
116-
}
117-
118-
return d2 - d1;
119-
});
120-
121-
return array;
122-
}
123-
12487
function splitEntries(entries, cutoff) {
12588
const late = [], regular = [];
12689

@@ -211,15 +174,15 @@ async function generateSchedule(req, next, eventID, config, divisionOrder) {
211174
let late = [], regular = div;
212175
if (config.LateOnFirst) {
213176
[late, regular] = splitEntries(div, cutoff);
214-
entrySort(late, 'desc');
177+
late = late.sort((a, b) => SortHelper.dateProp('EntryDate', a, b, false));
215178
}
216179

217180
if (config.Type.indexOf('entry') > -1) {
218-
entrySort(regular, config.Type.split('-')[1]);
181+
regular = regular.sort((a, b) => SortHelper.dateProp('EntryDate', a, b, config.Type.split('-')[1] == 'asc'));
219182
} else if (config.Type == 'league') {
220-
leagueSort(regular);
183+
regular = regular.sort((a, b) => SortHelper.compare(a.Organisation.OrganisationMemberships[0]?.LeagueScore, b.Organisation.OrganisationMemberships[0]?.LeagueScore));
221184
} else {
222-
shuffleArray(regular);
185+
regular = SortHelper.shuffleArray(regular);
223186
}
224187

225188
div = late.concat(regular);
@@ -272,7 +235,10 @@ router.get('/', async (req, res, next) => {
272235
],
273236
where: {
274237
SeasonId: season.id
275-
}
238+
},
239+
order: [
240+
['Start']
241+
]
276242
}),
277243
req.db.EventType.getActive()
278244
]);

routes/membership.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ const validator = require('@byba/express-validator');
1010
const WPOrderProcessor = require('../WPOrderProcessor');
1111
const { checkAdmin } = require('../middleware');
1212

13+
const {
14+
helpers: {
15+
SortHelper
16+
}
17+
} = require(global.__lib);
18+
1319
const router = express.Router();
1420

1521
router.get('/', checkAdmin, async (req, res, next) => {
@@ -19,7 +25,7 @@ router.get('/', checkAdmin, async (req, res, next) => {
1925
return res.redirect(`/config/season?needsSeason=true&next=${req.originalUrl}`);
2026
}
2127

22-
const memberships = await req.db.Membership.getAll({ SeasonId: season.id });
28+
const memberships = (await req.db.Membership.getAll({ SeasonId: season.id })).sort((a, b) => SortHelper.stringProp('Name', a, b));
2329

2430
const labels = await req.db.Label.findAll({
2531
where: { '$Memberships.SeasonId$': season.id },

routes/organisation.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ async function removeImage(config, id, origin, token = null) {
7474

7575
router.get('/', checkAdmin, async (req, res, next) => {
7676
const orgs = await req.db.Organisation.findAll({
77-
include: [req.db.OrganisationType]
77+
include: [req.db.OrganisationType],
78+
order: [
79+
['Name']
80+
]
7881
});
7982

8083
return res.render('organisation/index.hbs', {

routes/user.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ const idParamSchema = Joi.object({
1919
const {checkAdmin, matchingID} = require('../middleware');
2020

2121
router.get('/', checkAdmin, async (req, res, next) => {
22-
const users = await req.db.User.findAll();
22+
const users = await req.db.User.findAll({
23+
order: [
24+
['FirstName'],
25+
['Surname']
26+
]
27+
});
2328
const active = [];
2429
const inactive = [];
2530

views/config/season.hbs

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" :data-bs-target="'#collapse-' + season.id" aria-expanded="false" :aria-controls="'collapse-' + season.id">
5757
<span class="accordion-header header">${getTitle(season)} <span v-if="season.touched"> - edited</span></span>
5858
</button>
59-
<div :id="'collapse-' + season.id" class="accordion-collapse" :class="{'collapse': index < seasons.length, 'show': index == seasons.length - 1}" data-bs-parent="#seasons">
59+
<div :id="'collapse-' + season.id" class="accordion-collapse" :class="{'collapse': index < seasons.length, 'show': index == seasons.length - 1 && season.touched}" data-bs-parent="#seasons">
6060
<div class="accordion-body">
6161
<div class="form-group mb-3">
6262
<label :for="'name-' + season.id">Identifier</label>
@@ -85,7 +85,7 @@
8585
{{/if}}
8686

8787
<div class="text-center">
88-
<button class="btn btn-lg btn-success" @click="addSeason">+ Add</button>
88+
<button type="button" class="btn btn-lg btn-success" @click="addSeason">+ Add</button>
8989
<button type="submit" class="btn btn-default btn-lg" v-if="seasons.length > 0">Save Changes</button>
9090
</div>
9191
</form>
@@ -112,7 +112,7 @@
112112
Start: '',
113113
End: '',
114114
Identifier: '',
115-
touched: false
115+
touched: true
116116
});
117117
118118
Vue.nextTick(() => {

views/event/index.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
<div class='row text-center'>
4646
{{#each events}}
47-
<div class='col-12 col-md-6 col-lg-4'>
47+
<div class='col-12 col-md-6 col-lg-4 mb-3'>
4848
<div class='card card-action' data-type='{{EventType.id}}'>
4949
<div class='card-body'>
5050
<p class='h4'><a href='{{id}}/' class='stretched-link text-reset text-decoration-none'>{{Name}}</a></p>

0 commit comments

Comments
 (0)