mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
simple create room mutation
This commit is contained in:
parent
8229be36b2
commit
d548fc2b84
@ -459,6 +459,7 @@ export default shield(
|
|||||||
switchUserRole: isAdmin,
|
switchUserRole: isAdmin,
|
||||||
markTeaserAsViewed: allow,
|
markTeaserAsViewed: allow,
|
||||||
saveCategorySettings: isAuthenticated,
|
saveCategorySettings: isAuthenticated,
|
||||||
|
CreateRoom: isAuthenticated,
|
||||||
},
|
},
|
||||||
User: {
|
User: {
|
||||||
email: or(isMyOwn, isAdmin),
|
email: or(isMyOwn, isAdmin),
|
||||||
|
|||||||
34
backend/src/schema/resolvers/rooms.ts
Normal file
34
backend/src/schema/resolvers/rooms.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
export default {
|
||||||
|
Mutation: {
|
||||||
|
CreateRoom: async (_parent, params, context, _resolveInfo) => {
|
||||||
|
const { userId } = params
|
||||||
|
const { user: { id: currentUserId } } = context
|
||||||
|
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())
|
||||||
|
RETURN room
|
||||||
|
`
|
||||||
|
const createRommTxResponse = await await transaction.run(
|
||||||
|
createRoomCypher,
|
||||||
|
{ userId, currentUserId }
|
||||||
|
)
|
||||||
|
const [room] = await createRommTxResponse.records.map((record) =>
|
||||||
|
record.get('room'),
|
||||||
|
)
|
||||||
|
return room
|
||||||
|
})
|
||||||
|
try {
|
||||||
|
const room = await writeTxResultPromise
|
||||||
|
return room
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(error)
|
||||||
|
} finally {
|
||||||
|
session.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
13
backend/src/schema/types/type/Room.gql
Normal file
13
backend/src/schema/types/type/Room.gql
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
type Room {
|
||||||
|
id: ID!
|
||||||
|
createdAt: String
|
||||||
|
updatedAt: String
|
||||||
|
|
||||||
|
users: [User!]! @relation(name: "CHATS_IN", direction: "IN")
|
||||||
|
}
|
||||||
|
|
||||||
|
type Mutation {
|
||||||
|
CreateRoom(
|
||||||
|
userId: ID!
|
||||||
|
): Room
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user