fix room properties

This commit is contained in:
Moriz Wahl 2023-06-14 12:16:44 +02:00
parent d548fc2b84
commit 8b037ffa73

View File

@ -1,20 +1,24 @@
import { v4 as uuid } from 'uuid'
export default { export default {
Mutation: { Mutation: {
CreateRoom: async (_parent, params, context, _resolveInfo) => { CreateRoom: async (_parent, params, context, _resolveInfo) => {
const { userId } = params const { userId } = params
const { user: { id: currentUserId } } = context const { user: { id: currentUserId } } = context
const roomId = uuid()
const session = context.driver.session() const session = context.driver.session()
const writeTxResultPromise = session.writeTransaction(async (transaction) => { const writeTxResultPromise = session.writeTransaction(async (transaction) => {
const createRoomCypher = ` const createRoomCypher = `
MATCH (currentUser:User { id: $currentUserId }) MATCH (currentUser:User { id: $currentUserId })
MATCH (user:User { id: $userId }) MATCH (user:User { id: $userId })
MERGE (currentUser)-[:CHATS_IN]->(room:Room)<-[:CHATS_IN]-(user) MERGE (currentUser)-[:CHATS_IN]->(room:Room)<-[:CHATS_IN]-(user)
SET room.createdAt = toString(datetime()) SET room.createdAt = toString(datetime()),
RETURN room room.id = $roomId
RETURN room { .* }
` `
const createRommTxResponse = await await transaction.run( const createRommTxResponse = await await transaction.run(
createRoomCypher, createRoomCypher,
{ userId, currentUserId } { userId, currentUserId, roomId }
) )
const [room] = await createRommTxResponse.records.map((record) => const [room] = await createRommTxResponse.records.map((record) =>
record.get('room'), record.get('room'),