mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
use apoc.create.uuid to set id
This commit is contained in:
parent
0cdbf17fbf
commit
8063e58ef2
@ -1,4 +1,3 @@
|
||||
import { v4 as uuid } from 'uuid'
|
||||
import { neo4jgraphql } from 'neo4j-graphql-js'
|
||||
import Resolver from './helpers/Resolver'
|
||||
|
||||
@ -16,20 +15,20 @@ export default {
|
||||
CreateRoom: async (_parent, params, context, _resolveInfo) => {
|
||||
const { userId } = params
|
||||
const { user: { id: currentUserId } } = context
|
||||
const roomId = uuid()
|
||||
const session = context.driver.session()
|
||||
const writeTxResultPromise = session.writeTransaction(async (transaction) => {
|
||||
const createRoomCypher = `
|
||||
MATCH (currentUser:User { id: $currentUserId })
|
||||
MATCH (user:User { id: $userId })
|
||||
MERGE (currentUser)-[:CHATS_IN]->(room:Room)<-[:CHATS_IN]-(user)
|
||||
SET room.createdAt = toString(datetime()),
|
||||
room.id = $roomId
|
||||
ON CREATE SET
|
||||
room.createdAt = toString(datetime()),
|
||||
room.id = apoc.create.uuid()
|
||||
RETURN room { .* }
|
||||
`
|
||||
const createRommTxResponse = await await transaction.run(
|
||||
createRoomCypher,
|
||||
{ userId, currentUserId, roomId }
|
||||
{ userId, currentUserId }
|
||||
)
|
||||
const [room] = await createRommTxResponse.records.map((record) =>
|
||||
record.get('room'),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user