Skip to content

Commit 2a9e44f

Browse files
uds5501abhinavk96
authored andcommitted
fix: restrict event saving if information is incomplete (#3305)
1 parent 08fb445 commit 2a9e44f

File tree

1 file changed

+59
-41
lines changed

1 file changed

+59
-41
lines changed

app/mixins/event-wizard.js

Lines changed: 59 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -59,59 +59,76 @@ export default Mixin.create(MutableArray, CustomFormMixin, {
5959
}
6060
}
6161
}
62+
const numberOfTickets = data.tickets ? data.tickets.length : 0;
63+
if (event.name && event.locationName && event.startsAtDate && event.endsAtDate && numberOfTickets > 0) {
64+
await event.save();
6265

63-
await event.save();
64-
65-
for (const ticket of data.tickets ? data.tickets.toArray() : []) {
66-
ticket.set('maxOrder', Math.min(ticket.get('maxOrder'), ticket.get('quantity')));
67-
await ticket.save();
68-
}
66+
for (const ticket of data.tickets ? data.tickets.toArray() : []) {
67+
ticket.set('maxOrder', Math.min(ticket.get('maxOrder'), ticket.get('quantity')));
68+
await ticket.save();
69+
}
6970

70-
for (const socialLink of data.socialLinks ? data.socialLinks.toArray() : []) {
71-
await socialLink.save();
72-
}
71+
for (const socialLink of data.socialLinks ? data.socialLinks.toArray() : []) {
72+
await socialLink.save();
73+
}
7374

74-
if (data.copyright && data.copyright.get('licence')) {
75-
await data.copyright.save();
76-
}
75+
if (data.copyright && data.copyright.get('licence')) {
76+
await data.copyright.save();
77+
}
7778

78-
if (data.tax && data.tax.get('name')) {
79-
let tax = this.setRelationship(data.tax, event);
80-
if (event.get('isTaxEnabled')) {
81-
await tax.save();
82-
} else {
83-
await tax.destroyRecord();
79+
if (data.tax && data.tax.get('name')) {
80+
let tax = this.setRelationship(data.tax, event);
81+
if (event.get('isTaxEnabled')) {
82+
await tax.save();
83+
} else {
84+
await tax.destroyRecord();
85+
}
8486
}
85-
}
8687

87-
if (data.stripeAuthorization && data.stripeAuthorization.get('stripeAuthCode')) {
88-
let stripeAuthorization = this.setRelationship(data.stripeAuthorization, event);
89-
if (event.get('canPayByStripe')) {
90-
await stripeAuthorization.save();
91-
} else {
92-
await stripeAuthorization.destroyRecord();
88+
if (data.stripeAuthorization && data.stripeAuthorization.get('stripeAuthCode')) {
89+
let stripeAuthorization = this.setRelationship(data.stripeAuthorization, event);
90+
if (event.get('canPayByStripe')) {
91+
await stripeAuthorization.save();
92+
} else {
93+
await stripeAuthorization.destroyRecord();
94+
}
9395
}
94-
}
9596

96-
const bulkPromises = [];
97+
const bulkPromises = [];
9798

98-
for (const property of ['tracks', 'sessionTypes', 'microlocations', 'customForms']) {
99-
const items = data[property];
100-
for (const item of items ? items.toArray() : []) {
101-
bulkPromises.push(event.get('isSessionsSpeakersEnabled') ? item.save() : item.destroyRecord());
99+
for (const property of ['tracks', 'sessionTypes', 'microlocations', 'customForms']) {
100+
const items = data[property];
101+
for (const item of items ? items.toArray() : []) {
102+
bulkPromises.push(event.get('isSessionsSpeakersEnabled') ? item.save() : item.destroyRecord());
103+
}
102104
}
103-
}
104105

105-
for (const property of ['sponsors']) {
106-
const items = data[property];
107-
for (const item of items ? items.toArray() : []) {
108-
bulkPromises.push(event.get('isSponsorsEnabled') ? item.save() : item.destroyRecord());
106+
for (const property of ['sponsors']) {
107+
const items = data[property];
108+
for (const item of items ? items.toArray() : []) {
109+
bulkPromises.push(event.get('isSponsorsEnabled') ? item.save() : item.destroyRecord());
110+
}
109111
}
110-
}
111112

112-
await Promise.all(bulkPromises);
113+
await Promise.all(bulkPromises);
113114

114-
return event;
115+
return event;
116+
} else {
117+
let errorObject = { 'errors': [] };
118+
if (event.name === undefined || event.name === '') {
119+
errorObject.errors.push({ 'detail': 'Event name has not been provided' });
120+
}
121+
if (event.locationName === undefined || event.locationName === '') {
122+
errorObject.errors.push({ 'detail': 'Location has not been provided' });
123+
}
124+
if (event.startsAtDate === undefined || event.endsAtDate === undefined) {
125+
errorObject.errors.push({ 'detail': 'Dates have not been provided' });
126+
}
127+
if (numberOfTickets === 0) {
128+
errorObject.errors.push({ 'detail': 'Tickets are required for publishing event' });
129+
}
130+
throw (errorObject);
131+
}
115132
},
116133

117134
/**
@@ -128,8 +145,9 @@ export default Mixin.create(MutableArray, CustomFormMixin, {
128145
this.transitionToRoute(route, data.id);
129146
})
130147
.catch(e => {
131-
console.error(e);
132-
this.notify.error(this.l10n.t(e.errors[0].detail));
148+
e.errors.forEach(error => {
149+
this.notify.error(this.l10n.tVar(error.detail));
150+
});
133151
})
134152
.finally(() => {
135153
this.set('isLoading', false);

0 commit comments

Comments
 (0)