2021-07-13 21:31:15 +03:00
|
|
|
import HttpError from '@wasp/core/HttpError.js'
|
|
|
|
|
2021-03-09 18:09:37 +03:00
|
|
|
export const getThoughts = async (args, context) => {
|
2021-07-13 21:31:15 +03:00
|
|
|
if (!context.user) { throw new HttpError(403) }
|
|
|
|
|
2021-03-09 18:09:37 +03:00
|
|
|
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 },
|
2021-03-09 18:09:37 +03:00
|
|
|
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) }
|
|
|
|
|
2021-03-09 18:09:37 +03:00
|
|
|
return context.entities.Tag.findMany({
|
|
|
|
orderBy: [{ name: 'asc' }],
|
2021-07-13 21:31:15 +03:00
|
|
|
where: {
|
|
|
|
user: { id: context.user.id }
|
|
|
|
}
|
2021-03-09 18:09:37 +03:00
|
|
|
})
|
|
|
|
}
|