-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
why 게시글 좋아요 toggle 시 서버에 값이 반영되어야 함 이전의 좋아요, 좋아요취소가 따로 있어서 복잡 how 댓글의 좋아요 좋아요 취소를 하나로 합치고 서버쪽에서 구분해서 쿼리하도록 분리
- Loading branch information
1 parent
fdb1e8e
commit 55a5680
Showing
4 changed files
with
28 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,5 +61,5 @@ type Query { | |
} | ||
|
||
type Mutation { | ||
updateLike(feedId: Int): Boolean | ||
updateLike(feedId: Int, count: Int): Boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,12 @@ import db from '../../db'; | |
import { | ||
MATCH_NEW_FEEDS, | ||
MATCH_FEEDS, | ||
UPDATE_LIKE | ||
UPDATE_LIKE, | ||
DELETE_LIKE | ||
} from '../../schema/feed/query'; | ||
import { IKey } from '../../schema/commonTypes'; | ||
import neo4j from 'neo4j-driver'; | ||
import console = require('console'); | ||
|
||
const session = db.session(); | ||
|
||
|
@@ -39,8 +41,6 @@ const Datetransform = object => { | |
if (object.hasOwnProperty(property)) { | ||
const propertyValue = object[property]; | ||
if (neo4j.isInt(propertyValue)) { | ||
// console.log(neo4j.integer.toNumber(propertyValue)); | ||
// console.log('tet', propertyValue); | ||
returnobj[property] = String(propertyValue); | ||
} else if (toString.call(propertyValue) === '[object String]') { | ||
let temp = {}; | ||
|
@@ -71,7 +71,6 @@ const ParseResultRecords = records => { | |
arr = { ...arr, ...temp }; | ||
} else if (node instanceof neo4j.types.Integer) { | ||
const temp = {}; | ||
|
||
temp[nodeKey] = String(node); | ||
arr = { ...arr, ...temp }; | ||
} else if (toString.call(node) === '[object Array]') { | ||
|
@@ -112,21 +111,27 @@ export default { | |
}, | ||
|
||
Mutation: { | ||
updateLike: async (_, { feedId }, { req }) => { | ||
let userEmail1 = '[email protected]'; | ||
updateLike: async (_, { feedId, count }, { req }) => { | ||
let userEmail1 = ''; | ||
if (!req.user) { | ||
console.log('사용자 정보가 없습니다 다시 로그인해 주세요'); | ||
return false; | ||
} | ||
userEmail1 = req.user.email; | ||
console.log(req.user); | ||
|
||
const result = await session.run(UPDATE_LIKE, { | ||
useremail: userEmail1, | ||
feedId | ||
}); | ||
let result; | ||
if (count > 0) { | ||
result = await session.run(UPDATE_LIKE, { | ||
useremail: userEmail1, | ||
feedId | ||
}); | ||
} else { | ||
result = await session.run(DELETE_LIKE, { | ||
useremail: userEmail1, | ||
feedId | ||
}); | ||
} | ||
|
||
console.log('true', result); | ||
console.log('result: ', result); | ||
return true; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,26 +15,15 @@ order by feed.createdAt desc | |
LIMIT {first} | ||
`; | ||
|
||
const MATCH_NEW_FEEDS2 = `MATCH (user:User { email: '[email protected]' })-[:AUTHOR]->(feed:Feed) | ||
where feed.createdAt < datetime('9999-12-31T09:29:26.050Z') | ||
RETURN feed`; | ||
|
||
const UPDATE_LIKE = ` | ||
MATCH (u:User),(f:Feed) | ||
WHERE u.email = {useremail} AND ID(f) = {feedId} | ||
MERGE (u)-[r:LIKE]->(f) | ||
RETURN type(r)`; | ||
|
||
const DELETE_LIKE = ` | ||
MATCH (u:User),(f:Feed) | ||
MATCH (u:User)-[r:LIKE]->(f:Feed) | ||
WHERE u.email = {useremail} AND ID(f) = {feedId} | ||
MERGE (u)-[r:LIKE]->(f) | ||
RETURN type(r)`; | ||
delete r`; | ||
|
||
export { | ||
MATCH_NEW_FEEDS, | ||
MATCH_NEW_FEEDS2, | ||
MATCH_FEEDS, | ||
UPDATE_LIKE, | ||
DELETE_LIKE | ||
}; | ||
export { MATCH_NEW_FEEDS, MATCH_FEEDS, UPDATE_LIKE, DELETE_LIKE }; |