Skip to content

Commit 0f99d95

Browse files
authored
Merge pull request #259 from janong24/addValidators
Add validators
2 parents 0b9e760 + 9f710fb commit 0f99d95

9 files changed

+246
-56
lines changed

server/controllers/medicationController.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Request, Response } from "express";
22
import { Logger } from "../middlewares/logger";
33
import db from "../models";
4+
import {medicationValidator} from '../utils/databaseValidators';
45

56
export const createMedication = async (req: Request,res: Response) => {
67
try {
@@ -19,6 +20,7 @@ export const createMedication = async (req: Request,res: Response) => {
1920
}
2021

2122
const { medicationName, dateStarted, time, dosage, unit, frequency, route, notes } = req.body;
23+
medicationValidator(req.body);
2224
const medication = await db.Medication.create({
2325
uid: userId,
2426
medicationName,
@@ -125,7 +127,7 @@ export const updateMedication = async (req: Request,res: Response) => {
125127
}
126128

127129
const { medicationName, dateStarted, time, dosage, unit, frequency, route, notes } = req.body;
128-
130+
medicationValidator(req.body);
129131
await db.Medication.update({
130132
medicationName,
131133
dateStarted,

server/controllers/moodJournalController.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Request, Response } from 'express';
22
import { Logger } from '../middlewares/logger';
33
import db from '../models';
4+
import {moodJournalValidator} from '../utils/databaseValidators';
45

56
export const getMoodJournals = async (req: Request, res: Response) => {
67
try {
@@ -81,6 +82,9 @@ export const createMoodJournal = async (req: Request, res: Response) => {
8182
}
8283

8384
const { howAreYou, stressSignals, date, notes } = req.body;
85+
moodJournalValidator({ howAreYou, stressSignals, date, notes })
86+
87+
8488

8589
const stressSignalsString = JSON.stringify(stressSignals);
8690

@@ -122,6 +126,7 @@ export const updateMoodJournal = async (req: Request, res: Response) => {
122126
}
123127

124128
const { howAreYou, stressSignals, date, notes } = req.body;
129+
moodJournalValidator({ howAreYou, stressSignals, date, notes })
125130

126131
const stressSignalsString = JSON.stringify(stressSignals);
127132

server/controllers/notificationPreferenceController.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Request, Response } from "express";
22
import { Logger } from "../middlewares/logger";
33
import db from "../models";
4+
import {notificationPreferenceValidator} from '../utils/databaseValidators';
45

56
// Create the notification preferences for a given user
67
export const createNotificationPreference = async (
@@ -94,7 +95,7 @@ export const updateNotificationPreference = async (
9495
insulinDosageReminders,
9596
glucoseMeasurementReminders,
9697
} = req.body;
97-
98+
notificationPreferenceValidator(req.body)
9899
const updatedNotificationPreference =
99100
await db.NotificationPreference.update(
100101
{

server/controllers/weightJournalController.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Request, Response } from 'express';
22
import { Logger } from '../middlewares/logger';
33
import db from '../models';
4+
import {weightJournalValidator} from '../utils/databaseValidators';
45

56
export const getWeightJournals = async (req: Request, res: Response) => {
67
try {
@@ -83,6 +84,7 @@ export const createWeightJournal = async (req: Request, res: Response) => {
8384
}
8485

8586
const { date, time, weight, height, unit, notes } = req.body;
87+
weightJournalValidator({ date, time, weight, height, unit, notes })
8688

8789
const weightJournal = await db.WeightJournal.create({
8890
uid: user.uid,
@@ -107,6 +109,7 @@ export const createWeightJournal = async (req: Request, res: Response) => {
107109
export const updateWeightJournal = async (req: Request, res: Response) => {
108110
try {
109111
const { date, time, weight, height, unit, notes } = req.body;
112+
weightJournalValidator({ date, time, weight, height, unit, notes })
110113

111114
const weightJournalId = req.params.weightJournalId;
112115

server/package-lock.json

Lines changed: 33 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)