working with db, docker working, small error with personal data
This commit is contained in:
@@ -16,8 +16,7 @@ import Socket from './ws/ws.js'
|
||||
import Database from "./db/db.js"
|
||||
import AuthHandler from './auth.js';
|
||||
import PaymentsHandler from "./payments.js"
|
||||
|
||||
import parchment from '../apps/parchment/index.js';
|
||||
import sql from "./db/sql.js"
|
||||
|
||||
class Server {
|
||||
db;
|
||||
@@ -64,21 +63,14 @@ class Server {
|
||||
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");
|
||||
|
||||
const [joinRaw, contactRaw] = await Promise.all([
|
||||
fs.promises.readFile(pathOne, "utf8"),
|
||||
fs.promises.readFile(pathTwo, "utf8")
|
||||
if (networkId === "1") {
|
||||
const [join, contact, members, stripeMembers] = await Promise.all([
|
||||
sql`SELECT * FROM org_1.join_form ORDER BY time DESC`,
|
||||
sql`SELECT * FROM org_1.contact_form ORDER BY time DESC`,
|
||||
db.members.getByNetwork(networkId),
|
||||
payments.getCustomers(networkId)
|
||||
]);
|
||||
|
||||
const join = joinRaw.trim() ? JSON.parse(joinRaw) : [];
|
||||
const contact = contactRaw.trim() ? JSON.parse(contactRaw) : [];
|
||||
const members = db.members.getByNetwork(networkId)
|
||||
let stripeMembers = await payments.getCustomers(networkId)
|
||||
// console.log("stripemenbers: ", stripeMembers)
|
||||
|
||||
|
||||
res.json({
|
||||
join,
|
||||
contact,
|
||||
@@ -86,7 +78,7 @@ class Server {
|
||||
stripeMembers
|
||||
});
|
||||
} else {
|
||||
const members = db.members.getByNetwork(networkId)
|
||||
const members = await db.members.getByNetwork(networkId)
|
||||
|
||||
res.json({
|
||||
members
|
||||
@@ -225,6 +217,34 @@ class Server {
|
||||
next();
|
||||
}
|
||||
|
||||
async mountApps(app) {
|
||||
const appsDir = path.join(__dirname, '../apps');
|
||||
|
||||
if (!fs.existsSync(appsDir)) {
|
||||
fs.mkdirSync(appsDir, { recursive: true });
|
||||
console.log('created apps directory');
|
||||
return;
|
||||
}
|
||||
|
||||
const appFolders = fs.readdirSync(appsDir);
|
||||
|
||||
for (const folder of appFolders) {
|
||||
const indexPath = path.join(appsDir, folder, 'index.js');
|
||||
if (!fs.existsSync(indexPath)) continue;
|
||||
|
||||
const module = await import(indexPath);
|
||||
const appModule = module.default;
|
||||
|
||||
if (appModule?.type === 'app') {
|
||||
app.use(`/apps/${folder}`, appModule.app);
|
||||
console.log(`mounted app: /apps/${folder}`);
|
||||
} else if (appModule?.type === 'router') {
|
||||
app.use(`/apps/${folder}`, appModule.router);
|
||||
console.log(`mounted router: /apps/${folder}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.db = new Database()
|
||||
this.auth = new AuthHandler()
|
||||
@@ -265,7 +285,7 @@ class Server {
|
||||
app.use(this.logRequest);
|
||||
app.use(this.logResponse);
|
||||
|
||||
app.use('/apps/parchment', parchment.app);
|
||||
this.mountApps(app)
|
||||
|
||||
let router = express.Router();
|
||||
this.registerRoutes(router)
|
||||
|
||||
Reference in New Issue
Block a user