Allow for new parts to be created

This commit is contained in:
Kurt Hutten
2020-11-08 18:39:56 +11:00
parent 8107c7dcea
commit 8fa017beed
10 changed files with 78 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
import { db } from 'src/lib/db'
import { requireAuth } from 'src/lib/auth'
import { requireOwnership } from 'src/lib/owner'
import { UserInputError } from '@redwoodjs/api'
export const users = () => {
requireAuth({ role: 'admin' })
@@ -43,6 +44,9 @@ export const updateUserByUserName = async ({ userName, input }) => {
if(input.userName) {
input.userName = input.userName.replace(/([^a-zA-Z\d_:])/g, '-')
}
if(input.userName && ['new', 'edit', 'update'].includes(input.userName)) { //TODO complete this and use a regexp so that it's not case sensitive, don't want someone with the userName eDiT
throw new UserInputError(`You've tried to used a protected word as you userName, try something other than `)
}
return db.user.update({
data: input,
where: { userName },
@@ -58,7 +62,7 @@ export const deleteUser = ({ id }) => {
export const User = {
Parts: (_obj, { root }) => db.user.findOne({ where: { id: root.id } }).Part(),
Part: (_obj, { root, ...rest }) => db.part.findOne({where: { title_userId: {
Part: (_obj, { root, ...rest }) => _obj.partTitle && db.part.findOne({where: { title_userId: {
title: _obj.partTitle,
userId: root.id,
}}}),