Skip to content
This repository has been archived by the owner on Jul 17, 2022. It is now read-only.

fix(neo4j): update user bugfix #352

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion basic-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ export function runBasicTests(options: TestOptions) {

test("updateUser", async () => {
const newName = "Updated Name"
await adapter.updateUser({ id: user.id, name: newName })
const returnedUser = await adapter.updateUser({
id: user.id,
name: newName,
})
expect(returnedUser.name).toBe(newName)

const dbUser = await db.user(user.id)
expect(dbUser.name).toBe(newName)
Expand Down
29 changes: 15 additions & 14 deletions packages/neo4j/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ export function Neo4jAdapter(session: Session): Adapter {
},

async getUser(id) {
return await read(`MATCH (u:User { id: $id }) RETURN properties(u)`, {
return await read(`MATCH (u:User { id: $id }) RETURN u{.*}`, {
id,
})
},

async getUserByEmail(email) {
return await read(
`MATCH (u:User { email: $email }) RETURN properties(u)`,
{ email }
)
return await read(`MATCH (u:User { email: $email }) RETURN u{.*}`, {
email,
})
},

async getUserByAccount(provider_providerAccountId) {
Expand All @@ -34,24 +33,26 @@ export function Neo4jAdapter(session: Session): Adapter {
provider: $provider,
providerAccountId: $providerAccountId
})
RETURN properties(u)`,
RETURN u{.*}`,
provider_providerAccountId
)
},

async updateUser(data) {
return await write(
`MATCH (u:User { id: $data.id })
SET u += $data
RETURN properties(u)`,
data
)
return (
await write(
`MATCH (u:User { id: $data.id })
SET u += $data
RETURN u{.*}`,
data
)
).u
},

async deleteUser(id) {
return await write(
`MATCH (u:User { id: $data.id })
WITH u, properties(u) AS properties
WITH u, u{.*} AS properties
DETACH DELETE u
RETURN properties`,
{ id }
Expand Down Expand Up @@ -107,7 +108,7 @@ export function Neo4jAdapter(session: Session): Adapter {
DETACH DELETE s
WITH count(s) AS c
MATCH (u:User)-[:HAS_SESSION]->(s:Session { sessionToken: $data.sessionToken })
RETURN s { .*, userId: u.id } AS session, properties(u) AS user`,
RETURN s { .*, userId: u.id } AS session, u{.*} AS user`,
{ sessionToken, now: new Date().toISOString() }
)

Expand Down