getting org members
This commit is contained in:
@@ -37,11 +37,11 @@ export default class AuthHandler {
|
||||
const email = payload.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) => {
|
||||
return db.networks.get(c.to)
|
||||
})
|
||||
console.log(userOrgs)
|
||||
|
||||
res.send({ email: user.email, name: user.firstName + " " + user.lastName, networks: userOrgs});
|
||||
} catch (e) {
|
||||
console.error("Error getting profile: ", e)
|
||||
@@ -62,7 +62,7 @@ export default class AuthHandler {
|
||||
res.status(400).json({ error: 'Incorrect password.' });
|
||||
} else {
|
||||
const payload = { email: foundUser.email };
|
||||
console.log(payload)
|
||||
console.log("login: ", payload)
|
||||
const secret = process.env.JWT_SECRET;
|
||||
const options = { expiresIn: "2h" };
|
||||
const token = jwt.sign(payload, secret, options);
|
||||
|
||||
@@ -15,6 +15,5 @@ export default class Edge {
|
||||
// let
|
||||
}
|
||||
}
|
||||
console.log(fromID)
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,20 @@ export default class MEMBER_IN_NETWORK {
|
||||
})
|
||||
.strict()
|
||||
|
||||
getByFrom(fromID) {
|
||||
getByMember(stringID) {
|
||||
let result = []
|
||||
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])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,8 +39,20 @@ export default class Member {
|
||||
}
|
||||
}
|
||||
|
||||
get(id) {
|
||||
return this.entries[this.ids[id]]
|
||||
getByNetwork(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) {
|
||||
@@ -51,15 +63,4 @@ export default class Member {
|
||||
}
|
||||
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) {
|
||||
let id = stringID.split("-")[1]
|
||||
let index = this.indices[0] + (id - 1)
|
||||
console.log("networkget", index, id, global.db.nodes[index-1])
|
||||
return global.db.nodes[index]
|
||||
}
|
||||
|
||||
|
||||
@@ -37,13 +37,16 @@ class Server {
|
||||
/* Site */
|
||||
router.post('/free', this.newUserSubmission)
|
||||
router.get('/db/images/*', this.getUserImage)
|
||||
router.get('/app/comaldata', this.getComalData)
|
||||
router.get('/app/orgdata/*', this.getOrgData)
|
||||
router.get('/*', this.get)
|
||||
return router
|
||||
}
|
||||
|
||||
getComalData = async (req, res, next) => {
|
||||
getOrgData = async (req, res, next) => {
|
||||
try {
|
||||
const networkId = req.params[0]
|
||||
|
||||
if(networkId === "1") {
|
||||
const pathOne = path.join(this.ComalPath, "db", "join.json");
|
||||
const pathTwo = path.join(this.ComalPath, "db", "contact.json");
|
||||
|
||||
@@ -54,11 +57,20 @@ class Server {
|
||||
|
||||
const join = joinRaw.trim() ? JSON.parse(joinRaw) : [];
|
||||
const contact = contactRaw.trim() ? JSON.parse(contactRaw) : [];
|
||||
const members = db.members.getByNetwork(networkId)
|
||||
|
||||
res.json({
|
||||
join,
|
||||
contact
|
||||
contact,
|
||||
members
|
||||
});
|
||||
} else {
|
||||
const members = db.members.getByNetwork(networkId)
|
||||
|
||||
res.json({
|
||||
members
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
|
||||
@@ -97,8 +97,9 @@ async function setCurrentNetwork() {
|
||||
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()
|
||||
console.log(json)
|
||||
window.comalData = json
|
||||
|
||||
return path
|
||||
|
||||
Reference in New Issue
Block a user