Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 357b6a3

Browse files
committed
Bug fix
1 parent 3df9063 commit 357b6a3

File tree

3 files changed

+36
-52
lines changed

3 files changed

+36
-52
lines changed

src/adapters/fauna/setup.mjs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,6 @@ async function main() {
111111
})
112112
)
113113

114-
await client.query(
115-
q.CreateIndex({
116-
name: 'followers_by_user',
117-
source: q.Collection('user_followers'),
118-
unique: false,
119-
terms: [
120-
{
121-
field: ['data', 'user'],
122-
},
123-
],
124-
})
125-
)
126-
127114
await client.query(
128115
q.CreateIndex({
129116
name: 'unique_user_and_follower',

src/pages/api/fauna/goals/get-current-goal.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,34 @@ const FaunaCreateHandler: NextApiHandler = async (
3535
q.Index('all_goals_by_participant'),
3636
q.Ref(q.Collection('users'), userId)
3737
)
38-
)
38+
),
39+
null
40+
),
41+
goalParticipantDoc: q.If(
42+
q.Not(q.IsNull(q.Var('goalParticipantRef'))),
43+
q.Get(q.Var('goalParticipantRef')),
44+
null
45+
),
46+
goalRef: q.If(
47+
q.Not(q.IsNull(q.Var('goalParticipantDoc'))),
48+
q.Select(['data', 'goal'], q.Var('goalParticipantDoc')),
49+
null
3950
),
40-
goalParticipantDoc: q.Get(q.Var('goalParticipantRef')),
41-
goalRef: q.Select(['data', 'goal'], q.Var('goalParticipantDoc')),
4251
},
43-
{
44-
id: q.Select(['id'], q.Var('goalRef')),
45-
title: q.Select(['data', 'title'], q.Get(q.Var('goalRef'))),
46-
}
52+
q.If(
53+
q.Not(q.IsNull(q.Var('goalRef'))),
54+
{
55+
id: q.Select(['id'], q.Var('goalRef')),
56+
title: q.Select(['data', 'title'], q.Get(q.Var('goalRef'))),
57+
},
58+
null
59+
)
4760
)
4861
)
4962

5063
res.status(200).json({ goal: response })
5164
} catch (error) {
65+
console.error(error)
5266
console.error({ msg: error.message })
5367
res.status(500).json({ message: error.message })
5468
}

src/pages/api/fauna/who-to-follow.ts

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,22 @@ const FaunaCreateHandler: NextApiHandler = async (
2626

2727
try {
2828
const response: any = await client.query(
29-
q.Map(
30-
q.Paginate(
31-
q.Difference(
32-
q.Documents(q.Collection('users')),
33-
q.Union(
34-
q.Match(
35-
q.Index('followers_by_user'),
36-
q.Ref(q.Collection('users'), userId)
37-
),
38-
q.Match(
39-
q.Index('user_by_username'),
40-
(session.user as User).username
41-
)
42-
)
43-
)
44-
),
45-
(userRef) => {
46-
const userDoc = q.Get(userRef)
47-
return {
48-
id: q.Select(['ref', 'id'], userDoc),
49-
name: q.Select(['data', 'name'], userDoc, null),
50-
image: q.Select(['data', 'image'], userDoc, null),
51-
username: q.Select(['data', 'username'], userDoc, null),
52-
account: {
53-
firstName: q.Select(
54-
['data', 'account', 'firstName'],
55-
userDoc,
56-
null
57-
),
58-
},
59-
}
29+
q.Map(q.Paginate(q.Documents(q.Collection('users'))), (userRef) => {
30+
const userDoc = q.Get(userRef)
31+
return {
32+
id: q.Select(['ref', 'id'], userDoc),
33+
name: q.Select(['data', 'name'], userDoc, null),
34+
image: q.Select(['data', 'image'], userDoc, null),
35+
username: q.Select(['data', 'username'], userDoc, null),
36+
account: {
37+
firstName: q.Select(
38+
['data', 'account', 'firstName'],
39+
userDoc,
40+
null
41+
),
42+
},
6043
}
61-
)
44+
})
6245
)
6346

6447
res.status(200).json({ users: response.data })

0 commit comments

Comments
 (0)