feat(backend): unread rooms query

This commit is contained in:
Moriz Wahl 2023-07-14 13:25:57 +02:00
parent b933305cad
commit f4567b14ff
2 changed files with 22 additions and 0 deletions

View File

@ -25,6 +25,27 @@ export default {
} }
return resolved return resolved
}, },
UnreadRooms: async (object, params, context, resolveInfo) => {
const {
user: { id: currentUserId },
} = context
const session = context.driver.session()
const readTxResultPromise = session.readTransaction(async (transaction) => {
const unreadRoomsCypher = `
MATCH (:User { id: $currentUserId })-[:CHATS_IN]->(room:Room)<-[:INSIDE]-(message:Message)<-[:CREATED]-(user:User)
WHERE NOT message.seen AND NOT user.id = $currentUserId
RETURN toString(COUNT(room)) AS count
`
const unreadRoomsTxResponse = await transaction.run(unreadRoomsCypher, { currentUserId })
return unreadRoomsTxResponse.records.map((record) => record.get('count'))
})
try {
const count = await readTxResultPromise
return count
} finally {
session.close()
}
},
}, },
Mutation: { Mutation: {
CreateRoom: async (_parent, params, context, _resolveInfo) => { CreateRoom: async (_parent, params, context, _resolveInfo) => {

View File

@ -25,4 +25,5 @@ type Mutation {
type Query { type Query {
Room: [Room] Room: [Room]
UnreadRooms: Int
} }