getting org members
This commit is contained in:
@@ -37,11 +37,11 @@ export default class AuthHandler {
|
|||||||
const email = payload.email;
|
const email = payload.email;
|
||||||
|
|
||||||
const user = db.members.getByEmail(email);
|
const user = db.members.getByEmail(email);
|
||||||
let connections = db.MEMBER_IN_NETWORK.getByFrom(db.members.prefix + "-" + user.id)
|
let connections = db.MEMBER_IN_NETWORK.getByMember(db.members.prefix + "-" + user.id)
|
||||||
let userOrgs = connections.map((c) => {
|
let userOrgs = connections.map((c) => {
|
||||||
return db.networks.get(c.to)
|
return db.networks.get(c.to)
|
||||||
})
|
})
|
||||||
console.log(userOrgs)
|
|
||||||
res.send({ email: user.email, name: user.firstName + " " + user.lastName, networks: userOrgs});
|
res.send({ email: user.email, name: user.firstName + " " + user.lastName, networks: userOrgs});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Error getting profile: ", e)
|
console.error("Error getting profile: ", e)
|
||||||
@@ -62,7 +62,7 @@ export default class AuthHandler {
|
|||||||
res.status(400).json({ error: 'Incorrect password.' });
|
res.status(400).json({ error: 'Incorrect password.' });
|
||||||
} else {
|
} else {
|
||||||
const payload = { email: foundUser.email };
|
const payload = { email: foundUser.email };
|
||||||
console.log(payload)
|
console.log("login: ", payload)
|
||||||
const secret = process.env.JWT_SECRET;
|
const secret = process.env.JWT_SECRET;
|
||||||
const options = { expiresIn: "2h" };
|
const options = { expiresIn: "2h" };
|
||||||
const token = jwt.sign(payload, secret, options);
|
const token = jwt.sign(payload, secret, options);
|
||||||
|
|||||||
@@ -15,6 +15,5 @@ export default class Edge {
|
|||||||
// let
|
// let
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(fromID)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,10 +17,20 @@ export default class MEMBER_IN_NETWORK {
|
|||||||
})
|
})
|
||||||
.strict()
|
.strict()
|
||||||
|
|
||||||
getByFrom(fromID) {
|
getByMember(stringID) {
|
||||||
let result = []
|
let result = []
|
||||||
for(let i = this.indices[0]; i < this.indices[1]; i++) {
|
for(let i = this.indices[0]; i < this.indices[1]; i++) {
|
||||||
if(global.db.edges[i].from === fromID) {
|
if(global.db.edges[i].from === stringID) {
|
||||||
|
result.push(global.db.edges[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
getByNetwork(id) {
|
||||||
|
let result = []
|
||||||
|
for(let i = this.indices[0]; i < this.indices[1]; i++) {
|
||||||
|
if(global.db.edges[i].to === `${global.db.networks.prefix}-${id}`) {
|
||||||
result.push(global.db.edges[i])
|
result.push(global.db.edges[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,8 +39,20 @@ export default class Member {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get(id) {
|
getByNetwork(id) {
|
||||||
return this.entries[this.ids[id]]
|
let connections = db.MEMBER_IN_NETWORK.getByNetwork(id)
|
||||||
|
let members = []
|
||||||
|
connections.forEach((conn) => {
|
||||||
|
members.push(this.getByID(conn.from))
|
||||||
|
})
|
||||||
|
return members
|
||||||
|
}
|
||||||
|
|
||||||
|
getByID(id) {
|
||||||
|
if(typeof id === 'string') {
|
||||||
|
id = id.split("-")[1]
|
||||||
|
}
|
||||||
|
return global.db.nodes[this.indices[0] + id - 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
getByEmail(email) {
|
getByEmail(email) {
|
||||||
@@ -51,15 +63,4 @@ export default class Member {
|
|||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
getIDFromEmail(email) {
|
|
||||||
let index = 0
|
|
||||||
for(let i=0; i<this.entries.length; i++) {
|
|
||||||
if(this.entries[i].email === email) {
|
|
||||||
index = i
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Object.entries(this.ids)[index][0]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,6 @@ export default class Network {
|
|||||||
get(stringID) {
|
get(stringID) {
|
||||||
let id = stringID.split("-")[1]
|
let id = stringID.split("-")[1]
|
||||||
let index = this.indices[0] + (id - 1)
|
let index = this.indices[0] + (id - 1)
|
||||||
console.log("networkget", index, id, global.db.nodes[index-1])
|
|
||||||
return global.db.nodes[index]
|
return global.db.nodes[index]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,28 +37,40 @@ class Server {
|
|||||||
/* Site */
|
/* Site */
|
||||||
router.post('/free', this.newUserSubmission)
|
router.post('/free', this.newUserSubmission)
|
||||||
router.get('/db/images/*', this.getUserImage)
|
router.get('/db/images/*', this.getUserImage)
|
||||||
router.get('/app/comaldata', this.getComalData)
|
router.get('/app/orgdata/*', this.getOrgData)
|
||||||
router.get('/*', this.get)
|
router.get('/*', this.get)
|
||||||
return router
|
return router
|
||||||
}
|
}
|
||||||
|
|
||||||
getComalData = async (req, res, next) => {
|
getOrgData = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const pathOne = path.join(this.ComalPath, "db", "join.json");
|
const networkId = req.params[0]
|
||||||
const pathTwo = path.join(this.ComalPath, "db", "contact.json");
|
|
||||||
|
|
||||||
const [joinRaw, contactRaw] = await Promise.all([
|
if(networkId === "1") {
|
||||||
fs.promises.readFile(pathOne, "utf8"),
|
const pathOne = path.join(this.ComalPath, "db", "join.json");
|
||||||
fs.promises.readFile(pathTwo, "utf8")
|
const pathTwo = path.join(this.ComalPath, "db", "contact.json");
|
||||||
]);
|
|
||||||
|
const [joinRaw, contactRaw] = await Promise.all([
|
||||||
const join = joinRaw.trim() ? JSON.parse(joinRaw) : [];
|
fs.promises.readFile(pathOne, "utf8"),
|
||||||
const contact = contactRaw.trim() ? JSON.parse(contactRaw) : [];
|
fs.promises.readFile(pathTwo, "utf8")
|
||||||
|
]);
|
||||||
res.json({
|
|
||||||
join,
|
const join = joinRaw.trim() ? JSON.parse(joinRaw) : [];
|
||||||
contact
|
const contact = contactRaw.trim() ? JSON.parse(contactRaw) : [];
|
||||||
});
|
const members = db.members.getByNetwork(networkId)
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
join,
|
||||||
|
contact,
|
||||||
|
members
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const members = db.members.getByNetwork(networkId)
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
members
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
next(err);
|
next(err);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,8 +97,9 @@ async function setCurrentNetwork() {
|
|||||||
path += defaultApp.toLowerCase()
|
path += defaultApp.toLowerCase()
|
||||||
}
|
}
|
||||||
|
|
||||||
let appData = await fetch("/app/comaldata", {method: "GET"})
|
let appData = await fetch("/app/orgdata/" + defaultNetwork.id, {method: "GET"})
|
||||||
let json = await appData.json()
|
let json = await appData.json()
|
||||||
|
console.log(json)
|
||||||
window.comalData = json
|
window.comalData = json
|
||||||
|
|
||||||
return path
|
return path
|
||||||
|
|||||||
Reference in New Issue
Block a user