mirror of
https://github.com/jorgev259/soc_site-astro.git
synced 2025-06-29 07:57:41 +00:00
Set up sequelize
This commit is contained in:
parent
6833439a4a
commit
87c08df02b
47 changed files with 2171 additions and 6 deletions
33
src/graphql/resolvers/queries/user.js
Normal file
33
src/graphql/resolvers/queries/user.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { Op } from 'sequelize'
|
||||
import { composeResolvers } from '@graphql-tools/resolvers-composition'
|
||||
|
||||
import info from '@/next/constants/info.json'
|
||||
import { hasRole } from '@/server/utils/resolvers'
|
||||
import { getUser } from '@/next/utils/getSession'
|
||||
|
||||
const { permissions } = info
|
||||
|
||||
const resolversComposition = { 'Query.users': hasRole('MANAGE_USER') }
|
||||
const resolvers = {
|
||||
Query: {
|
||||
me: (parent, args, { db }) => getUser(db),
|
||||
permissions: () => permissions,
|
||||
roles: (parent, args, { db }) => db.models.role.findAll(),
|
||||
users: (parent, args, { db }) => {
|
||||
const search = args.search.trim()
|
||||
if (search.length < 3) return []
|
||||
|
||||
return db.models.user.findAll({
|
||||
where: {
|
||||
[Op.or]: [
|
||||
{ username: { [Op.like]: `%${search}%` } },
|
||||
{ email: search }
|
||||
]
|
||||
}
|
||||
})
|
||||
},
|
||||
user: async (_, { user }, { db }) => user
|
||||
}
|
||||
}
|
||||
|
||||
export default composeResolvers(resolvers, resolversComposition)
|
||||
Loading…
Add table
Add a link
Reference in a new issue