changing posts to reference clerkUserID rather than id in mongodb
This commit is contained in:
@@ -37,7 +37,7 @@ export const getPost = async (req, res, next) => {
|
|||||||
|
|
||||||
export const getAllPostsByUser = async (req, res, next) => {
|
export const getAllPostsByUser = async (req, res, next) => {
|
||||||
console.log(req.params)
|
console.log(req.params)
|
||||||
const posts = await Post.find({ userID: req.params.user }).exec()
|
const posts = await Post.find({ clerkUserID: req.params.id }).exec()
|
||||||
posts.map((el) => {
|
posts.map((el) => {
|
||||||
el.photo = process.env.CLOUDFRONT_URL + el.photo
|
el.photo = process.env.CLOUDFRONT_URL + el.photo
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import mongoose from 'mongoose'
|
import mongoose from 'mongoose'
|
||||||
|
|
||||||
const postSchema = new mongoose.Schema({
|
const postSchema = new mongoose.Schema({
|
||||||
userID: {
|
clerkUserID: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ router.route('/').get(getAllPosts).post(createPost)
|
|||||||
|
|
||||||
router.route('/:id').get(getPost).patch(updatePost).delete(deletePost)
|
router.route('/:id').get(getPost).patch(updatePost).delete(deletePost)
|
||||||
|
|
||||||
router.route('/user/:user').get(getAllPostsByUser)
|
router.route('/user/:id').get(getAllPostsByUser)
|
||||||
|
|
||||||
router.route('/status/:status').get(getAllPostsByStatus)
|
router.route('/status/:status').get(getAllPostsByStatus)
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
|
import { useUser } from '@clerk/clerk-react'
|
||||||
import { CameraView, useCameraPermissions } from 'expo-camera'
|
import { CameraView, useCameraPermissions } from 'expo-camera'
|
||||||
import React, { useRef, useState } from 'react'
|
import React, { useRef, useState } from 'react'
|
||||||
import { Button, Image, Modal, StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native'
|
import { Button, Image, Modal, StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native'
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
|
const { user } = useUser()
|
||||||
const [permission, requestPermission] = useCameraPermissions()
|
const [permission, requestPermission] = useCameraPermissions()
|
||||||
const [photo, setPhoto] = useState('')
|
const [photo, setPhoto] = useState('')
|
||||||
const [address, setAddress] = useState('')
|
const [address, setAddress] = useState('')
|
||||||
@@ -35,7 +37,7 @@ export default function App() {
|
|||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
userID: '6883ddb2640ebaa1a12e3791',
|
clerkUserID: user?.id,
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
photo,
|
photo,
|
||||||
address,
|
address,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export default function PostsScreen() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
async function fetchData() {
|
async function fetchData() {
|
||||||
fetch(`http://localhost:3000/api/v1/posts/user/6883ddb2640ebaa1a12e3791`)
|
fetch(`http://localhost:3000/api/v1/posts/user/${user?.id}`)
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then((json) => {
|
.then((json) => {
|
||||||
console.log(json)
|
console.log(json)
|
||||||
|
|||||||
Reference in New Issue
Block a user