Skip to content

Commit

Permalink
added transaction support from mongoose
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiebones committed Mar 17, 2021
1 parent be3e111 commit 2a755a1
Show file tree
Hide file tree
Showing 27 changed files with 274 additions and 153 deletions.
21 changes: 19 additions & 2 deletions client/src/components/createNewSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import NumberFormat from "react-number-format";
import styled from "styled-components";

const SessionStyles = styled.div`
/* input[type="range"]::-webkik-slider-runnable-track{
/* input[type="range"]::-webkik-slider-runnable-track{
width: 100%;
height: 8.4px;
cursor: pointer;
Expand Down Expand Up @@ -98,6 +98,7 @@ export default (props) => {
const [loadingState, setLoadingState] = useState(false);
const [bedspaceStats, setBedSpaceStats] = useState(null);
const [sessionText, setSessionText] = useState("");
const [sessionShouldUpdate, setSessionShouldUpdate] = useState(false);

const subtractTwoNumbers = (a, b) => {
const answer = +a - +b;
Expand Down Expand Up @@ -351,7 +352,7 @@ export default (props) => {
levelArray.push(obj);
});
let confirmDetails = window.confirm(
`session: ${session} \n ${facultyConfirmation} \n ${levelConfirmation}`
`session: ${session} \n ${facultyConfirmation} \n ${levelConfirmation} \n should update level: ${sessionShouldUpdate}`
);

if (!confirmDetails) {
Expand All @@ -365,6 +366,7 @@ export default (props) => {
facultyAllocation: facultyArray,
levelAllocation: levelArray,
active: false,
shouldUpdateLevel: sessionShouldUpdate,
};
await sessionMutation({
variables: {
Expand Down Expand Up @@ -482,6 +484,21 @@ export default (props) => {
</select>
</div>

<div className="form-group form-check">
<input
type="checkbox"
className="form-check-input"
value={sessionShouldUpdate}
checked={sessionShouldUpdate}
onChange={() =>
setSessionShouldUpdate((prevValue) => !prevValue)
}
/>
<label className="form-check-label">
Update Student Level
</label>
</div>

<div>
{facComponents.length > 0 &&
facComponents.map(({ faculty, facultyId }) => {
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const Login = (props) => {
setSubmitted(!submitted);
if (accessLevel === "super-admin") {
history.push("/admin/dashboard");
} else if (accessLevel === "student") {
} else if (accessLevel === "normal") {
history.push("/dashboard");
}
}
Expand Down
21 changes: 12 additions & 9 deletions client/src/components/studentAccountCreation.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const StudentAccountCreation = (props) => {

const [password, setPassword] = useState("");
const [confirmPassword, setconfirmPassword] = useState("");
const [errors, setErrors] = useState([]);
const [errors, setErrors] = useState(null);
const [submitted, setSubmitted] = useState(false);
const [loading, setLoading] = useState(false);
//const [file, setFile] = useState("");
Expand All @@ -50,10 +50,8 @@ const StudentAccountCreation = (props) => {

useEffect(() => {
if (createNewAccountResult.error) {
let errorArray = [];
setSubmitted(!submitted);
errorArray = ExtractError(createNewAccountResult.error);
setErrors(errorArray);
setErrors(createNewAccountResult.error);
setLoading(!loading);
}

Expand Down Expand Up @@ -92,11 +90,9 @@ const StudentAccountCreation = (props) => {
window.alert("password does not match");
return;
}

const studentObject = { ...student };
studentObject.password = password;
setSubmitted(!submitted);
student.password = password;
setLoading(!loading);
await createNewAccount({
variables: {
Expand All @@ -110,7 +106,10 @@ const StudentAccountCreation = (props) => {

return (
<CreateAccountStyles>
<ErrorDisplay errors={errors} />
<div className="text-center">
{errors && <p className="text-danger lead">{errors.message}</p>}
</div>

<form
onSubmit={submitStudentDataToDatabase}
// action="/upload_studentData"
Expand All @@ -130,7 +129,9 @@ const StudentAccountCreation = (props) => {
<div className="float-md-right">
<div className="preview-images">
<img
src={`http://uniuyo.edu.ng/eportals/passports/${student && student.profileImage}`}
src={`http://uniuyo.edu.ng/eportals/passports/${
student && student.profileImage
}`}
className="passport"
id="passportImage"
style={{ width: 200 + "px", height: 200 + "px" }}
Expand Down Expand Up @@ -217,7 +218,9 @@ const StudentAccountCreation = (props) => {
readOnly
type="text"
className="form-control"
value={student.currentLevel && student.currentLevel.toUpperCase()}
value={
student.currentLevel && student.currentLevel.toUpperCase()
}
/>
</div>

Expand Down
28 changes: 21 additions & 7 deletions client/src/components/updateSessionNew.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default ({ history, match }) => {
const [levelComponents, setLevelComponents] = useState([]);
const [submitted, setSubmitted] = useState(false);
const [sessionId, setSessionId] = useState("");
const [sessionShouldUpdate, setSessionShouldUpdate] = useState(false);

const [sessionMutation, sessionResult] = useMutation(UpdateSessionMutation);

Expand All @@ -61,7 +62,7 @@ export default ({ history, match }) => {
const sessionData = getSessionResult.data.getSessionById;
const {
id,

shouldUpdateLevel,
facultyAllocation,
levelAllocation,
} = sessionData;
Expand All @@ -85,6 +86,7 @@ export default ({ history, match }) => {
setFacComponents(facultyAllocationComponentsArray);
setLevelComponents(levelAllocationComponentsArray);
setSessionId(id);
setSessionShouldUpdate(shouldUpdateLevel);
setFacValue(() =>
filterArrayForTotal(facultyAllocationComponentsArray, null, "faculty")
);
Expand Down Expand Up @@ -245,7 +247,7 @@ export default ({ history, match }) => {
levelArray.push(obj);
});
let confirmDetails = window.confirm(
` ${facultyConfirmation} \n ${levelConfirmation}`
` ${facultyConfirmation} \n ${levelConfirmation} \n should update level: ${sessionShouldUpdate}`
);

if (!confirmDetails) {
Expand All @@ -254,13 +256,14 @@ export default ({ history, match }) => {
}

try {
let varableToSend = {
let variableToSend = {
facultyAllocation: facultyArray,
levelAllocation: levelArray,
shouldUpdateLevel: sessionShouldUpdate,
};
await sessionMutation({
variables: {
input: varableToSend,
input: variableToSend,
sessionId: sessionId,
},
});
Expand Down Expand Up @@ -299,9 +302,7 @@ export default ({ history, match }) => {
<form onSubmit={handleSessionSubmit}>
<div className="row">
<div className="col-md-6 offset-md-3">
<p className="lead text-center">
updating academic session
</p>
<p className="lead text-center">updating academic session</p>
<div className="form-group">
<label htmlFor="facultySelect">Faculties</label>
<select
Expand Down Expand Up @@ -339,6 +340,19 @@ export default ({ history, match }) => {
<option value="other years">other years student</option>
</select>
</div>

<div className="form-group form-check">
<input
type="checkbox"
className="form-check-input"
value={sessionShouldUpdate}
checked={sessionShouldUpdate}
onChange={() =>
setSessionShouldUpdate((prevValue) => !prevValue)
}
/>
<label className="form-check-label">Update Student Level</label>
</div>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion client/src/graphql/mutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ const DashStudentFreeRoom = gql`

//SendSMSToStudents
const SendSMSToStudents = gql`
mutation SendSMSToStudents($roomIds: RoomIDS!, $sms: String!) {
mutation SendSMSToStudents($roomIds: RoomIDInput!, $sms: String!) {
sendMessage(roomIds: $roomIds, sms: $sms) {
status
totalMessage
Expand Down
2 changes: 2 additions & 0 deletions client/src/graphql/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ const AllSessions = gql`
}
session
active
shouldUpdateLevel
}
}
`;
Expand Down Expand Up @@ -284,6 +285,7 @@ const GetSessionById = gql`
percentAllocation
}
active
shouldUpdateLevel
}
}
`;
Expand Down
Loading

0 comments on commit 2a755a1

Please sign in to comment.