override user._id with user.id to not expose internal db id

This commit is contained in:
Moriz Wahl 2023-06-16 12:38:13 +02:00
parent 64120a0009
commit 6a6efd5a23
2 changed files with 15 additions and 5 deletions

View File

@ -143,11 +143,11 @@ describe('Room', () => {
roomId: result.data.Room[0].id,
users: expect.arrayContaining([
{
_id: expect.any(String),
_id: 'chatting-user',
id: 'chatting-user',
},
{
_id: expect.any(String),
_id: 'other-chatting-user',
id: 'other-chatting-user',
},
]),
@ -174,11 +174,11 @@ describe('Room', () => {
roomId: result.data.Room[0].id,
users: expect.arrayContaining([
{
_id: expect.any(String),
_id: 'chatting-user',
id: 'chatting-user',
},
{
_id: expect.any(String),
_id: 'other-chatting-user',
id: 'other-chatting-user',
},
]),

View File

@ -9,7 +9,17 @@ export default {
params.filter.users_some = {
id: context.user.id,
}
return neo4jgraphql(object, params, context, resolveInfo)
const resolved = await neo4jgraphql(object, params, context, resolveInfo)
if (resolved) {
resolved.forEach((room) => {
if (room.users) {
room.users.forEach((user) => {
user._id = user.id
})
}
})
}
return resolved
},
},
Mutation: {