Skip to content

Commit

Permalink
added dat folder to connect unsocial app to mongodb server b00tc4mp#173
Browse files Browse the repository at this point in the history
  • Loading branch information
angelzrc committed Nov 7, 2024
1 parent a573a81 commit 6c9ea6f
Show file tree
Hide file tree
Showing 22 changed files with 202 additions and 1,034 deletions.
45 changes: 0 additions & 45 deletions staff/angelzrc/unsocial/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,7 @@ server.post('/posts', jsonBodyParser, (req, res) => {
}
})

<<<<<<< HEAD
server.get('/posts', (req, res) => {
=======
server.patch('/posts/:postId/likes', (req, res) => {
const { postId } = req.params
>>>>>>> 1b468274c84eb6f3853c660b2b2683f639a5aa7b
const userId = req.headers.authorization.slice(6)

try {
Expand All @@ -90,46 +85,6 @@ server.patch('/posts/:postId/likes', (req, res) => {
}
})

<<<<<<< HEAD
=======


server.post('/posts/:postId/comments', jsonBodyParser, (req, res) => {
const { postId } = req.params
const userId = req.headers.authorization.slice(6) // 'Basic asdfasdfas'
const { text } = req.body

try {
logic.addComment(userId, postId, text)

res.status(201).send()
} catch (error) {

res.status(400).json({ error: error.constructor.name, message: error.message })

console.error(error)
}


})

server.delete('posts/:postId/comments/:commentId', (req, res) => {
const { postId, commentId } = req.params
const userId = req.headers.authorization.slice(6)

try {
logic.removeComment(postId, userId, commentId)

res.status(204).send()
} catch (error) {

res.status(400).json({ error: error.constructor.name, message: error.message })

console.error(error)
}
})

>>>>>>> 1b468274c84eb6f3853c660b2b2683f639a5aa7b
server.delete('/posts/:postId', (req, res) => {
const userId = req.headers.authorization.slice(6)

Expand Down
20 changes: 0 additions & 20 deletions staff/angelzrc/unsocial/api/logic/addComment.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,7 @@ export default (userId, postId, text) => {

if (!found) throw new Error('user not found')

<<<<<<< HEAD
const post = posts.find(({ id }) => id === postId)
=======
if (!found) {
throw new Error('user not found')
} else if (!postFound) {
throw new Error('post not found')
} else {
const post = posts.find(({ id }) => id === postId)

const comment = {
id: uuid(),
author: userId,
text,
date: new Date
}
post.comments.push(comment)

storage.posts = posts
}
>>>>>>> 1b468274c84eb6f3853c660b2b2683f639a5aa7b

if (!post) throw new Error('post not found')

Expand Down
3 changes: 2 additions & 1 deletion staff/angelzrc/unsocial/api/logic/authenticateUser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { storage } from '../data/index.js'
import { validate } from 'com'
import { storage } from '../data/index.js'


export default (username, password) => {
validate.username(username)
Expand Down
8 changes: 0 additions & 8 deletions staff/angelzrc/unsocial/api/logic/deletePost.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ export default (userId, postId) => {

if (!found) throw new Error('user not found')

<<<<<<< HEAD
=======
const { users, posts } = storage
const user = users.find(({ id }) => id === userId)

if (!user) throw new Error('user not found')

>>>>>>> 1b468274c84eb6f3853c660b2b2683f639a5aa7b
const index = posts.findIndex(({ id }) => id === postId)

if (index < 0) throw new Error('post not found')
Expand Down
4 changes: 0 additions & 4 deletions staff/angelzrc/unsocial/api/logic/getComments.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ export default (userId, postId) => {

if (!found) throw new Error('user not found')

const found = users.some(({ id }) => id === userId)

if (!found) throw new Error('user not found')

const post = posts.find(({ id }) => id === postId)

if (!post) throw new Error('post not found')
Expand Down
12 changes: 0 additions & 12 deletions staff/angelzrc/unsocial/api/logic/getPosts.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { storage } from '../data/index.js'
<<<<<<< HEAD
import { validate } from 'com'
=======
import { validate } from './helpers/index.js'
>>>>>>> 1b468274c84eb6f3853c660b2b2683f639a5aa7b

export default userId => {
validate.id(userId, 'userId')
Expand All @@ -25,14 +21,6 @@ export default userId => {

post.comments = post.comments.length
})
<<<<<<< HEAD
=======

/* const reversedPosts = posts.slice().reverse();
return reversedPosts */
/* console.log(Array.isArray(posts))
console.log(posts) */
>>>>>>> 1b468274c84eb6f3853c660b2b2683f639a5aa7b

return posts.toReversed()
}
7 changes: 1 addition & 6 deletions staff/angelzrc/unsocial/api/logic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import toggleLikePost from './toggleLikePost.js'
import addComment from './addComment.js'
import removeComment from './removeComment.js'
import getComments from './getComments.js'
import toggleLikePost from './toggleLikePost.js'



const logic = {
Expand All @@ -23,12 +23,7 @@ const logic = {

addComment,
removeComment,
<<<<<<< HEAD
getComments
=======
deletePost,
toggleLikePost
>>>>>>> 1b468274c84eb6f3853c660b2b2683f639a5aa7b
}

export default logic
4 changes: 0 additions & 4 deletions staff/angelzrc/unsocial/api/logic/removeComment.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ export default (userId, postId, commentId) => {
const found = users.some(({ id }) => id === userId)

if (!found) throw new Error('user not found')
<<<<<<< HEAD
=======

>>>>>>> 1b468274c84eb6f3853c660b2b2683f639a5aa7b

const post = posts.find(({ id }) => id === postId)

Expand Down
16 changes: 0 additions & 16 deletions staff/angelzrc/unsocial/api/logic/toggleLikePost.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
<<<<<<< HEAD
import { validate } from 'com'
import { storage } from '../data/index.js'
=======
import { storage } from "../data/index.js"
>>>>>>> 1b468274c84eb6f3853c660b2b2683f639a5aa7b

export default (userId, postId) => {
validate.id(userId, 'userId')
validate.id(postId, 'postId')

const { users, posts } = storage
<<<<<<< HEAD

const found = users.some(({ id }) => id === userId)
=======
const found = users.som(({ id }) => id === userId)
>>>>>>> 1b468274c84eb6f3853c660b2b2683f639a5aa7b

if (!found) throw new Error('user not found')

const post = posts.find(({ id }) => id === postId)

<<<<<<< HEAD
if (!post) throw new Error('post not found')
=======
if (!post) throw new Error('user not found')
>>>>>>> 1b468274c84eb6f3853c660b2b2683f639a5aa7b

const { likes } = post

Expand All @@ -37,8 +25,4 @@ export default (userId, postId) => {
likes.splice(index, 1)

storage.posts = posts
<<<<<<< HEAD
=======

>>>>>>> 1b468274c84eb6f3853c660b2b2683f639a5aa7b
}
Loading

0 comments on commit 6c9ea6f

Please sign in to comment.