Update to RW 8.3.0 + Project CRUD complete
This commit is contained in:
14
api/db/migrations/20240927031102_/migration.sql
Normal file
14
api/db/migrations/20240927031102_/migration.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the `ProjectImage` table. If the table is not empty, all the data it contains will be lost.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "ProjectImage" DROP CONSTRAINT "ProjectImage_projectId_fkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Project" ADD COLUMN "images" TEXT[];
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "ProjectImage";
|
||||
@@ -65,20 +65,12 @@ model Tag {
|
||||
projects Project[]
|
||||
}
|
||||
|
||||
model ProjectImage {
|
||||
id Int @id @default(autoincrement())
|
||||
fileId String
|
||||
|
||||
Project Project? @relation(fields: [projectId], references: [id])
|
||||
projectId Int?
|
||||
}
|
||||
|
||||
model Project {
|
||||
id Int @id @default(autoincrement())
|
||||
id Int @id @default(autoincrement())
|
||||
title String
|
||||
description String @default("No description provided")
|
||||
images ProjectImage[]
|
||||
description String @default("No description provided")
|
||||
images String[]
|
||||
date DateTime
|
||||
links String[] @default([])
|
||||
links String[] @default([])
|
||||
tags Tag[]
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
"dependencies": {
|
||||
"@fastify/cors": "^9.0.1",
|
||||
"@fastify/rate-limit": "^9.1.0",
|
||||
"@redwoodjs/api": "8.0.0",
|
||||
"@redwoodjs/api-server": "8.0.0",
|
||||
"@redwoodjs/auth-dbauth-api": "8.0.0",
|
||||
"@redwoodjs/graphql-server": "8.0.0",
|
||||
"@redwoodjs/api": "8.3.0",
|
||||
"@redwoodjs/api-server": "8.3.0",
|
||||
"@redwoodjs/auth-dbauth-api": "8.3.0",
|
||||
"@redwoodjs/graphql-server": "8.3.0",
|
||||
"@tus/file-store": "^1.4.0",
|
||||
"@tus/server": "^1.7.0",
|
||||
"graphql-scalars": "^1.23.0",
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
export const schema = gql`
|
||||
type ProjectImage {
|
||||
id: Int!
|
||||
fileId: URL!
|
||||
Project: Project
|
||||
projectId: Int
|
||||
}
|
||||
|
||||
type Query {
|
||||
projectImages: [ProjectImage!]! @requireAuth
|
||||
projectImage(id: Int!): ProjectImage @requireAuth
|
||||
}
|
||||
|
||||
input CreateProjectImageInput {
|
||||
fileId: URL!
|
||||
projectId: Int
|
||||
}
|
||||
|
||||
input UpdateProjectImageInput {
|
||||
fileId: URL
|
||||
projectId: Int
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
createProjectImage(input: CreateProjectImageInput!): ProjectImage!
|
||||
@requireAuth
|
||||
updateProjectImage(
|
||||
id: Int!
|
||||
input: UpdateProjectImageInput!
|
||||
): ProjectImage! @requireAuth
|
||||
deleteProjectImage(id: Int!): ProjectImage! @requireAuth
|
||||
}
|
||||
`
|
||||
@@ -3,7 +3,7 @@ export const schema = gql`
|
||||
id: Int!
|
||||
title: String!
|
||||
description: String!
|
||||
images: [ProjectImage]!
|
||||
images: [String]!
|
||||
date: DateTime!
|
||||
links: [URL]!
|
||||
tags: [Tag]!
|
||||
@@ -19,6 +19,8 @@ export const schema = gql`
|
||||
description: String!
|
||||
date: DateTime!
|
||||
links: [URL]!
|
||||
images: [URL]!
|
||||
tags: [Int!]
|
||||
}
|
||||
|
||||
input UpdateProjectInput {
|
||||
@@ -26,6 +28,9 @@ export const schema = gql`
|
||||
description: String
|
||||
date: DateTime
|
||||
links: [URL]!
|
||||
images: [URL]!
|
||||
tags: [Int!]
|
||||
removeTags: [Int!]
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
import type {
|
||||
QueryResolvers,
|
||||
MutationResolvers,
|
||||
ProjectImageRelationResolvers,
|
||||
} from 'types/graphql'
|
||||
|
||||
import { db } from 'src/lib/db'
|
||||
|
||||
export const projectImages: QueryResolvers['projectImages'] = () => {
|
||||
return db.projectImage.findMany()
|
||||
}
|
||||
|
||||
export const projectImage: QueryResolvers['projectImage'] = ({ id }) => {
|
||||
return db.projectImage.findUnique({
|
||||
where: { id },
|
||||
})
|
||||
}
|
||||
|
||||
export const createProjectImage: MutationResolvers['createProjectImage'] = ({
|
||||
input,
|
||||
}) => {
|
||||
return db.projectImage.create({
|
||||
data: input,
|
||||
})
|
||||
}
|
||||
|
||||
export const updateProjectImage: MutationResolvers['updateProjectImage'] = ({
|
||||
id,
|
||||
input,
|
||||
}) => {
|
||||
return db.projectImage.update({
|
||||
data: input,
|
||||
where: { id },
|
||||
})
|
||||
}
|
||||
|
||||
export const deleteProjectImage: MutationResolvers['deleteProjectImage'] = ({
|
||||
id,
|
||||
}) => {
|
||||
return db.projectImage.delete({
|
||||
where: { id },
|
||||
})
|
||||
}
|
||||
|
||||
export const ProjectImage: ProjectImageRelationResolvers = {
|
||||
Project: (_obj, { root }) => {
|
||||
return db.projectImage.findUnique({ where: { id: root?.id } }).Project()
|
||||
},
|
||||
}
|
||||
@@ -15,15 +15,34 @@ export const project: QueryResolvers['project'] = ({ id }) =>
|
||||
|
||||
export const createProject: MutationResolvers['createProject'] = ({ input }) =>
|
||||
db.project.create({
|
||||
data: input,
|
||||
data: {
|
||||
title: input.title,
|
||||
description: input.description,
|
||||
date: input.date,
|
||||
links: input.links,
|
||||
images: input.images,
|
||||
tags: {
|
||||
connect: input.tags.map((tagId) => ({ id: tagId })),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export const updateProject: MutationResolvers['updateProject'] = ({
|
||||
export const updateProject: MutationResolvers['updateProject'] = async ({
|
||||
id,
|
||||
input,
|
||||
}) =>
|
||||
db.project.update({
|
||||
data: input,
|
||||
data: {
|
||||
title: input.title,
|
||||
description: input.description,
|
||||
date: input.date,
|
||||
links: input.links,
|
||||
images: input.images,
|
||||
tags: {
|
||||
disconnect: input.removeTags?.map((tagId) => ({ id: tagId })),
|
||||
connect: input.tags?.map((tagId) => ({ id: tagId })),
|
||||
},
|
||||
},
|
||||
where: { id },
|
||||
})
|
||||
|
||||
@@ -33,8 +52,6 @@ export const deleteProject: MutationResolvers['deleteProject'] = ({ id }) =>
|
||||
})
|
||||
|
||||
export const Project: ProjectRelationResolvers = {
|
||||
images: (_obj, { root }) =>
|
||||
db.project.findUnique({ where: { id: root?.id } }).images(),
|
||||
tags: (_obj, { root }) =>
|
||||
db.project.findUnique({ where: { id: root?.id } }).tags(),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user