diff --git a/staff/luis-morlets/unsocial/api/data/index.js b/staff/luis-morlets/unsocial/api/data/index.js deleted file mode 100644 index 3ee0a1d57..000000000 --- a/staff/luis-morlets/unsocial/api/data/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import uuid from './uuid.js' -import storage from './storage.js' - -export { - storage, - - uuid -} \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/data/posts.json b/staff/luis-morlets/unsocial/api/data/posts.json deleted file mode 100644 index acc3ed28c..000000000 --- a/staff/luis-morlets/unsocial/api/data/posts.json +++ /dev/null @@ -1 +0,0 @@ -[{"id":"m2xaozivndc","image":"https://i.pinimg.com/736x/7b/45/48/7b4548987582999980e7ac720cfd504a.jpg","text":"El Libertador","author":"m2x9yvtmjgu","date":"2024-10-31T12:42:00.535Z","likedBy":["m2x9yvtmjgu","m2wd1d38rhe","m2wd7pkr7xq","m34kcl8k76i","m34m1x7tbyb"],"comments":[{"id":"m34lbtbyz1u","author":"m34kcl8k76i","text":"Cuanto ha crecido mi simoncito"},{"id":"m3614zfvbo7","author":"m34m1x7tbyb","text":"Que grande ese Bolivita!!"}]},{"id":"m34j2e2tx1p","image":"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQPufJ3rYLCohIyTu_nEilzM04sNZCp5WL4uQ&s","text":"Para el recuerdo","author":"m3352rtur6c","date":"2024-11-05T14:10:46.086Z","likedBy":["m34m1x7tbyb","m34kcl8k76i","m2x9yvtmjgu"],"comments":[{"id":"m34m3kvu0id","author":"m34m1x7tbyb","text":"Manuelita una gran amiga, saludos!!"},{"id":"m35mgc1toa","author":"m34kcl8k76i","text":"Linda manuelita"}]},{"id":"m35mhjjf4d","image":"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRTZjZASv_2DCaVPg8OWrz7HPcDDlAMc6Sqgg&s","text":"Con mi pequeño simoncito","author":"m34kcl8k76i","date":"2024-11-06T08:34:18.027Z","likedBy":["m2x9yvtmjgu","m3352rtur6c","m34m1x7tbyb"],"comments":[{"id":"m35mk93u5yu","author":"m2x9yvtmjgu","text":"Mi segunda madre!"}]}] \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/data/storage.js b/staff/luis-morlets/unsocial/api/data/storage.js deleted file mode 100644 index 23c6ef895..000000000 --- a/staff/luis-morlets/unsocial/api/data/storage.js +++ /dev/null @@ -1,31 +0,0 @@ -import fs from 'fs' - -export default { - get users() { - const json = fs.readFileSync('./data/users.json', 'utf-8') - - const users = JSON.parse(json) - - return users - }, - - set users(users) { - const json = JSON.stringify(users) - - fs.writeFileSync('./data/users.json', json) - }, - - get posts() { - const json = fs.readFileSync('./data/posts.json', 'utf-8') - - const posts = JSON.parse(json) - - return posts - }, - - set posts(posts) { - const json = JSON.stringify(posts) - - fs.writeFileSync('./data/posts.json', json) - } -} \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/data/storage.test.js b/staff/luis-morlets/unsocial/api/data/storage.test.js deleted file mode 100644 index 4ddd67caa..000000000 --- a/staff/luis-morlets/unsocial/api/data/storage.test.js +++ /dev/null @@ -1,11 +0,0 @@ -import uuid from './uuid.js' - -import storage from './storage.js' - -storage.users = [ - { id: uuid(), name: 'Pepito Grillo', email: 'pepito@grillo.com', username: 'pepitogrillo', password: '123123123' } -] - -storage.posts = [] - -console.log(storage.users) \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/data/users.json b/staff/luis-morlets/unsocial/api/data/users.json deleted file mode 100644 index 77dd193d3..000000000 --- a/staff/luis-morlets/unsocial/api/data/users.json +++ /dev/null @@ -1,44 +0,0 @@ -[ - { - "id": "m2wd1d38rhe", - "name": "Pepito Grillo", - "email": "pepito@grillo.com", - "username": "pepitogrillo", - "password": "123123123" - }, - { - "id": "m2wd7pkr7xq", - "name": "Pin Ocho", - "email": "pin@ocho.com", - "username": "pinocho", - "password": "123123123" - }, - { - "id": "m2x9yvtmjgu", - "name": "Simon Bolivar", - "email": "simon@bolivar.com", - "username": "simoncito", - "password": "123123123" - }, - { - "id": "m3352rtur6c", - "name": "Manuela Saenz", - "email": "manuela@saenz.com", - "username": "manuelita", - "password": "123123123" - }, - { - "id": "m34kcl8k76i", - "name": "Hipolita Bolivar", - "email": "hipolita@bolivar.com", - "username": "negrahipolita", - "password": "123123123" - }, - { - "id": "m34m1x7tbyb", - "name": "Simon Rodriguez", - "email": "simon@rodriguez.com", - "username": "profesimon", - "password": "123123123" - } -] \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/data/uuid.js b/staff/luis-morlets/unsocial/api/data/uuid.js deleted file mode 100644 index dda113a0e..000000000 --- a/staff/luis-morlets/unsocial/api/data/uuid.js +++ /dev/null @@ -1,3 +0,0 @@ -const uuid = () => (Date.now() + Math.random()).toString(36).replace('.', '') - -export default uuid \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/index.js b/staff/luis-morlets/unsocial/api/index.js index 23573aeba..b4632a2fa 100644 --- a/staff/luis-morlets/unsocial/api/index.js +++ b/staff/luis-morlets/unsocial/api/index.js @@ -1,174 +1,221 @@ +import db from 'dat' import express, { json } from 'express' import logic from './logic/index.js' import cors from 'cors' -const server = express() +db.connect('mongodb://127.0.0.1:27017/unsocial-test') + .then(() => { + console.log('connected to db') -server.use(cors()) + const server = express() -const jsonBodyParser = json() + server.use(cors()) -server.get('/', (_, res) => res.send('Hello, API!')) + const jsonBodyParser = json() -server.post('/authenticate', jsonBodyParser, (req, res) => { + server.get('/', (_, res) => res.send('Hello, API!')) - const { username, password } = req.body - try { + server.post('/authenticate', jsonBodyParser, (req, res) => { + try { + const { username, password } = req.body - const userId = logic.authenticateUser(username, password) + logic.authenticateUser(username, password) + .then(userId => res.json(userId)) + .catch(error => { + res.status(401).json({ error: error.constructor.name, message: error.message }) - res.json(userId) - } catch (error) { - res.status(401).json({ error: error.constructor.name, message: error.message }) + console.error(error) + }) + } catch (error) { + res.status(401).json({ error: error.constructor.name, message: error.message }) - console.error(error) - } -}) + console.error(error) + } + }) -server.post('/register', jsonBodyParser, (req, res) => { + server.post('/register', jsonBodyParser, (req, res) => { + try { + const { name, email, username, password, 'password-repeat': passwordRepeat } = req.body - try { - const { name, email, username, password, 'password-repeat': passwordRepeat } = req.body + logic.registerUser(name, email, username, password, passwordRepeat) + .then(() => res.status(201).send()) + .catch(error => { + res.status(400).json({ error: error.constructor.name, message: error.message }) - logic.registerUser(name, email, username, password, passwordRepeat) + console.error(error) + }) + } catch (error) { + res.status(400).json({ error: error.constructor.name, message: error.message }) - res.status(201).send() - } catch (error) { - res.status(400).json({ error: error.constructor.name, message: error.message }) + console.error(error) + } + }) - console.error(error) - } -}) + server.get('/users/:targetUserId/name', (req, res) => { -server.get('/users/:targetUserId/name', (req, res) => { - const userId = req.headers.authorization.slice(6) + try { + const userId = req.headers.authorization.slice(6) - const { targetUserId } = req.params + const { targetUserId } = req.params - try { - const name = logic.getUserName(userId, targetUserId) + logic.getUserName(userId, targetUserId) + .then(name => res.json(name)) + .catch(error => { + res.status(400).json({ error: error.constructor.name, message: error.message }) - res.json(name) - } catch (error) { - res.status(400).json({ error: error.constructor.name, message: error.message }) + console.error(error) + }) + } catch (error) { + res.status(400).json({ error: error.constructor.name, message: error.message }) - console.error(error) - } -}) + console.error(error) + } + }) -server.post('/posts', jsonBodyParser, (req, res) => { - const userId = req.headers.authorization.slice(6) //Basic sgsgsgsgs + server.post('/posts', jsonBodyParser, (req, res) => { - const { image, text } = req.body + try { + const userId = req.headers.authorization.slice(6) //Basic sgsgsgsgs - try { - logic.createPost(userId, image, text) + const { image, text } = req.body - res.status(201).send() - } catch (error) { - res.status(400).json({ error: error.constructor.name, message: error.message }) + logic.createPost(userId, image, text) + .then(() => res.status(201).send()) + .catch(error => { + res.status(400).json({ error: error.constructor.name, message: error.message }) - console.error(error) - } -}) + console.error(error) + }) + } catch (error) { + res.status(400).json({ error: error.constructor.name, message: error.message }) -server.get('/posts', (req, res) => { - const userId = req.headers.authorization.slice(6) + console.error(error) + } + }) - try { - const posts = logic.getPosts(userId) + server.get('/posts', (req, res) => { - res.json(posts) - } catch (error) { - res.status(404).json({ error: error.constructor.name, message: error.message }) + try { + const userId = req.headers.authorization.slice(6) - console.error(error) - } -}) + logic.getPosts(userId) + .then(posts => res.json(posts)) + .catch(error => { + res.status(404).json({ error: error.constructor.name, message: error.message }) -server.delete('/posts/:postId', (req, res) => { - const { postId } = req.params - const userId = req.headers.authorization.slice(6) + console.error(error) + }) + } catch (error) { + res.status(404).json({ error: error.constructor.name, message: error.message }) - try { - logic.deletePost(userId, postId) + console.error(error) + } + }) - res.status(204).send() - } catch (error) { - res.status(400).json({ error: error.constructor.name, message: error.message }) + server.delete('/posts/:postId', (req, res) => { - console.error(error) - } -}) + try { + const { postId } = req.params + const userId = req.headers.authorization.slice(6) -server.post('/posts/:postId/comments', jsonBodyParser, (req, res) => { + logic.deletePost(userId, postId) + .then(() => res.status(204).send()) + .catch(error => { + res.status(400).json({ error: error.constructor.name, message: error.message }) - const userId = req.headers.authorization.slice(6) + console.error(error) + }) + } catch (error) { + res.status(400).json({ error: error.constructor.name, message: error.message }) - const { text } = req.body + console.error(error) + } + }) - const { postId } = req.params + server.post('/posts/:postId/comments', jsonBodyParser, (req, res) => { - try { - logic.addComment(userId, postId, text) + try { + const userId = req.headers.authorization.slice(6) - res.status(201).send() + const { text } = req.body - } catch (error) { - res.status(400).json({ error: error.constructor.name, message: error.message }) + const { postId } = req.params - console.error(error) - } -}) + logic.addComment(userId, postId, text) + .then(() => res.status(201).send()) + .catch(error => { + res.status(400).json({ error: error.constructor.name, message: error.message }) -server.get('/posts/:postId/comments', (req, res) => { - const userId = req.headers.authorization.slice(6) + console.error(error) + }) + } catch (error) { + res.status(400).json({ error: error.constructor.name, message: error.message }) - const { postId } = req.params + console.error(error) + } + }) - try { - const comment = logic.getComments(userId, postId) + server.get('/posts/:postId/comments', (req, res) => { - res.json(comment) - } catch (error) { - res.status(400).json({ error: error.constructor.name, message: error.message }) + try { + const userId = req.headers.authorization.slice(6) - console.error(error) - } -}) + const { postId } = req.params -server.delete('/posts/:postId/comments/:commentId', (req, res) => { + logic.getComments(userId, postId) + .then(comment => res.json(comment)) + .catch(error => { + res.status(400).json({ error: error.constructor.name, message: error.message }) - const userId = req.headers.authorization.slice(6) + console.error(error) + }) + } catch (error) { + res.status(400).json({ error: error.constructor.name, message: error.message }) - const { postId, commentId } = req.params + console.error(error) + } + }) - try { - logic.removeComment(userId, postId, commentId) + server.delete('/posts/:postId/comments/:commentId', (req, res) => { - res.status(204).send() + try { + const userId = req.headers.authorization.slice(6) - } catch (error) { - res.status(400).json({ error: error.constructor.name, message: error.message }) + const { postId, commentId } = req.params - console.error(error) - } -}) + logic.removeComment(userId, postId, commentId) + .then(() => res.status(204).send()) + .catch(error => { + res.status(400).json({ error: error.constructor.name, message: error.message }) -server.patch('/posts/:postId/likes', (req, res) => { - const userId = req.headers.authorization.slice(6) + console.error(error) + }) + } catch (error) { + res.status(400).json({ error: error.constructor.name, message: error.message }) - const { postId } = req.params - try { - logic.likesInteraction(userId, postId) + console.error(error) + } + }) - res.status(204).send() + server.patch('/posts/:postId/likes', (req, res) => { + try { + const userId = req.headers.authorization.slice(6) - } catch (error) { - res.status(400).json({ error: error.constructor.name, message: error.message }) + const { postId } = req.params - console.error(error) - } -}) + logic.likesInteraction(userId, postId) + .then(() => res.status(204).send()) + .catch(error => { + res.status(400).json({ error: error.constructor.name, message: error.message }) -server.listen(8080, () => console.log('api is up')) \ No newline at end of file + console.error(error) + }) + } catch (error) { + res.status(400).json({ error: error.constructor.name, message: error.message }) + + console.error(error) + } + }) + + server.listen(8080, () => console.log('api is up')) + }) \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/logic/addComment.js b/staff/luis-morlets/unsocial/api/logic/addComment.js index 52c8495b8..9e9370dbf 100644 --- a/staff/luis-morlets/unsocial/api/logic/addComment.js +++ b/staff/luis-morlets/unsocial/api/logic/addComment.js @@ -1,29 +1,36 @@ -import { storage, uuid } from '../data/index.js' +import db from 'dat' import { validate } from 'com' +const { ObjectId } = db export default (userId, postId, text) => { validate.id(postId, 'postId') validate.id(userId, 'userId') validate.text(text) - const { posts, users } = storage - - 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') - - post.comments.push({ - id: uuid(), - author: userId, - text, - date: new Date().toISOString - }) - - storage.posts = posts -} \ No newline at end of file + const userObjectId = ObjectId.createFromHexString(userId) + const postObjectId = ObjectId.createFromHexString(postId) + + return Promise.all([ + db.users.findOne({ _id: userObjectId }), + db.posts.findOne({ _id: postObjectId }) + ]) + .catch(error => { throw new Error(error.message) }) + .then(([user, post]) => { + if (!user) throw new Error("user not found"); + if (!post) throw new Error("post not found") + + return db.posts.updateOne({ _id: postObjectId }, + { + $push: { + comments: { + _id: new ObjectId(), + author: userObjectId, + text, + date: new Date(), + } + } + }) + }) +} diff --git a/staff/luis-morlets/unsocial/api/logic/addComment.test.js b/staff/luis-morlets/unsocial/api/logic/addComment.test.js index 2306d02b1..6703c5c8b 100644 --- a/staff/luis-morlets/unsocial/api/logic/addComment.test.js +++ b/staff/luis-morlets/unsocial/api/logic/addComment.test.js @@ -1,7 +1,17 @@ +import db from 'dat' + import addComment from './addComment.js' -try { - addComment('m2wd7pkr7xq', 'm2xaozivndc', 'Grande Boliva') -} catch (error) { - console.error(error) -} \ No newline at end of file +db.connect("mongodb://127.0.0.1:27017/unsocial-test") + .then(() => { + try { + return addComment("672e20b8106be73d00f7ee7b", "67321930d260445bfba74342", "Grande Boliva" + ) + .then(console.log) + .catch(console.error) + } catch (error) { + console.error(error) + } + }) + .catch(console.error) + .finally(() => db.disconnect()) \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/logic/authenticateUser.js b/staff/luis-morlets/unsocial/api/logic/authenticateUser.js index c411f831d..27df2b9d6 100644 --- a/staff/luis-morlets/unsocial/api/logic/authenticateUser.js +++ b/staff/luis-morlets/unsocial/api/logic/authenticateUser.js @@ -1,16 +1,15 @@ -import { storage } from '../data/index.js' +import db from 'dat' import { validate } from 'com' export default (username, password) => { validate.username(username) validate.password(password) - const { users } = storage + return db.users.findOne({ username, password }) + .catch(error => { throw new Error(error.message) }) + .then(user => { + if (!user) throw new Error('wrong credentials') - const user = users.find(user => user.username === username && user.password === password) - - if (user === undefined) - throw new Error('Wrong credentials, try again') - - return user.id + return user._id.toString() + }) } \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/logic/authenticateUser.test.js b/staff/luis-morlets/unsocial/api/logic/authenticateUser.test.js index c703ceff7..73ee73596 100644 --- a/staff/luis-morlets/unsocial/api/logic/authenticateUser.test.js +++ b/staff/luis-morlets/unsocial/api/logic/authenticateUser.test.js @@ -1,7 +1,14 @@ +import db from 'dat' import authenticateUser from './authenticateUser.js' -try { - console.log(authenticateUser('pinocho', '123123123')) -} catch (error) { - console.error(error) -} \ No newline at end of file +db.connect('mongodb://127.0.0.1:27017/unsocial-test') + .then(() => { + try { + authenticateUser('franciscom', '123123123') + .then(console.log) + .catch(console.error) + } catch (error) { + console.error(error) + } + }) + .catch(console.error) \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/logic/createPost.js b/staff/luis-morlets/unsocial/api/logic/createPost.js index 9e2e7d39f..67ee1e2e7 100644 --- a/staff/luis-morlets/unsocial/api/logic/createPost.js +++ b/staff/luis-morlets/unsocial/api/logic/createPost.js @@ -1,27 +1,22 @@ -import { uuid, storage } from '../data/index.js' +import db from 'dat' import { validate } from 'com' +const { ObjectId } = db + export default (userId, image, text) => { validate.id(userId, 'userId') validate.image(image) validate.text(text) - const { users, posts } = storage - - const found = users.some(({ id }) => id === userId) - - if (!found) throw new Error('user not found') + const userObjectId = ObjectId.createFromHexString(userId) - const post = { - id: uuid(), - image: image, - text: text, - author: userId, - date: new Date, - likedBy: [], - comments: [] - } - posts.push(post) + return db.users.findOne({ _id: userObjectId }) + .catch(error => { throw new Error(error.message) }) + .then(user => { + if (!user) throw new Error('user not found') - storage.posts = posts + return db.posts.insertOne({ author: userObjectId, image, text, date: new Date, likes: [], comments: [] }) + .catch(error => { throw new Error(error.messsage) }) + .then(_ => { }) + }) } \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/logic/createPost.test.js b/staff/luis-morlets/unsocial/api/logic/createPost.test.js index 4c50a36d3..4b31e623a 100644 --- a/staff/luis-morlets/unsocial/api/logic/createPost.test.js +++ b/staff/luis-morlets/unsocial/api/logic/createPost.test.js @@ -1,8 +1,15 @@ +import db from 'dat' import createPost from './createPost.js' -try { - createPost('m2wd7pkr7xq', 'https://pixabay.com/get/g0259c3660213baf3e4aa36f843176f3d021f71f70db7da315dda8809d7fe49fd0f394a4d00203563adb597194a0868c2_1280.jpg', 'cuando estudiaba') - -} catch (error) { - console.error(error) -} \ No newline at end of file +db.connect('mongodb://127.0.0.1:27017/unsocial-test') + .then(() => { + try { + return createPost('672e2c487f1acbd7a5009c67', 'https://upload.wikimedia.org/wikipedia/commons/a/a9/Sim%C3%B3n_Bol%C3%ADvar_by_Acevedo_Bernal%2C_1922.jpg', 'Libertando') + .then(console.log) + .catch(console.error) + } catch (error) { + console.error(error) + } + }) + .catch(console.error) + .finally(() => db.disconnect()) \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/logic/deletePost.js b/staff/luis-morlets/unsocial/api/logic/deletePost.js index b8a803e1f..45f03e822 100644 --- a/staff/luis-morlets/unsocial/api/logic/deletePost.js +++ b/staff/luis-morlets/unsocial/api/logic/deletePost.js @@ -1,27 +1,31 @@ -import { storage } from '../data/index.js' +import db from 'dat' import { validate } from 'com' +const { ObjectId } = db + export default (userId, postId) => { - validate.id(userId, 'userId') validate.id(postId, 'postId') + validate.id(userId, 'userId') - const { posts, users } = storage - - const found = users.some(({ id }) => id === userId) - - if (!found) throw new Error('user not found') - - const index = posts.findIndex(({ id }) => id === postId) - - if (index < 0) throw new Error('post not found') + const userObjectId = ObjectId.createFromHexString(userId) + const postObjectId = ObjectId.createFromHexString(postId) - const post = posts[index] + return Promise.all([ + db.users.findOne({ _id: userObjectId }), + db.posts.findOne({ _id: postObjectId }) + ]) + .catch(error => { throw new Error(error.message) }) + .then(([user, post]) => { + if (!user) throw new Error('user not found') + if (!post) throw new Error('post not found') - const { author } = post + const { author } = post - if (author !== userId) throw new Error('user is not author of post') + if (!author.equals(userId)) { throw new Error('User is not author of this post') } - posts.splice(index, 1) + return db.posts.deleteOne({ _id: postObjectId }) + .catch(error => { throw new Error(error.message) }) + .then(_ => { }) + }) +} - storage.posts = posts -} \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/logic/deletePost.test.js b/staff/luis-morlets/unsocial/api/logic/deletePost.test.js index 978fbad27..df435fc2e 100644 --- a/staff/luis-morlets/unsocial/api/logic/deletePost.test.js +++ b/staff/luis-morlets/unsocial/api/logic/deletePost.test.js @@ -1,7 +1,16 @@ +import db from 'dat' + import deletePost from './deletePost.js' -try { - deletePost('m2wd7pkr7xq', 'm32snzaun6d') -} catch (error) { - console.error(error) -} \ No newline at end of file +db.connect('mongodb://127.0.0.1:27017/unsocial-test') + .then(() => { + try { + return deletePost('672e2c487f1acbd7a5009c67', '67321930d260445bfba74342') + .then(console.log) + .catch(console.error) + } catch (error) { + console.error(error) + } + }) + .catch(console.error) + .finally(() => db.disconnect()) \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/logic/getComments.js b/staff/luis-morlets/unsocial/api/logic/getComments.js index 954884630..f7b9822ab 100644 --- a/staff/luis-morlets/unsocial/api/logic/getComments.js +++ b/staff/luis-morlets/unsocial/api/logic/getComments.js @@ -1,29 +1,43 @@ +import db from 'dat' import { validate } from 'com' -import { storage } from '../data/index.js' + +const { ObjectId } = db export default (userId, postId) => { validate.id(userId, 'userId') validate.id(postId, 'postId') - const { users, posts } = storage - - const found = users.some(({ id }) => id === userId) + const userObjectId = ObjectId.createFromHexString(userId) + const postObjectId = ObjectId.createFromHexString(postId) - if (!found) throw new Error('user not found') + return Promise.all([ + db.users.findOne({ _id: userObjectId }), + db.posts.findOne({ _id: postObjectId }) + ]) + .catch(error => { throw new Error(error.message) }) + .then(([user, post]) => { + if (!user) throw new Error('user not found') + if (!post) throw new Error('post not found') - const post = posts.find(({ id }) => id === postId) + const { comments } = post - if (!post) throw new Error('post not found') + const promises = comments.map(comment => { + return db.users.findOne({ _id: comment.author }) + .catch(error => { throw new Error(error.message) }) + .then(user => { + if (!user) throw new Error('author of comment not found') - const { comments } = post + const { username } = user - comments.forEach(comment => { - const { author: authorId } = comment + comment.id = comment._id.toString() + delete comment._id - const { username } = users.find(({ id }) => id === authorId) + comment.author = { id: comment.author.toString(), username } - comment.author = { id: authorId, username } - }) + return comment + }) + }) + return Promise.all(promises) + }) +} - return comments -} \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/logic/getComments.test.js b/staff/luis-morlets/unsocial/api/logic/getComments.test.js index 54e7c8bc5..10efe726e 100644 --- a/staff/luis-morlets/unsocial/api/logic/getComments.test.js +++ b/staff/luis-morlets/unsocial/api/logic/getComments.test.js @@ -1,7 +1,15 @@ +import db from 'dat' import getComments from './getComments.js' -try { - console.log(getComments('m2x9yvtmjgu', 'm2xaozivndc')) -} catch (error) { - console.error(error) -} \ No newline at end of file +db.connect('mongodb://127.0.0.1:27017/unsocial-test') + .then(() => { + try { + return getComments('672e20b8106be73d00f7ee7b', '67321930d260445bfba74342') + .then(console.log) + .catch(console.error) + } catch (error) { + console.error(error) + } + }) + .catch(console.error) + .finally(() => db.disconnect()) \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/logic/getPosts.js b/staff/luis-morlets/unsocial/api/logic/getPosts.js index 9d924c428..d6255ccc0 100644 --- a/staff/luis-morlets/unsocial/api/logic/getPosts.js +++ b/staff/luis-morlets/unsocial/api/logic/getPosts.js @@ -1,26 +1,45 @@ -import { storage } from '../data/index.js' +import db from 'dat' import { validate } from 'com' +const { ObjectId } = db + export default userId => { validate.id(userId, 'userId') - const { users, posts } = storage + const userObjectId = ObjectId.createFromHexString(userId) + + return db.users.findOne({ _id: userObjectId }) + .catch(error => { throw new Error(error.message) }) + .then(user => { + if (!user) throw new Error('user not found') - const found = users.some(({ id }) => id === userId) + return db.posts.find().sort({ date: -1 }).toArray() + .catch(error => { throw new Error(error.message) }) + }) + .then(posts => { + const promises = posts.map(post => + db.users.findOne({ _id: post.author }, { projection: { _id: 0, username: 1 } }) + .then(user => { + if (!user) throw new Error('author of post not found') - if (!found) throw new Error('user not found') + const { username } = user - posts.forEach(post => { - const { author: authorId } = post + //normalize / sanitize + post.id = post._id.toString() + delete post._id - const { username } = users.find(({ id }) => id === authorId) + post.author = { id: post.author.toString(), username } - post.author = { id: authorId, username } + const { likes, comments } = post - post.liked = post.likedBy.includes(userId) + post.liked = likes.some(userObjectId => userObjectId.equals(userId)) + post.likes = likes.length - post.comments = post.comments.length - }) + post.comments = comments.length - return posts.toReversed() -} \ No newline at end of file + return post + }) + ) + return Promise.all(promises) + }) +} diff --git a/staff/luis-morlets/unsocial/api/logic/getPosts.test.js b/staff/luis-morlets/unsocial/api/logic/getPosts.test.js index 555b80315..ec362c318 100644 --- a/staff/luis-morlets/unsocial/api/logic/getPosts.test.js +++ b/staff/luis-morlets/unsocial/api/logic/getPosts.test.js @@ -1,7 +1,15 @@ -import getPosts from './getPosts.js'; +import db from 'dat' +import getPosts from './getPosts.js' -try { - console.log(getPosts('m2wd1d38rhe')) -} catch (error) { - console.error(error) -} \ No newline at end of file +db.connect('mongodb://127.0.0.1:27017/unsocial-test') + .then(() => { + try { + return getPosts('672e2c487f1acbd7a5009c67') + .then(console.log) + .catch(console.error) + } catch (error) { + console.error(error) + } + }) + .catch(console.error) + .finally(() => db.disconnect()) \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/logic/getUserName.js b/staff/luis-morlets/unsocial/api/logic/getUserName.js index 995b904fa..42ced61e3 100644 --- a/staff/luis-morlets/unsocial/api/logic/getUserName.js +++ b/staff/luis-morlets/unsocial/api/logic/getUserName.js @@ -1,19 +1,26 @@ -import { storage } from '../data/index.js' +import db from 'dat' import { validate } from 'com' +const { ObjectId } = db + export default (userId, targetUserId) => { validate.id(userId, 'userId') validate.id(targetUserId, 'targetUserId') - const { users } = storage - - const found = users.some(({ id }) => id === userId) - - if (!found) throw new Error('user not found') + const userObjectId = ObjectId.createFromHexString(userId) + const targetUserObjectId = ObjectId.createFromHexString(targetUserId) - const user = users.find(({ id }) => id === targetUserId) + return db.users.findOne({ _id: userObjectId }) + .catch(error => { throw new Error(error.message) }) + .then(user => { + if (!user) throw new Error('user not found') - if (!user) throw new Error('target user not found') + return db.users.findOne({ _id: targetUserObjectId }) + .catch(error => { throw new Error(error.message) }) + }) + .then(user => { + if (!user) throw new Error('target user not found') - return user.name + return user.name + }) } \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/logic/getUserName.test.js b/staff/luis-morlets/unsocial/api/logic/getUserName.test.js index 0dac04dbd..27e240ae6 100644 --- a/staff/luis-morlets/unsocial/api/logic/getUserName.test.js +++ b/staff/luis-morlets/unsocial/api/logic/getUserName.test.js @@ -1,7 +1,15 @@ +import db from 'dat' import getUserName from './getUserName.js' -try { - console.log(getUserName('m2wd7pkr7xq')) -} catch (error) { - console.error(error) -} \ No newline at end of file +db.connect('mongodb://127.0.0.1:27017/unsocial-test') + .then(() => { + try { + return getUserName('672e20b8106be73d00f7ee7b', '672e2c487f1acbd7a5009c67') + .then(console.log) + .catch(console.error) + } catch (error) { + console.error(error) + } + }) + .catch(console.error) + .finally(() => db.disconnect()) \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/logic/likesInteraction.js b/staff/luis-morlets/unsocial/api/logic/likesInteraction.js index dece9a3b4..fea2df01a 100644 --- a/staff/luis-morlets/unsocial/api/logic/likesInteraction.js +++ b/staff/luis-morlets/unsocial/api/logic/likesInteraction.js @@ -1,26 +1,34 @@ +import db from 'dat' import { validate } from 'com' -import { storage } from '../data/index.js' + +const { ObjectId } = db export default (userId, postId) => { + validate.id(userId, 'userId') validate.id(postId, 'postId') - const { posts, users } = storage - - 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') + const userObjectId = ObjectId.createFromHexString(userId) + const postObjectId = ObjectId.createFromHexString(postId) - const { likedBy } = post + return Promise.all([ + db.users.findOne({ _id: userObjectId }), + db.posts.findOne({ _id: postObjectId }) + ]) + .catch(error => { throw new Error(error.message) }) + .then(([user, post]) => { + if (!user) throw new Error('user not found') + if (!post) throw new Error('post not found') - const index = likedBy.indexOf(userId) + const { likes } = post - if (index < 0) likedBy.push(userId) + const found = likes.some(userObjectId => userObjectId.equals(userId)) - else likedBy.splice(index, 1) + if (!found) + return db.posts.updateOne({ _id: postObjectId }, { $push: { likes: userObjectId } }) + .catch(error => { throw new Error(error.message) }) - storage.posts = posts + return db.posts.updateOne({ _id: postObjectId }, { $pull: { likes: userObjectId } }) + .catch(error => { throw new Error(error.message) }) + }) + .then(_ => { }) } \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/logic/likesInteraction.test.js b/staff/luis-morlets/unsocial/api/logic/likesInteraction.test.js index 4819187a5..a2ad123e2 100644 --- a/staff/luis-morlets/unsocial/api/logic/likesInteraction.test.js +++ b/staff/luis-morlets/unsocial/api/logic/likesInteraction.test.js @@ -1,7 +1,15 @@ +import db from 'dat' import likesInteraction from './likesInteraction.js' -try { - likesInteraction('m2x9yvtmjgu', 'm2xaozivndc') -} catch (error) { - console.error(error) -} \ No newline at end of file +db.connect('mongodb://127.0.0.1:27017/unsocial-test') + .then(() => { + try { + return likesInteraction('672e20b8106be73d00f7ee7b', '67321930d260445bfba74342') + .then(console.log) + .catch(console.error) + } catch (error) { + console.error(error) + } + }) + .catch(console.error) + .finally(() => db.disconnect()) \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/logic/registerUser.1.warn.js b/staff/luis-morlets/unsocial/api/logic/registerUser.1.warn.js new file mode 100644 index 000000000..9f0986189 --- /dev/null +++ b/staff/luis-morlets/unsocial/api/logic/registerUser.1.warn.js @@ -0,0 +1,27 @@ +import db from 'dat' + +import { validate } from 'com' + +let chain = Promise.resolve() + +export default (name, email, username, password, passwordRepeat) => { + validate.name(name) + validate.email(email) + validate.username(username) + validate.password(password) + validate.passwordMatch(password, passwordRepeat) + + chain = chain.then(() => new Promise((resolve, reject) => { + db.users.findOne({ $or: [{ email }, { username }] }) + .then(user => { + if (user) throw new Error('user already exists') + + return db.users.insertOne({ name, email, username, password }) + .then(_ => resolve()) + .catch(error => reject(error)) + }) + })) + + return chain + +} \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/logic/registerUser.js b/staff/luis-morlets/unsocial/api/logic/registerUser.js index d56a7da46..e5899db6c 100644 --- a/staff/luis-morlets/unsocial/api/logic/registerUser.js +++ b/staff/luis-morlets/unsocial/api/logic/registerUser.js @@ -1,24 +1,19 @@ +import db from 'dat' + import { validate } from 'com' -import { uuid, storage } from '../data/index.js' export default (name, email, username, password, passwordRepeat) => { - validate.name(name) validate.email(email) validate.username(username) validate.password(password) validate.passwordMatch(password, passwordRepeat) - const { users } = storage - - let user = users.find(user => user.username === username || user.email === email) - - if (user !== undefined) - throw new Error('user already exists') - - user = { id: uuid(), name: name, email: email, username: username, password: password } - - users.push(user) + return db.users.insertOne({ name, email, username, password }) + .then(_ => { }) + .catch(error => { + if (error.code === 11000) throw new Error('user already exists') - storage.users = users + throw new Error(error.message) + }) } \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/logic/registerUser.test.js b/staff/luis-morlets/unsocial/api/logic/registerUser.test.js index 6a7f233a9..97b5d2b45 100644 --- a/staff/luis-morlets/unsocial/api/logic/registerUser.test.js +++ b/staff/luis-morlets/unsocial/api/logic/registerUser.test.js @@ -1,7 +1,16 @@ +import db from 'dat' + import registerUser from './registerUser.js' -try { - registerUser('Pin Ocho', 'pin@ocho.com', 'pinocho', '123123123', '123123123') -} catch (error) { - console.error(error) -} \ No newline at end of file +db.connect('mongodb://127.0.0.1:27017/unsocial-test') + .then(() => { + try { + return registerUser('Francisco Miranda', 'francisco@miranda.com', 'franciscom', '123123123', '123123123') + .then(console.log) + .catch(console.error) + } catch (error) { + console.error(error) + } + }) + .catch(console.error) + .finally(() => db.disconnect()) \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/logic/removeComment.js b/staff/luis-morlets/unsocial/api/logic/removeComment.js index 463f409f5..c6c5da997 100644 --- a/staff/luis-morlets/unsocial/api/logic/removeComment.js +++ b/staff/luis-morlets/unsocial/api/logic/removeComment.js @@ -1,31 +1,46 @@ -import { storage } from '../data/index.js' +import db from 'dat' import { validate } from 'com' +const { ObjectId } = db + export default (userId, postId, commentId) => { validate.id(userId, 'userId') validate.id(postId, 'postId') validate.id(commentId, 'commentId') - const { posts, users } = storage - - const found = users.some(({ id }) => id === userId) - - if (!found) throw new Error('user not found') - - const post = posts.find(({ id }) => id === postId) - - const { comments } = post - - const index = comments.findIndex(({ id }) => id === commentId) - - if (index < 0) throw new Error('comment not found') - - const { author } = comments[index] - - if (author !== userId) throw new Error('user is not author of comment') - - comments.splice(index, 1) - - storage.posts = posts + const userObjectId = ObjectId.createFromHexString(userId) + const postObjectId = ObjectId.createFromHexString(postId) + const commentObjectId = ObjectId.createFromHexString(commentId) + + return Promise.all([ + db.users.findOne({ _id: userObjectId }), + db.posts.findOne({ _id: postObjectId }) + ]) + .catch(error => { throw new Error(error.message) }) + .then(([user, post]) => { + if (!user) throw new Error("user not found") + if (!post) throw new Error("post not found") + + const { comments } = post + + const comment = comments.find(comment => comment._id.equals(commentId)) + + if (!comment) throw new Error("comment not found") + + const { author } = comment + + if (!author.equals(userId)) { + throw new Error("user is not author") + } + return db.posts.updateOne({ _id: postObjectId }, + { + $pull: { + comments: { _id: commentObjectId }, + }, + } + ) + .catch(error => { throw new Error(error.message) }) + .then(_ => { }) + }) } \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/logic/removeComment.test.js b/staff/luis-morlets/unsocial/api/logic/removeComment.test.js index 476b0634a..9d677e2d1 100644 --- a/staff/luis-morlets/unsocial/api/logic/removeComment.test.js +++ b/staff/luis-morlets/unsocial/api/logic/removeComment.test.js @@ -1,7 +1,16 @@ +import db from 'dat' + import removeComment from './removeComment.js' -try { - removeComment('m2wd7pkr7xq', 'm2xaozivndc', 'm32e79kpesi') -} catch (error) { - console.error(error) -} \ No newline at end of file +db.connect("mongodb://127.0.0.1:27017/unsocial-test") + .then(() => { + try { + return removeComment("672e2c487f1acbd7a5009c67", "67321930d260445bfba74342", "6732267a7b1efe270b964d5b") + .then(console.log) + .catch(console.error) + } catch (error) { + console.error(error); + } + }) + .catch(console.error) + .finally(() => db.disconnect()) \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/package-lock.json b/staff/luis-morlets/unsocial/api/package-lock.json index 8be6d8149..c630c9989 100644 --- a/staff/luis-morlets/unsocial/api/package-lock.json +++ b/staff/luis-morlets/unsocial/api/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "com": "file:../com", "cors": "^2.8.5", + "dat": "file:../dat", "express": "^4.21.1" } }, @@ -18,6 +19,13 @@ "version": "1.0.0", "license": "ISC" }, + "../dat": { + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "mongodb": "^6.10.0" + } + }, "node_modules/accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", @@ -142,6 +150,10 @@ "node": ">= 0.10" } }, + "node_modules/dat": { + "resolved": "../dat", + "link": true + }, "node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", diff --git a/staff/luis-morlets/unsocial/api/package.json b/staff/luis-morlets/unsocial/api/package.json index 8b71d6d0b..39e0ca7d8 100644 --- a/staff/luis-morlets/unsocial/api/package.json +++ b/staff/luis-morlets/unsocial/api/package.json @@ -15,6 +15,7 @@ "dependencies": { "com": "file:../com", "cors": "^2.8.5", + "dat": "file:../dat", "express": "^4.21.1" } } diff --git a/staff/luis-morlets/unsocial/api/test/add-comment.sh b/staff/luis-morlets/unsocial/api/test/add-comment.sh index aa1954223..df7cb652f 100644 --- a/staff/luis-morlets/unsocial/api/test/add-comment.sh +++ b/staff/luis-morlets/unsocial/api/test/add-comment.sh @@ -1 +1 @@ - curl -H 'Authorization: Basic m2wd7pkr7xq' -H 'Content-Type: application/json' -d '{"text":"Bolivar te anda buscando la negra Matea"}' http://localhost:8080/posts/m2xaozivndc/comments -v \ No newline at end of file + curl -H 'Authorization: Basic 672e20b8106be73d00f7ee7b' -H 'Content-Type: application/json' -d '{"text":"Bolivar te anda buscando la negra Matea"}' http://localhost:8080/posts/6731bc157694cc12fa4aa6ce/comments -v \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/test/authenticate-user.sh b/staff/luis-morlets/unsocial/api/test/authenticate-user.sh index 3b6c86fbd..163b26e78 100644 --- a/staff/luis-morlets/unsocial/api/test/authenticate-user.sh +++ b/staff/luis-morlets/unsocial/api/test/authenticate-user.sh @@ -1 +1 @@ - curl -H 'Content-Type: application/json' -d '{"username":"pepitogrillo","password":"123123123"}' http://localhost:8080/authenticate -v \ No newline at end of file + curl -H 'Content-Type: application/json' -d '{"username":"simoncito","password":"123123123"}' http://localhost:8080/authenticate -v \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/test/create-post.sh b/staff/luis-morlets/unsocial/api/test/create-post.sh index c75a7bed5..cfdb0c112 100644 --- a/staff/luis-morlets/unsocial/api/test/create-post.sh +++ b/staff/luis-morlets/unsocial/api/test/create-post.sh @@ -1 +1 @@ - curl -H 'Authorization: Basic m2wd7pkr7xq' -H 'Content-Type: application/json' -d '{"image":"https://pixabay.com/get/g06da7d838998e600f884be0c6558604c482fa15c277d7900f4dc77dee8cc3050c9b5368341311c84f0aa204aa7b82a3e_1280.jpg","text":"En la chamba"}' http://localhost:8080/posts -v \ No newline at end of file + curl -H 'Authorization: Basic 672e2c487f1acbd7a5009c67' -H 'Content-Type: application/json' -d '{"image":"https://pixabay.com/get/g06da7d838998e600f884be0c6558604c482fa15c277d7900f4dc77dee8cc3050c9b5368341311c84f0aa204aa7b82a3e_1280.jpg","text":"En la chamba"}' http://localhost:8080/posts -v \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/test/delete-post.sh b/staff/luis-morlets/unsocial/api/test/delete-post.sh index 5dafa1a5c..30141dc96 100644 --- a/staff/luis-morlets/unsocial/api/test/delete-post.sh +++ b/staff/luis-morlets/unsocial/api/test/delete-post.sh @@ -1 +1 @@ - curl -H 'Authorization: Basic m2wd7pkr7xq' -X DELETE http://localhost:8080/posts/m2xjhal531h -v \ No newline at end of file + curl -H 'Authorization: Basic 672e2c487f1acbd7a5009c67' -X DELETE http://localhost:8080/posts/672e40d1c379b39ec9410cd3 -v \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/test/get-comments.sh b/staff/luis-morlets/unsocial/api/test/get-comments.sh index e55e60523..6f438677a 100644 --- a/staff/luis-morlets/unsocial/api/test/get-comments.sh +++ b/staff/luis-morlets/unsocial/api/test/get-comments.sh @@ -1 +1 @@ -curl -H 'Authorization: Basic m2x9yvtmjgu' http://localhost:8080/posts/m2xaozivndc/comments -v \ No newline at end of file +curl -H 'Authorization: Basic 672e2c487f1acbd7a5009c67' http://localhost:8080/posts/67331278d9522b9878546bd3/comments -v \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/test/get-posts.sh b/staff/luis-morlets/unsocial/api/test/get-posts.sh index 47f362af3..c423cd267 100644 --- a/staff/luis-morlets/unsocial/api/test/get-posts.sh +++ b/staff/luis-morlets/unsocial/api/test/get-posts.sh @@ -1 +1 @@ - curl -H 'Authorization: Basic m2wd7pkr7xq' http://localhost:8080/posts -v \ No newline at end of file + curl -H 'Authorization: Basic 672e2c487f1acbd7a5009c67' http://localhost:8080/posts -v \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/test/get-user-name.sh b/staff/luis-morlets/unsocial/api/test/get-user-name.sh index 990425472..63fa7212b 100644 --- a/staff/luis-morlets/unsocial/api/test/get-user-name.sh +++ b/staff/luis-morlets/unsocial/api/test/get-user-name.sh @@ -1 +1 @@ -curl -H 'Authorization: Basic m2wakjmutke' http://localhost:8080/users/m2wakjmutke/name -v \ No newline at end of file +curl -H 'Authorization: Basic 672e20b8106be73d00f7ee7b' http://localhost:8080/users/672e2c487f1acbd7a5009c67/name -v \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/test/likes-interaction.sh b/staff/luis-morlets/unsocial/api/test/likes-interaction.sh index c44655f80..64f410998 100644 --- a/staff/luis-morlets/unsocial/api/test/likes-interaction.sh +++ b/staff/luis-morlets/unsocial/api/test/likes-interaction.sh @@ -1 +1 @@ -curl -H 'Authorization: Basic m2wd1d38rhe' -X PATCH http://localhost:8080/posts/m2xaozivndc/likes -v \ No newline at end of file +curl -H 'Authorization: Basic 672e20b8106be73d00f7ee7b' -X PATCH http://localhost:8080/posts/6731bc157694cc12fa4aa6ce/likes -v \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/test/register-user.sh b/staff/luis-morlets/unsocial/api/test/register-user.sh index 16867f646..0efc2b780 100644 --- a/staff/luis-morlets/unsocial/api/test/register-user.sh +++ b/staff/luis-morlets/unsocial/api/test/register-user.sh @@ -1 +1 @@ - curl -H 'Content-Type: application/json' -d '{"name":"Pepito Grillo","email":"pepito@grillo.com","username":"pepitogrillo","password":"123123123","password-repeat":"123123123"}' http://localhost:8080/register -v \ No newline at end of file + curl -H 'Content-Type: application/json' -d '{"name":"Simon Bolivar","email":"simon@bolivar.com","username":"simoncito","password":"123123123","password-repeat":"123123123"}' http://localhost:8080/register -v \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/api/test/remove-comment.sh b/staff/luis-morlets/unsocial/api/test/remove-comment.sh index 69451025e..66bba7388 100644 --- a/staff/luis-morlets/unsocial/api/test/remove-comment.sh +++ b/staff/luis-morlets/unsocial/api/test/remove-comment.sh @@ -1 +1 @@ -curl -H 'Authorization: Basic m2wd7pkr7xq' -X DELETE http://localhost:8080/posts/m2xaozivndc/comments/m32dvxttqm -v \ No newline at end of file +curl -H 'Authorization: Basic 672e20b8106be73d00f7ee7b' -X DELETE http://localhost:8080/posts/6731bc157694cc12fa4aa6ce/comments/6731bcb97694cc12fa4aa6cf -v \ No newline at end of file diff --git a/staff/luis-morlets/unsocial/app/src/components/functional/PostItem.jsx b/staff/luis-morlets/unsocial/app/src/components/functional/PostItem.jsx index ea2d7e8e0..140835e38 100644 --- a/staff/luis-morlets/unsocial/app/src/components/functional/PostItem.jsx +++ b/staff/luis-morlets/unsocial/app/src/components/functional/PostItem.jsx @@ -12,7 +12,7 @@ import './PostItem.css' export default function PostItem({ post, onLiked, onDeleted, onCommented, onCommentRemoved }) { const [view, setView] = useState(null) - const { id, author, image, text, date, liked, likedBy, comments } = post + const { id, author, image, text, date, liked, likes, comments } = post const handleLikeClick = () => { try { @@ -71,7 +71,7 @@ export default function PostItem({ post, onLiked, onDeleted, onCommented, onComm