Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jackson/mongo #41

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions client/components/containers/Item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const Item = () => {

//useselector to subscribe to the items piece of state to populate
const items = useSelector((state) => {return state.swoop.items})
const [itemDiv, setItemDiv] = useState([]);
const [itemDiv, setItemDiv] = useState([]);//can use redux state

//loop through the list from back to front & push all of the
const render = () => {
Expand All @@ -48,7 +48,7 @@ const Item = () => {
}
}
}

//do this filtering on fetch request w specified params
//for filter form
const [neighboorhoodValues, setNeighboorhoodValues] = useState([]);
const neighboorhoodPicker = () => {
Expand Down Expand Up @@ -80,6 +80,8 @@ const Item = () => {
}
};

//filtering listings by neighbored
//send another fetch request with params that specify the neighboorhood
const renderWithFilter = () => {
const filterChoice = document.querySelector('#filter-neighboorhood');

Expand Down
2 changes: 1 addition & 1 deletion client/components/sidenav/CreatePost.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import DatePicker from "react-datepicker";
//import supabase API and set up connection to supabase storage of images
//we've implemented row-level security to the database so the API key can be on the client side
import { createClient } from '@supabase/supabase-js'
const supabaseUrl = 'https://pvjgsahtonujtyehjsqv.supabase.co'
const supabaseUrl = 'https://bmvohouexqmijckbooug.supabase.co'
const supabaseKey = process.env.REACT_APP_SUPABASE
const supabase = createClient(supabaseUrl, supabaseKey)

Expand Down
4 changes: 2 additions & 2 deletions server/controller/itemController.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const itemController = {}

itemController.createItem = (req, res, next) => {
console.log('in the itemController, and here are the contents of the request body: ', req.body)
Item.create(req.body)
Item.create(req.body) //makes a new Item document in mongoDB and returns it
.then((data) => {
res.locals.newItem = data;
next();
Expand All @@ -18,7 +18,7 @@ itemController.createItem = (req, res, next) => {
itemController.getAllItems = async (req, res, next) => {

try{
let allListings = await Item.find({})
let allListings = await Item.find({}) //serve the entire Item collection
console.log('here are all of the listings: ', allListings)
res.locals.allListings = allListings
next()
Expand Down
21 changes: 10 additions & 11 deletions server/models/itemModel.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
const mongoose = require('mongoose')
const Schema = mongoose.Schema

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const itemSchema = new Schema({
title: {type: String, required: true},
image: {type: String, required: false},
description: {type: String, required: true},
location: {type: Array, required: true},
dropDate: {type: Date, default: Date.now},
expireAt: {type: Date, expires: '1d'}
})
title: { type: String, required: true },
image: { type: String, required: false }, //url from supabase
description: { type: String, required: true },
location: { type: Array, required: true }, // [borough, neighborhood]
dropDate: { type: Date, default: Date.now },
expireAt: { type: Date, expires: '1d' }, // I think this is wrong, full document should expire
});

module.exports = mongoose.model('Item', itemSchema)
module.exports = mongoose.model('Item', itemSchema);
2 changes: 1 addition & 1 deletion server/models/sessionModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Schema = mongoose.Schema

const userSession = new Schema({
cookieId: { type: String, required: true, unique: true},
createdAt: { type: Date, expires: 1750, default: Date.now}
createdAt: { type: Date, expires: 1750, default: Date.now} // fixed for session to expire
})

module.exports = mongoose.model('Session', userSession)
4 changes: 2 additions & 2 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const path = require('path')
//install path

//set up cors policy
var corsOptions = {
var corsOptions = {
origin: "http://localhost:8080"
};
app.use(cors(corsOptions));
Expand All @@ -19,7 +19,7 @@ const mongoose = require('mongoose')
require('dotenv').config()

app.use(express.json());
mongoose.connect(process.env.DATABASE_CONNECTION_KEY)
mongoose.connect(process.env.DATABASE_CONNECTION_KEY) //must create a new .env file somehow link to this, will give us mongoDB access
mongoose.connection.once('open', () => {
console.log('Connected to Database');
});
Expand Down