wasp/examples/thoughts/ext/queries.js
2021-07-13 21:09:18 +02:00

26 lines
624 B
JavaScript

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