initial commit

This commit is contained in:
OddlyTimbot 2025-02-20 10:00:56 -05:00
parent d7ff07be1d
commit 2a2e55242c
6 changed files with 1517 additions and 0 deletions

17
db.js Normal file
View File

@ -0,0 +1,17 @@
const { MongoClient }= require('mongodb');
let dbConnection
module.exports = {
connectToDB: (cb)=>{
MongoClient.connect('mongodb://localhost:27017/makerspace').then((client)=>{
dbConnection = client.db()
return cb()
})
.catch(err =>{
console.log(err)
return cb(err)
})
},
getDB: ()=> dbConnection
}

110
index.js Normal file
View File

@ -0,0 +1,110 @@
const GhostAdminAPI = require('@tryghost/admin-api');
const path = require('path');
const express = require('express');
const { connectToDB, getDB} = require('./db')
const { ObjectId }=require('mongodb')
const cors = require('cors');
let db
// Your GHOST API config
/*
const api = new GhostAdminAPI({
url: 'https://members.ttlmakerspace.com',
version: "v5.0",
key: process.env.GHOST_KEY
});
api.members.browse().then((members) => {
members.forEach((member) => {
console.log(JSON.stringify(member, null, 2))
});
}).catch((err) => {
console.error(err);
});
*/
//////API//////////
///Timmy Tester uuid: b071b92a-f812-4f0a-b9fc-de6bd8e76562
const app = express()
app.use(cors());
app.use(express.json() )
connectToDB((err)=>{
if(!err){
app.listen(3000, ()=>{
console.log("app listening on 3000")
})
db = getDB()
}
})
//all members
app.get('/members',(req,res)=>{
let members=[]
db.collection('members').find()
.forEach(member=>{
members.push(member)
})
.then(()=>{
res.status(200).json(members)
})
.catch((err)=>{
res.status(500).json({error:"Could not get members"})
})
})
//one member
app.get('/member/:uuid',(req,res)=>{
db.collection('members').findOne({uuid:req.params.uuid})
.then((member)=>{
res.status(200).json(member)
})
.catch((err)=>{
res.status(500).json({error:"Could not get member"})
})
})
//add one member
app.post('/member',(req,res)=>{
const recipe = req.body
db.collection('members')
.insertOne(recipe)
.then(result =>{
res.status(201).json(result)
})
.catch(err => {
res.status(500).json({err: 'Could not create member'})
})
})
//update one member
app.patch('/member/:uuid', (req, res)=>{
const updates = req.body
const myId = req.params.uuid
console.log('Object id is valid')
db.collection('members')
.updateOne({uuid: myId}, {$set: updates})
.then(result =>{
res.status(200).json(result)
})
.catch(err =>{
res.status(500).json({error: 'Could not update'})
})
})
//get a locker
app.patch('/member/locker/:uuid', (req, res)=>{
const locker = req.body
const myId = req.params.uuid
locker.date=new Date(locker.date)
db.collection('members')
.updateOne({uuid: myId}, {$set: locker})
.then(result =>{
res.status(200).json(result)
})
.catch(err =>{
res.status(500).json({error: 'Could not update'})
})
})
app.patch('/member/checkin/:id', (req, res)=>{
//check in a member or check them out
//keep a record of checkins??
})

1233
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

8
package.json Normal file
View File

@ -0,0 +1,8 @@
{
"dependencies": {
"@tryghost/admin-api": "^1.13.12",
"cors": "^2.8.5",
"express": "^4.21.2",
"mongodb": "^6.13.0"
}
}

126
sample.json Normal file
View File

@ -0,0 +1,126 @@
[
{
"id": "67a60c6512ce7300010c6b64",
"uuid": "b071b92a-f812-4f0a-b9fc-de6bd8e76562",
"email": "thedigitalartist@gmail.com",
"name": "Timmy Tester",
"note": null,
"geolocation": "{\"country_code\":\"CA\",\"country_code3\":\"CAN\",\"ip\":\"76.66.249.136\",\"region\":\"Ontario\",\"latitude\":\"43.6512\",\"longitude\":\"-79.3736\",\"accuracy\":5,\"country\":\"Canada\",\"timezone\":\"America/Toronto\",\"asn\":577,\"organization\":\"AS577 BACOM\",\"continent_code\":\"NA\",\"city\":\"Toronto\",\"area_code\":\"0\",\"organization_name\":\"BACOM\"}",
"subscribed": true,
"created_at": "2025-02-07T13:36:37.000Z",
"updated_at": "2025-02-17T12:13:25.000Z",
"labels": [],
"subscriptions": [
{
"id": "sub_1QpuRMLUmdC5RxWV4NviUFHe",
"customer": {
"id": "cus_RjLONPbBROG0aQ",
"name": "Timmy Tester",
"email": "thedigitalartist@gmail.com"
},
"plan": {
"id": "price_1Qpuc2LUmdC5RxWVDz9jj5Pv",
"nickname": "Monthly",
"amount": 1000,
"interval": "month",
"currency": "CAD"
},
"status": "active",
"start_date": "2025-02-07T16:30:04.000Z",
"default_payment_card_last4": "6212",
"cancel_at_period_end": false,
"cancellation_reason": null,
"current_period_end": "2025-03-07T16:30:04.000Z",
"trial_start_at": null,
"trial_end_at": null,
"price": {
"id": "price_1Qpuc2LUmdC5RxWVDz9jj5Pv",
"price_id": "67a637a313a1dc00011f0038",
"nickname": "Monthly",
"amount": 1000,
"interval": "month",
"type": "recurring",
"currency": "CAD",
"tier": {
"id": "prod_RjNM0g9v4xotfc",
"name": "Supporter Member - TTLMakerspace",
"tier_id": "67a637a213a1dc00011f0034"
}
},
"tier": {
"id": "67a637a213a1dc00011f0034",
"name": "Supporter Member - TTLMakerspace",
"slug": "supporter-member-ttlmakerspace",
"active": true,
"welcome_page_url": null,
"visibility": "public",
"trial_days": 0,
"description": "Recurring monthly contribution",
"type": "paid",
"currency": "CAD",
"monthly_price": 1000,
"yearly_price": 36000,
"created_at": "2025-02-07T16:41:06.000Z",
"updated_at": null,
"monthly_price_id": null,
"yearly_price_id": null,
"expiry_at": null
},
"offer": null
}
],
"avatar_image": "https://www.gravatar.com/avatar/55499e27fcc4697aada1dfe057f65474?s=250&r=g&d=blank",
"comped": false,
"email_count": 0,
"email_opened_count": 0,
"email_open_rate": null,
"status": "paid",
"last_seen_at": "2025-02-17T12:13:25.000Z",
"unsubscribe_url": "https://members.ttlmakerspace.com/unsubscribe/?uuid=b071b92a-f812-4f0a-b9fc-de6bd8e76562&key=60e641101fefbc0b974b81a85a623c5ce4325378abdb83d7f11f8209f42878db",
"email_suppression": {
"suppressed": false,
"info": null
},
"newsletters": [
{
"id": "67a522cde543b4000121c213",
"name": "TTLMakerspace",
"description": null,
"status": "active"
}
]
},
{
"id": "67a52ee0f38204000171cad5",
"uuid": "c0b939c9-ba12-473f-aabc-00839c5e884c",
"email": "timbot@oddlystudios.com",
"name": "Tim Willison",
"note": null,
"geolocation": null,
"subscribed": true,
"created_at": "2025-02-06T21:51:28.000Z",
"updated_at": "2025-02-06T21:51:28.000Z",
"labels": [],
"subscriptions": [],
"avatar_image": "https://www.gravatar.com/avatar/5a98deb866a64d621c01c0954056ddba?s=250&r=g&d=blank",
"comped": false,
"email_count": 0,
"email_opened_count": 0,
"email_open_rate": null,
"status": "free",
"last_seen_at": null,
"unsubscribe_url": "https://members.ttlmakerspace.com/unsubscribe/?uuid=c0b939c9-ba12-473f-aabc-00839c5e884c&key=940f669a48012d009e8928770b155b67fc72a7b807d900769705f4d1e553b4e4",
"email_suppression": {
"suppressed": false,
"info": null
},
"newsletters": [
{
"id": "67a522cde543b4000121c213",
"name": "TTLMakerspace",
"description": null,
"status": "active"
}
]
}
]

23
staticserver.js Normal file
View File

@ -0,0 +1,23 @@
const express = require('express');
const path = require('path');
const app = express();
// Serve static files from the React app
app.use(express.static(path.join(__dirname, '../client/makerspace/dist')));
// Handle GET requests to /api route
app.get("/api", (req, res) => {
res.json({ message: "Hello from server!" });
});
// All other GET requests will be handled by React app
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, '../client/makerspace/dist', 'index.html'));
});
// Start the server
const PORT = process.env.PORT || 9111;
app.listen(PORT, () => {
console.log(`App listening on port ${PORT}`);
console.log('Press Ctrl+C to quit.');
});