use apoc.create.uuid to set id

This commit is contained in:
Moriz Wahl 2023-06-20 09:02:32 +02:00
parent 0cdbf17fbf
commit 8063e58ef2

View File

@ -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'),