Skip to content

Commit dde1ede

Browse files
authored
Merge pull request #203 from BritishYouthBandAssociation/bugfix
Bugfix
2 parents 5d3dc41 + 01a3d25 commit dde1ede

17 files changed

+104
-141
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
} = require(global.__lib);
88

@@ -20,8 +20,8 @@ class WPOrderProcessor {
2020
async getContact(order) {
2121
const contact = {
2222
Email: order.billing.email,
23-
FirstName: order.billing.first_name,
24-
Surname: order.billing.last_name,
23+
FirstName: StringHelper.toTitleCase(order.billing.first_name),
24+
Surname: StringHelper.toTitleCase(order.billing.last_name),
2525
IsActive: true,
2626
IsAdmin: false,
2727
Password: `BYBA@${this.#season.Identifier}`
@@ -46,9 +46,9 @@ class WPOrderProcessor {
4646
}
4747

4848
async getOrganisation(orgName) {
49-
const slug = SlugHelper.formatSlug(orgName);
49+
const slug = StringHelper.formatSlug(orgName);
5050
const org = {
51-
Name: orgName,
51+
Name: StringHelper.toTitleCase(orgName),
5252
Slug: slug,
5353
Description: '',
5454
OrganisationTypeId: 1

app.js

-5
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,6 @@ async function main() {
106106

107107
app.use(express.static(path.join(__dirname, 'public')));
108108

109-
// Serve uploads locally
110-
if (serverOptions.serveUploads) {
111-
app.use('/uploads', express.static(path.resolve(serverOptions.uploadPath)));
112-
}
113-
114109
// Get database models and connection
115110
const dbPath = path.join(libPath, 'models');
116111
const db = await require(dbPath)(path.join(__dirname, 'config/db'));

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
}

routes/config.js

+25-20
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ router.post('/event-type', checkAdmin,
190190
})),
191191
async (req, res, next) => {
192192
await Promise.all(req.body.type.map((_, i) => {
193-
return (async function(){
193+
return (async function() {
194194
const details = {
195195
Name: req.body.type[i],
196196
EntryCost: req.body.cost[i],
@@ -216,27 +216,29 @@ router.post('/event-type', checkAdmin,
216216
}
217217
});
218218

219-
await Promise.all(req.body.discountAfter[i].map((_, d) => {
220-
return (async function() {
221-
const allPos = (req.body.membershipType[i][d] ?? []).indexOf(-1);
222-
if (allPos > -1) {
223-
req.body.membershipType[i][d].splice(allPos, 1);
224-
}
219+
if (req.body.discountAfter && req.body.discountAfter.length > i) {
220+
await Promise.all(req.body.discountAfter[i].map((_, d) => {
221+
return (async function() {
222+
const allPos = (req.body.membershipType[i][d] ?? []).indexOf(-1);
223+
if (allPos > -1) {
224+
req.body.membershipType[i][d].splice(allPos, 1);
225+
}
225226

226-
const discountDetails = {
227-
DiscountAfter: req.body.discountAfter[i][d],
228-
DiscountMultiplier: req.body.multiplier[i][d],
229-
MembersOnly: req.body.membersOnly[i][d],
230-
AllMembers: allPos > -1
231-
};
227+
const discountDetails = {
228+
DiscountAfter: req.body.discountAfter[i][d],
229+
DiscountMultiplier: req.body.multiplier[i][d],
230+
MembersOnly: req.body.membersOnly[i][d],
231+
AllMembers: allPos > -1
232+
};
232233

233-
const discount = await type.createEventTypeDiscount(discountDetails);
234+
const discount = await type.createEventTypeDiscount(discountDetails);
234235

235-
if (discount.MembersOnly) {
236-
await discount.addMembershipTypes(req.body.membershipType[i][d]);
237-
}
238-
})();
239-
}));
236+
if (discount.MembersOnly) {
237+
await discount.addMembershipTypes(req.body.membershipType[i][d]);
238+
}
239+
})();
240+
}));
241+
}
240242
})();
241243
}));
242244

@@ -447,7 +449,10 @@ router.get('/season', checkAdmin, validator.query(Joi.object({
447449
id: {
448450
[Op.not]: season?.id ?? 0
449451
}
450-
}
452+
},
453+
order: [
454+
['Start', 'DESC']
455+
]
451456
});
452457

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

routes/event.js

+9-43
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const { Op } = require('sequelize');
88

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

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

1313
const router = express.Router();
1414

@@ -91,43 +91,6 @@ async function recalculateEntryFees(db, season, typeID, org) {
9191
}
9292
}
9393

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

@@ -218,15 +181,15 @@ async function generateSchedule(req, next, eventID, config, divisionOrder) {
218181
let late = [], regular = div;
219182
if (config.LateOnFirst) {
220183
[late, regular] = splitEntries(div, cutoff);
221-
entrySort(late, 'desc');
184+
late = late.sort((a, b) => SortHelper.dateProp('EntryDate', a, b, false));
222185
}
223186

224187
if (config.Type.indexOf('entry') > -1) {
225-
entrySort(regular, config.Type.split('-')[1]);
188+
regular = regular.sort((a, b) => SortHelper.dateProp('EntryDate', a, b, config.Type.split('-')[1] == 'asc'));
226189
} else if (config.Type == 'league') {
227-
leagueSort(regular);
190+
regular = regular.sort((a, b) => SortHelper.compare(a.Organisation.OrganisationMemberships[0]?.LeagueScore, b.Organisation.OrganisationMemberships[0]?.LeagueScore));
228191
} else {
229-
shuffleArray(regular);
192+
regular = SortHelper.shuffleArray(regular);
230193
}
231194

232195
div = late.concat(regular);
@@ -288,7 +251,10 @@ router.get('/', async (req, res, next) => {
288251
],
289252
where: {
290253
SeasonId: season.id
291-
}
254+
},
255+
order: [
256+
['Start']
257+
]
292258
}),
293259
req.db.EventType.findAll()
294260
]);

routes/main.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ router.get('/home', async (req, res) => {
101101
include: [req.db.Address, {
102102
model: req.db.EventRegistration,
103103
include: [req.db.Organisation]
104-
}]
104+
}],
105+
order: [
106+
['Start']
107+
]
105108
}), req.db.Season.findOne({
106109
where: {
107110
Start: {

routes/membership.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ const { helpers } = require(global.__lib);
99
const validator = require('@byba/express-validator');
1010
const WPOrderProcessor = require('../WPOrderProcessor');
1111

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

1420
router.get('/', async (req, res, next) => {
@@ -31,7 +37,7 @@ router.get('/', async (req, res, next) => {
3137
return res.redirect(`/config/season?needsSeason=true&next=${req.originalUrl}`);
3238
}
3339

34-
const memberships = await req.db.Membership.findAll({
40+
const memberships = (await req.db.Membership.findAll({
3541
where: { SeasonId: season.id },
3642
include: [
3743
req.db.Label,
@@ -45,7 +51,7 @@ router.get('/', async (req, res, next) => {
4551
include: [req.db.Organisation]
4652
}
4753
]
48-
});
54+
})).sort((a, b) => SortHelper.stringProp('Name', a, b));
4955

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

routes/organisation.js

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

8787
router.get('/', checkAdmin, async (req, res, next) => {
8888
const orgs = await req.db.Organisation.findAll({
89-
include: [req.db.OrganisationType]
89+
include: [req.db.OrganisationType],
90+
order: [
91+
['Name']
92+
]
9093
});
9194

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

routes/user.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ const checkAccess = (req, res, next) => {
3333
};
3434

3535
router.get('/', checkAdmin, async (req, res, next) => {
36-
const users = await req.db.User.findAll();
36+
const users = await req.db.User.findAll({
37+
order: [
38+
['FirstName'],
39+
['Surname']
40+
]
41+
});
3742
const active = [];
3843
const inactive = [];
3944

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)