add parts data

This commit is contained in:
Kurt Hutten
2020-10-11 19:41:48 +11:00
parent f1dc6c28e4
commit b3456860d2
34 changed files with 1146 additions and 11 deletions

View File

@@ -0,0 +1,35 @@
export const schema = gql`
type Part {
id: Int!
title: String!
description: String!
code: String!
mainImage: String!
createdAt: DateTime!
}
type Query {
parts: [Part!]!
part(id: Int!): Part
}
input CreatePartInput {
title: String!
description: String!
code: String
mainImage: String
}
input UpdatePartInput {
title: String
description: String
code: String
mainImage: String
}
type Mutation {
createPart(input: CreatePartInput!): Part!
updatePart(id: Int!, input: UpdatePartInput!): Part!
deletePart(id: Int!): Part!
}
`

View File

@@ -0,0 +1,30 @@
import { db } from 'src/lib/db'
export const parts = () => {
return db.part.findMany()
}
export const part = ({ id }) => {
return db.part.findOne({
where: { id },
})
}
export const createPart = ({ input }) => {
return db.part.create({
data: input,
})
}
export const updatePart = ({ id, input }) => {
return db.part.update({
data: input,
where: { id },
})
}
export const deletePart = ({ id }) => {
return db.part.delete({
where: { id },
})
}

View File

@@ -0,0 +1,9 @@
/*
import { parts } from './parts'
*/
describe('parts', () => {
it('returns true', () => {
expect(true).toBe(true)
})
})