issue-152 wasn't quiet solved correctly it showed all parts

on the user's profile instead of only their own parts
This commit is contained in:
Kurt Hutten
2020-12-13 13:41:46 +11:00
parent 6ce4031cae
commit 5dc14a6e5a
8 changed files with 118 additions and 8 deletions

View File

@@ -14,7 +14,7 @@ export const schema = gql`
}
type Query {
parts: [Part!]!
parts(userName: String): [Part!]!
part(id: String!): Part
partByUserAndTitle(userName: String!, partTitle: String!): Part
}

View File

@@ -7,8 +7,18 @@ import {
import { requireAuth } from 'src/lib/auth'
import { requireOwnership } from 'src/lib/owner'
export const parts = () => {
return db.part.findMany({ where: { deleted: false } })
export const parts = ({ userName }) => {
if (!userName) {
return db.part.findMany({ where: { deleted: false } })
}
return db.part.findMany({
where: {
deleted: false,
user: {
userName,
},
},
})
}
export const part = ({ id }) => {