MCPcopy Create free account
hub / github.com/devxnshsharma/UnMessify / validateExpenseForm

Method validateExpenseForm

app.js:1331–1370  ·  view source on GitHub ↗
(formData)

Source from the content-addressed store, hash-verified

1329 }
1330
1331 validateExpenseForm(formData) {
1332 const errors = {};
1333
1334 const date = formData.get('date');
1335 if (!date) {
1336 errors.expenseDate = 'Date is required';
1337 } else {
1338 const expDate = new Date(date);
1339 const today = new Date();
1340 today.setHours(23, 59, 59, 999);
1341
1342 if (expDate > today) {
1343 errors.expenseDate = 'Date cannot be in the future';
1344 }
1345
1346 if (this.profile) {
1347 const startDate = new Date(this.profile.startDate);
1348 const endDate = new Date(startDate);
1349 endDate.setDate(endDate.getDate() + this.profile.monthDays - 1);
1350
1351 if (expDate < startDate || expDate > endDate) {
1352 errors.expenseDate = 'Date must be within your billing month';
1353 }
1354 }
1355 }
1356
1357 const cost = parseFloat(formData.get('cost'));
1358 if (isNaN(cost) || cost <= 0) {
1359 errors.cost = 'Cost must be greater than 0';
1360 } else if (cost > 2000) {
1361 errors.cost = 'Cost seems too high. Please verify.';
1362 }
1363
1364 const quantity = parseInt(formData.get('quantity'));
1365 if (isNaN(quantity) || quantity < 1) {
1366 errors.quantity = 'Quantity must be at least 1';
1367 }
1368
1369 return errors;
1370 }
1371
1372 handlePreferencesSubmit(form) {
1373 if (!this.profile) {

Callers 1

handleExpenseSubmitMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected