Compare commits
No commits in common. "4b231538ed3b40967a96ac4cde5932843483e38a" and "378751ecedd9a1382aef05cbb15c3aa4636235a7" have entirely different histories.
4b231538ed
...
378751eced
2
.gitignore
vendored
@ -1,7 +1,7 @@
|
|||||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
# dependencies
|
# dependencies
|
||||||
node_modules
|
/node_modules
|
||||||
/.pnp
|
/.pnp
|
||||||
.pnp.js
|
.pnp.js
|
||||||
|
|
||||||
|
|||||||
@ -1,24 +0,0 @@
|
|||||||
use budgetdb
|
|
||||||
|
|
||||||
db.createCollection(“users”)
|
|
||||||
db.createCollection(“accounts”)
|
|
||||||
db.createCollection("budgets")
|
|
||||||
db.createCollection("budgetPeriods")
|
|
||||||
|
|
||||||
users: [{
|
|
||||||
_id: <id>
|
|
||||||
username: “maximx1”
|
|
||||||
}]
|
|
||||||
|
|
||||||
accounts: [{
|
|
||||||
name: amazon,
|
|
||||||
user: <id>
|
|
||||||
}]
|
|
||||||
|
|
||||||
budgets: [{
|
|
||||||
name: "main"
|
|
||||||
}]
|
|
||||||
|
|
||||||
budgetPeriods: [{
|
|
||||||
|
|
||||||
}]
|
|
||||||
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
|
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 9.4 KiB |
1866
server/package-lock.json
generated
@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "budget-demo-server",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "",
|
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
|
||||||
"start": "node src/server.js",
|
|
||||||
"dev": "nodemon src/server.js",
|
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
|
||||||
},
|
|
||||||
"author": "",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"express": "^4.18.2",
|
|
||||||
"mongodb": "^5.1.0",
|
|
||||||
"nodemon": "^2.0.20"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
const userStore = require('../stores/UserStore'),
|
|
||||||
accountStore = require('../stores/AccountStore');
|
|
||||||
|
|
||||||
exports.getUserAccounts = (username) => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
userStore.findUser(username).then((user) => {
|
|
||||||
accountStore.getAccountsForUser(user._id).then(accounts => {
|
|
||||||
resolve(accounts);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
const express = require('express'),
|
|
||||||
port = process.env.PORT || 3001,
|
|
||||||
app = express(),
|
|
||||||
userManager = require('./managers/UserManager'),
|
|
||||||
userStore = require('./stores/UserStore'),
|
|
||||||
accountStore = require('./stores/AccountStore');
|
|
||||||
|
|
||||||
app.get('/users', (req, res) => {
|
|
||||||
userStore.getUsers().then(data => res.json({ users: data }));
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get('/:username/accounts', (req, res) => {
|
|
||||||
const { username } = req.params;
|
|
||||||
userManager.getUserAccounts(username).then(data => res.json(data));
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get('/accounts', (req, res) => {
|
|
||||||
accountStore.getAccounts().then(data => res.json({ accounts: data }));
|
|
||||||
});
|
|
||||||
|
|
||||||
app.listen(port, () => {
|
|
||||||
console.log(`===> Server started: http://localhost:${port}/`);
|
|
||||||
});
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
const mongo = require('./Mongo');
|
|
||||||
|
|
||||||
exports.getAccounts = () => {
|
|
||||||
return mongo.listAll('accounts');
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.getAccountsForUser = (userId) => {
|
|
||||||
return mongo.find('accounts', { user: userId });
|
|
||||||
};
|
|
||||||
@ -1,44 +0,0 @@
|
|||||||
const { MongoClient } = require('mongodb'),
|
|
||||||
mongoUri = process.env.MONGOURI || 'mongodb://localhost:27017',
|
|
||||||
mongoDb = process.env.MONGODB || 'budgetdb';
|
|
||||||
|
|
||||||
const find = (collectionName, query) => {
|
|
||||||
return new Promise(async(resolve, reject) => {
|
|
||||||
const client = new MongoClient(mongoUri);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const db = client.db(mongoDb),
|
|
||||||
collection = db.collection(collectionName);
|
|
||||||
|
|
||||||
resolve(await collection.find(query).toArray());
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err);
|
|
||||||
reject(err);
|
|
||||||
} finally {
|
|
||||||
client.close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
exports.find = find;
|
|
||||||
|
|
||||||
exports.findOne = (collectionName, query) => {
|
|
||||||
return new Promise(async(resolve, reject) => {
|
|
||||||
const client = new MongoClient(mongoUri);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const db = client.db(mongoDb),
|
|
||||||
collection = db.collection(collectionName);
|
|
||||||
|
|
||||||
resolve(await collection.findOne(query));
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err);
|
|
||||||
reject(err);
|
|
||||||
} finally {
|
|
||||||
client.close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.listAll = (collectionName) => {
|
|
||||||
return find(collectionName);
|
|
||||||
};
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
const mongo = require('./Mongo');
|
|
||||||
|
|
||||||
exports.getUsers = () => {
|
|
||||||
return mongo.listAll('users');
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.findUser = (username) => {
|
|
||||||
return mongo.findOne('users', { username: username });
|
|
||||||
}
|
|
||||||
|
Before Width: | Height: | Size: 615 B After Width: | Height: | Size: 615 B |
|
Before Width: | Height: | Size: 710 B After Width: | Height: | Size: 710 B |