-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
successfully update progress on goals
- Loading branch information
1 parent
d4c0910
commit 027a351
Showing
6 changed files
with
220 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const { getCustomError } = require("../../../helpers/errorHandler"); | ||
const { getAuthenticatedUser } = require("../../../helpers/authenticationHelpers"); | ||
|
||
async function updateGoalProgress(req, res, db) { | ||
if ( | ||
!req.body || | ||
!req.body.data || | ||
!req.body.data.goal || | ||
!req.body.data.goal.id || | ||
!req.body.data.goal.practiceTimes | ||
) { | ||
return res.status(400).json(getCustomError(400)); | ||
} | ||
|
||
const authenticatedUser = getAuthenticatedUser(req.headers); | ||
|
||
if (!authenticatedUser) { | ||
return res.status(401).json(getCustomError(401)); | ||
} | ||
|
||
await db('goals').where({ | ||
user_email: authenticatedUser.email, | ||
id: req.body.data.goal.id | ||
}).update({ | ||
goal_practice_times: Number(req.body.data.goal.existingPracticeTimes) + Number(req.body.data.goal.practiceTimes) | ||
}); | ||
|
||
return res.json({ | ||
type: "Goal progress updated", | ||
attributes: { | ||
value: req.body.data.goal.id | ||
} | ||
}); | ||
} | ||
|
||
module.exports = updateGoalProgress; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { | ||
Dialog, | ||
Button, | ||
DialogTitle, | ||
DialogContent, | ||
DialogContentText, | ||
TextField, | ||
Box, | ||
Typography | ||
} from '@material-ui/core'; | ||
import makeStyles from '@material-ui/core/styles/makeStyles'; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
buttonMargin: { | ||
marginRight: '0.5rem' | ||
}, | ||
textFieldMargin: { | ||
marginBottom: '1rem' | ||
} | ||
})); | ||
|
||
function TrackProgressDialog(props) { | ||
const classes = useStyles(); | ||
|
||
return ( | ||
<Dialog open={props.isOpen} onClose={props.handleClose}> | ||
<DialogTitle>Track Goal Progress</DialogTitle> | ||
<DialogContent> | ||
<DialogContentText> | ||
Track progress towards your goal by entering how much you practiced. | ||
</DialogContentText> | ||
<Box pt={2}> | ||
<TextField | ||
className={classes.textFieldMargin} | ||
type="number" | ||
name="practice_times" | ||
label="How many times did you practice?" | ||
id="practice_times" | ||
onChange={(e) => props.setPracticeTimes(e.target.value)} | ||
variant="outlined" | ||
value={props.practiceTimes} | ||
fullWidth={true} | ||
required={true} | ||
placeholder="5" | ||
/> | ||
</Box> | ||
</DialogContent> | ||
<Box display="flex" justifyContent="flex-end" pt={1} pr={3} pb={2}> | ||
<Button | ||
className={classes.buttonMargin} | ||
variant="outlined" | ||
component="label" | ||
size="medium" | ||
color="primary" | ||
onClick={props.handleClose} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
variant="contained" | ||
component="label" | ||
size="medium" | ||
color="primary" | ||
onClick={props.handleSubmit} | ||
> | ||
Track Progress | ||
</Button> | ||
</Box> | ||
{props.trackProgressDialogError && ( | ||
<Box pt={2}> | ||
<Typography>{props.trackProgressDialogError}</Typography> | ||
</Box> | ||
)} | ||
</Dialog> | ||
); | ||
} | ||
|
||
export default TrackProgressDialog; |