stacker.news/api/resolvers/user.js

30 lines
959 B
JavaScript
Raw Normal View History

2021-03-25 19:29:24 +00:00
export default {
Query: {
me: async (parent, args, { models, me }) =>
me ? await models.user.findUnique({ where: { id: me.id } }) : null,
2021-04-22 22:14:32 +00:00
user: async (parent, { name }, { models }) => {
return await models.user.findUnique({ where: { name } })
},
2021-03-25 19:29:24 +00:00
users: async (parent, args, { models }) =>
await models.user.findMany()
},
User: {
2021-04-22 22:14:32 +00:00
nitems: async (user, args, { models }) => {
return await models.item.count({ where: { userId: user.id, parentId: null } })
},
ncomments: async (user, args, { models }) => {
return await models.item.count({ where: { userId: user.id, parentId: { not: null } } })
},
2021-04-27 21:30:58 +00:00
stacked: async (user, args, { models }) => {
const [{ sum }] = await models.$queryRaw`
SELECT sum("Vote".sats)
FROM "Item"
LEFT JOIN "Vote" on "Vote"."itemId" = "Item".id
WHERE "Item"."userId" = ${user.id}`
return sum
},
2021-04-22 22:14:32 +00:00
sats: () => 0
2021-03-25 19:29:24 +00:00
}
}