Skip to content

Commit

Permalink
group deactivate and activate
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiebones committed Mar 29, 2021
1 parent 2f5f6e6 commit 1a3edb6
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 8 deletions.
12 changes: 7 additions & 5 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,25 +248,27 @@ const App = (props) => {
component={StudentAccountCreation}
/>
{/* Admin routes from here */}

<AuthorizedComponent
path="/admin/view_transactions"
path="/admin/student_account"
exact
component={AdminViewTransaction}
component={SearchUserAccount}
authenticated={authenticated}
currentUser={currentUser}
authorizedRole={["super-admin", "admin"]}
{...props}
/>

<AuthorizedComponent
path="/admin/student_account"
path="/admin/dashboard"
exact
component={SearchUserAccount}
component={AdminDashboard}
authenticated={authenticated}
currentUser={currentUser}
authorizedRole={["super-admin", "admin"]}
{...props}
/>

<AuthorizedComponent
path="/admin/view_transactions"
exact
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/adminViewTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const AdminViewTransaction = () => {
const [errors, setErrors] = useState(null);
const [noData, setNoData] = useState(null);
const [selectedColumn, setSelectedColumn] = useState([]);
const [submitted, setSubmitted ] = useState(false);
const [submitted, setSubmitted] = useState(false);
const [transQuery, transResult] = useLazyQuery(GetSuccessFullTransactions, {
variables: {
session: selectedSession,
Expand Down
58 changes: 56 additions & 2 deletions client/src/components/searchStudentAccount.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React, { useState, useEffect } from "react";
import { useLazyQuery, useMutation } from "@apollo/client";
import { ActivateDeactivateUser } from "../graphql/mutation";
import {
ActivateDeactivateUser,
ActivateGroupUsers,
} from "../graphql/mutation";
import { SearchUserAccount } from "../graphql/queries";
import styled from "styled-components";
import Loading from "./common/loading";
Expand All @@ -20,10 +23,14 @@ const SearchStudentAccount = () => {
ActivateDeactivateUser
);

const [activateGroupUser, activateGroupResult] = useMutation(
ActivateGroupUsers
);

useEffect(() => {
if (searchResult.data) {
const users = searchResult.data.searchStudentAccount;

if (users.length > 0) {
setUsers(users);
setNoData(false);
Expand All @@ -48,6 +55,17 @@ const SearchStudentAccount = () => {
}
}, [activateResult.data, activateResult.error]);

useEffect(() => {
if (activateGroupResult.data) {
setSubmitted(!submitted);
window.alert("successful");
}
if (activateResult.error) {
setSubmitted(!submitted);
setErrors(activateGroupResult.error);
}
}, [activateGroupResult.data, activateGroupResult.error]);

const performSearchInput = (e) => {
const value = e.target.value;
setRegNumber(value);
Expand Down Expand Up @@ -83,6 +101,26 @@ const SearchStudentAccount = () => {
});
} catch (error) {}
};

const handleActivate = () => {
setSubmitted(!submitted)
try {
activateGroupUser({
variables: {
groupReg: regNumber,
},
refetchQueries: [
{
query: SearchUserAccount,
variables: {
regNumber: regNumber,
},
},
],
});
} catch (error) {}
};

return (
<SearchRecordsStyles>
<div className="row">
Expand Down Expand Up @@ -115,6 +153,22 @@ const SearchStudentAccount = () => {
<div className="text-center">
{noData && <p className="lead">Your query returned no result!</p>}

{users.length > 1 && (
<div className="text-right">
<button
disabled={submitted}
className="btn btn-warning btn-sm"
onClick={handleActivate}
>
{submitted
? "please wait...."
: "activate/deactivate account"}
</button>
<br />
<br />
</div>
)}

{users.length > 0 && (
<UsersTable
users={users}
Expand Down
9 changes: 9 additions & 0 deletions client/src/graphql/mutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,16 @@ const ActivateDeactivateUser = gql`
}
`;

//

const ActivateGroupUsers = gql`
mutation activateGroupUser($groupReg: String!) {
activateUserInGroups(groupReg: $groupReg)
}
`;

export {
ActivateGroupUsers,
ActivateDeactivateUser,
SendSMSToStudents,
EditHall,
Expand Down
1 change: 1 addition & 0 deletions server/logs/app.log
Original file line number Diff line number Diff line change
Expand Up @@ -637,3 +637,4 @@
{"error":{"code":"EADDRINUSE","errno":"EADDRINUSE","syscall":"listen","address":"::","port":8000},"level":"error","message":"uncaughtException: listen EADDRINUSE: address already in use :::8000\nError: listen EADDRINUSE: address already in use :::8000\n at Server.setupListenHandle [as _listen2] (net.js:1316:16)\n at listenInCluster (net.js:1364:12)\n at Server.listen (net.js:1450:7)\n at StartUp (/usr/app/src/index.js:111:14)\n at processTicksAndRejections (internal/process/task_queues.js:97:5)","stack":"Error: listen EADDRINUSE: address already in use :::8000\n at Server.setupListenHandle [as _listen2] (net.js:1316:16)\n at listenInCluster (net.js:1364:12)\n at Server.listen (net.js:1450:7)\n at StartUp (/usr/app/src/index.js:111:14)\n at processTicksAndRejections (internal/process/task_queues.js:97:5)","exception":true,"date":"Sat Mar 27 2021 11:05:40 GMT+0000 (Coordinated Universal Time)","process":{"pid":1502,"uid":0,"gid":0,"cwd":"/usr/app","execPath":"/usr/local/bin/node","version":"v12.20.1","argv":["node","/usr/app/src/index.js"],"memoryUsage":{"rss":627601408,"heapTotal":579420160,"heapUsed":519171224,"external":20574047,"arrayBuffers":18506828}},"os":{"loadavg":[4.53,4.23,3.81],"uptime":353483},"trace":[{"column":16,"file":"net.js","function":"Server.setupListenHandle [as _listen2]","line":1316,"method":"setupListenHandle [as _listen2]","native":false},{"column":12,"file":"net.js","function":"listenInCluster","line":1364,"method":null,"native":false},{"column":7,"file":"net.js","function":"Server.listen","line":1450,"method":"listen","native":false},{"column":14,"file":"/usr/app/src/index.js","function":"StartUp","line":111,"method":null,"native":false},{"column":5,"file":"internal/process/task_queues.js","function":"processTicksAndRejections","line":97,"method":null,"native":false}]}
{"error":{"code":"EADDRINUSE","errno":"EADDRINUSE","syscall":"listen","address":"::","port":8000},"level":"error","message":"uncaughtException: listen EADDRINUSE: address already in use :::8000\nError: listen EADDRINUSE: address already in use :::8000\n at Server.setupListenHandle [as _listen2] (net.js:1316:16)\n at listenInCluster (net.js:1364:12)\n at Server.listen (net.js:1450:7)\n at StartUp (/usr/app/src/index.js:111:14)\n at processTicksAndRejections (internal/process/task_queues.js:97:5)","stack":"Error: listen EADDRINUSE: address already in use :::8000\n at Server.setupListenHandle [as _listen2] (net.js:1316:16)\n at listenInCluster (net.js:1364:12)\n at Server.listen (net.js:1450:7)\n at StartUp (/usr/app/src/index.js:111:14)\n at processTicksAndRejections (internal/process/task_queues.js:97:5)","exception":true,"date":"Sun Mar 28 2021 18:50:12 GMT+0000 (Coordinated Universal Time)","process":{"pid":2378,"uid":0,"gid":0,"cwd":"/usr/app","execPath":"/usr/local/bin/node","version":"v12.20.1","argv":["node","/usr/app/src/index.js"],"memoryUsage":{"rss":565899264,"heapTotal":412860416,"heapUsed":309370440,"external":20574680,"arrayBuffers":18507461}},"os":{"loadavg":[5.52,4.21,3.48],"uptime":467755},"trace":[{"column":16,"file":"net.js","function":"Server.setupListenHandle [as _listen2]","line":1316,"method":"setupListenHandle [as _listen2]","native":false},{"column":12,"file":"net.js","function":"listenInCluster","line":1364,"method":null,"native":false},{"column":7,"file":"net.js","function":"Server.listen","line":1450,"method":"listen","native":false},{"column":14,"file":"/usr/app/src/index.js","function":"StartUp","line":111,"method":null,"native":false},{"column":5,"file":"internal/process/task_queues.js","function":"processTicksAndRejections","line":97,"method":null,"native":false}]}
{"error":{"code":"EADDRINUSE","errno":"EADDRINUSE","syscall":"listen","address":"::","port":8000},"level":"error","message":"uncaughtException: listen EADDRINUSE: address already in use :::8000\nError: listen EADDRINUSE: address already in use :::8000\n at Server.setupListenHandle [as _listen2] (net.js:1316:16)\n at listenInCluster (net.js:1364:12)\n at Server.listen (net.js:1450:7)\n at StartUp (/usr/app/src/index.js:111:14)\n at processTicksAndRejections (internal/process/task_queues.js:97:5)","stack":"Error: listen EADDRINUSE: address already in use :::8000\n at Server.setupListenHandle [as _listen2] (net.js:1316:16)\n at listenInCluster (net.js:1364:12)\n at Server.listen (net.js:1450:7)\n at StartUp (/usr/app/src/index.js:111:14)\n at processTicksAndRejections (internal/process/task_queues.js:97:5)","exception":true,"date":"Sun Mar 28 2021 18:55:52 GMT+0000 (Coordinated Universal Time)","process":{"pid":8686,"uid":0,"gid":0,"cwd":"/usr/app","execPath":"/usr/local/bin/node","version":"v12.20.1","argv":["node","/usr/app/src/index.js"],"memoryUsage":{"rss":1779183616,"heapTotal":1601847296,"heapUsed":1557823480,"external":47542903,"arrayBuffers":18515020}},"os":{"loadavg":[6.09,4.66,3.78],"uptime":468095},"trace":[{"column":16,"file":"net.js","function":"Server.setupListenHandle [as _listen2]","line":1316,"method":"setupListenHandle [as _listen2]","native":false},{"column":12,"file":"net.js","function":"listenInCluster","line":1364,"method":null,"native":false},{"column":7,"file":"net.js","function":"Server.listen","line":1450,"method":"listen","native":false},{"column":14,"file":"/usr/app/src/index.js","function":"StartUp","line":111,"method":null,"native":false},{"column":5,"file":"internal/process/task_queues.js","function":"processTicksAndRejections","line":97,"method":null,"native":false}]}
{"error":{"errno":"ECONNREFUSED","code":"ECONNREFUSED","syscall":"connect","address":"192.168.0.3","port":6379},"level":"error","message":"uncaughtException: Redis connection to redis_cache:6379 failed - connect ECONNREFUSED 192.168.0.3:6379\nError: Redis connection to redis_cache:6379 failed - connect ECONNREFUSED 192.168.0.3:6379\n at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16)","stack":"Error: Redis connection to redis_cache:6379 failed - connect ECONNREFUSED 192.168.0.3:6379\n at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16)","exception":true,"date":"Mon Mar 29 2021 08:03:42 GMT+0000 (Coordinated Universal Time)","process":{"pid":62,"uid":0,"gid":0,"cwd":"/usr/app","execPath":"/usr/local/bin/node","version":"v12.20.1","argv":["node","/usr/app/src/index.js"],"memoryUsage":{"rss":440717312,"heapTotal":295014400,"heapUsed":292567848,"external":20597012,"arrayBuffers":18531081}},"os":{"loadavg":[4.08,3.65,3.39],"uptime":515366},"trace":[{"column":16,"file":"net.js","function":"TCPConnectWrap.afterConnect [as oncomplete]","line":1144,"method":"afterConnect [as oncomplete]","native":false}]}
14 changes: 14 additions & 0 deletions server/src/resolvers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ export default {
return true;
}
),
activateUserInGroups: combineResolvers(
isAuthenticated,
isAdmin,
async (parent, { groupReg }, { fastConn }) => {
const docsToUpdate = await fastConn.models.User.find({
regNumber: { $regex: groupReg, $options: "i" },
});
docsToUpdate.map(async (doc) => {
doc.active = !doc.active;
await doc.save();
});
return true;
}
),
},
LoginUserResult: {
__resolveType(obj) {
Expand Down
1 change: 1 addition & 0 deletions server/src/schema/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default gql`
role: String!
): Boolean
activateDeactivateUser(userId: String!): Boolean
activateUserInGroups(groupReg: String!): Boolean
}
union LoginUserResult = User | Error
Expand Down

0 comments on commit 1a3edb6

Please sign in to comment.