Skip to content

Commit 3757168

Browse files
Merge pull request #34 from oslabs-beta/nathan
this commit will initialize the user database on first register
2 parents 3ad03be + 58153f0 commit 3757168

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

server/routes/dbRouter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
*/
55
import { Router, Request, Response } from 'express';
66
import dbController from '../controllers/dbController';
7-
7+
88
const router = Router();
99

1010
// Route handler: instantiates user and roles tables of database, adds role types
1111
router.get('/',
1212
dbController.createRoles,
1313
dbController.insertRoles,
1414
dbController.createTable,
15-
dbController.createAdminPassword,
16-
dbController.insertAdmin,
15+
// dbController.createAdminPassword,
16+
// dbController.insertAdmin,
1717
(req: Request, res: Response) => {
1818
return res.status(200).json('Database initialized successfully');
1919
}

src/components/SignUp.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import PasswordStrengthBar from 'react-password-strength-bar';
1717

1818
// Helper Functions
1919
import {
20+
checkDbInit,
2021
handleNewUser,
2122
checkPasswordLength,
2223
confirmPassword,
@@ -51,7 +52,10 @@ const SignUp = () => {
5152
className='settingsForm'
5253
component='form'
5354
autoComplete='off'
54-
onSubmit={(e: any) => handleNewUser(e, '1')}
55+
onSubmit={(e: any) => {
56+
checkDbInit();
57+
handleNewUser(e, '1');
58+
}}
5559
sx={{ color: 'blue' }}
5660
>
5761

@@ -84,7 +88,7 @@ const SignUp = () => {
8488
type={values.showPassword ? 'text' : 'password'}
8589
onChange={(e) => {
8690
checkPasswordLength();
87-
setValues({ ...values, password: e.target.value })
91+
setValues({ ...values, password: e.target.value });
8892
}}
8993
endAdornment={
9094
<InputAdornment position="end">
@@ -111,8 +115,8 @@ const SignUp = () => {
111115
type='password'
112116
required
113117
onChange={(e) => {
114-
setValues({ ...values, passwordConfirmation: e.target.value })
115-
confirmPassword()
118+
setValues({ ...values, passwordConfirmation: e.target.value });
119+
confirmPassword();
116120
}}
117121
sx={{
118122
m: 1
@@ -131,7 +135,7 @@ const SignUp = () => {
131135

132136
onChange={() => {
133137
const inputElement = (document.getElementById('signupPhone') as HTMLInputElement).value;
134-
checkPhone(inputElement)
138+
checkPhone(inputElement);
135139
}}
136140
sx={{
137141
m: 1
@@ -145,7 +149,7 @@ const SignUp = () => {
145149
variant='contained'
146150
size='medium'
147151
onClick={() => {
148-
history.back()
152+
history.back();
149153
}}
150154
sx={{
151155
m: 1
@@ -167,7 +171,7 @@ const SignUp = () => {
167171
</Box>
168172
</div>
169173
</div>
170-
)
171-
}
174+
);
175+
};
172176

173177
export default SignUp;

src/components/helper/newUserHelper.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ export const createNewUser = (email: string, username: string, password: string,
102102

103103
window.alert(`New user has been successfully created. \n\n
104104
An email with the user's credentials and login instructions has been sent to ${email}`);
105-
106-
}). then (() =>{
105+
106+
}).then(() => {
107107
getUpdatedUserList();
108108
})
109109
.catch((err) => {
@@ -133,6 +133,13 @@ export const getUpdatedUserList = () => {
133133
});
134134
};
135135

136-
export const updateUserList = (data: object[]) => {
136+
export const updateUserList = (data: object[]) => {
137137
store.dispatch(actions.updateUserList(data));
138138
};
139+
140+
export const checkDbInit = () => {
141+
fetch('http://localhost:3000/db')
142+
.then((response) => response.json())
143+
.then((data) => console.log(data))
144+
.catch((err) => { console.log(err); });
145+
};

0 commit comments

Comments
 (0)