wasp/examples/thoughts/ext/queries.js

26 lines
624 B
JavaScript
Raw Normal View History

2021-07-13 21:31:15 +03:00
import HttpError from '@wasp/core/HttpError.js'
export const getThoughts = async (args, context) => {
2021-07-13 21:31:15 +03:00
if (!context.user) { throw new HttpError(403) }
return context.entities.Thought.findMany({
orderBy: [{ createdAt: 'desc' }],
include: { tags: true },
where: {
2021-07-13 21:31:15 +03:00
user: { id: context.user.id },
tags: { some: { name: args.tagName || undefined } }
}
})
}
export const getTags = async (args, context) => {
2021-07-13 21:31:15 +03:00
if (!context.user) { throw new HttpError(403) }
return context.entities.Tag.findMany({
orderBy: [{ name: 'asc' }],
2021-07-13 21:31:15 +03:00
where: {
user: { id: context.user.id }
}
})
}