[resumes][feat] add resumeprofiles model (#316)

* [resumes][feat] add resumeprofiles model

* [resumes][fix] fix typo

* [resumes][chore] update migration file
pull/317/head
Keane Chan 2 years ago committed by GitHub
parent 0933cce7b5
commit b2b8f3b553
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,74 @@
/*
Warnings:
- You are about to drop the column `userId` on the `ResumesComment` table. All the data in the column will be lost.
- You are about to drop the column `userId` on the `ResumesCommentVote` table. All the data in the column will be lost.
- You are about to drop the column `userId` on the `ResumesResume` table. All the data in the column will be lost.
- You are about to drop the column `userId` on the `ResumesStar` table. All the data in the column will be lost.
- A unique constraint covering the columns `[commentId,resumesProfileId]` on the table `ResumesCommentVote` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[resumeId,resumesProfileId]` on the table `ResumesStar` will be added. If there are existing duplicate values, this will fail.
- Added the required column `resumesProfileId` to the `ResumesComment` table without a default value. This is not possible if the table is not empty.
- Added the required column `resumesProfileId` to the `ResumesCommentVote` table without a default value. This is not possible if the table is not empty.
- Added the required column `resumesProfileId` to the `ResumesResume` table without a default value. This is not possible if the table is not empty.
- Added the required column `resumesProfileId` to the `ResumesStar` table without a default value. This is not possible if the table is not empty.
*/
-- DropForeignKey
ALTER TABLE "ResumesComment" DROP CONSTRAINT "ResumesComment_userId_fkey";
-- DropForeignKey
ALTER TABLE "ResumesCommentVote" DROP CONSTRAINT "ResumesCommentVote_userId_fkey";
-- DropForeignKey
ALTER TABLE "ResumesResume" DROP CONSTRAINT "ResumesResume_userId_fkey";
-- DropForeignKey
ALTER TABLE "ResumesStar" DROP CONSTRAINT "ResumesStar_userId_fkey";
-- AlterTable
ALTER TABLE "ResumesComment" DROP COLUMN "userId",
ADD COLUMN "resumesProfileId" TEXT NOT NULL;
-- AlterTable
ALTER TABLE "ResumesCommentVote" DROP COLUMN "userId",
ADD COLUMN "resumesProfileId" TEXT NOT NULL;
-- AlterTable
ALTER TABLE "ResumesResume" DROP COLUMN "userId",
ADD COLUMN "resumesProfileId" TEXT NOT NULL;
-- AlterTable
ALTER TABLE "ResumesStar" DROP COLUMN "userId",
ADD COLUMN "resumesProfileId" TEXT NOT NULL;
-- CreateTable
CREATE TABLE "ResumesProfile" (
"id" TEXT NOT NULL,
"userId" TEXT NOT NULL,
CONSTRAINT "ResumesProfile_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "ResumesProfile_userId_key" ON "ResumesProfile"("userId");
-- CreateIndex
CREATE UNIQUE INDEX "ResumesCommentVote_commentId_resumesProfileId_key" ON "ResumesCommentVote"("commentId", "resumesProfileId");
-- CreateIndex
CREATE UNIQUE INDEX "ResumesStar_resumeId_resumesProfileId_key" ON "ResumesStar"("resumeId", "resumesProfileId");
-- AddForeignKey
ALTER TABLE "ResumesProfile" ADD CONSTRAINT "ResumesProfile_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ResumesResume" ADD CONSTRAINT "ResumesResume_resumesProfileId_fkey" FOREIGN KEY ("resumesProfileId") REFERENCES "ResumesProfile"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ResumesStar" ADD CONSTRAINT "ResumesStar_resumesProfileId_fkey" FOREIGN KEY ("resumesProfileId") REFERENCES "ResumesProfile"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ResumesComment" ADD CONSTRAINT "ResumesComment_resumesProfileId_fkey" FOREIGN KEY ("resumesProfileId") REFERENCES "ResumesProfile"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ResumesCommentVote" ADD CONSTRAINT "ResumesCommentVote_resumesProfileId_fkey" FOREIGN KEY ("resumesProfileId") REFERENCES "ResumesProfile"("id") ON DELETE CASCADE ON UPDATE CASCADE;

@ -37,18 +37,15 @@ model Session {
}
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
todos Todo[]
resumesResumes ResumesResume[]
resumesStars ResumesStar[]
resumesComments ResumesComment[]
resumesCommentVotes ResumesCommentVote[]
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
todos Todo[]
resumesProfile ResumesProfile?
}
model VerificationToken {
@ -88,45 +85,56 @@ model Company {
// Add Resumes project models here, prefix all models with "Resumes",
// use camelCase for field names, and try to name them consistently
// across all models in this file.
// End of Resumes project models.
model ResumesProfile {
id String @id @default(cuid())
userId String @unique
resumesResumes ResumesResume[]
resumesStars ResumesStar[]
resumesComments ResumesComment[]
resumesCommentVotes ResumesCommentVote[]
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
model ResumesResume {
id String @id @default(cuid())
userId String
title String @db.Text
id String @id @default(cuid())
resumesProfileId String
title String @db.Text
// TODO: Update role, experience, location to use Enums
role String @db.Text
experience String @db.Text
location String @db.Text
url String
additionalInfo String? @db.Text
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
stars ResumesStar[]
comments ResumesComment[]
role String @db.Text
experience String @db.Text
location String @db.Text
url String
additionalInfo String? @db.Text
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
resumesProfile ResumesProfile @relation(fields: [resumesProfileId], references: [id], onDelete: Cascade)
stars ResumesStar[]
comments ResumesComment[]
}
model ResumesStar {
id String @id @default(cuid())
resumeId String
userId String
createdAt DateTime @default(now())
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
resume ResumesResume @relation(fields: [resumeId], references: [id], onDelete: Cascade)
id String @id @default(cuid())
resumesProfileId String
resumeId String
createdAt DateTime @default(now())
resumesProfile ResumesProfile @relation(fields: [resumesProfileId], references: [id], onDelete: Cascade)
resume ResumesResume @relation(fields: [resumeId], references: [id], onDelete: Cascade)
@@unique([resumeId, resumesProfileId])
}
model ResumesComment {
id String @id @default(cuid())
resumeId String
userId String
description String @db.Text
section ResumesSection
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
resume ResumesResume @relation(fields: [resumeId], references: [id], onDelete: Cascade)
votes ResumesCommentVote[]
id String @id @default(cuid())
resumesProfileId String
resumeId String
description String @db.Text
section ResumesSection
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
resumesProfile ResumesProfile @relation(fields: [resumesProfileId], references: [id], onDelete: Cascade)
resume ResumesResume @relation(fields: [resumeId], references: [id], onDelete: Cascade)
votes ResumesCommentVote[]
}
enum ResumesSection {
@ -138,16 +146,20 @@ enum ResumesSection {
}
model ResumesCommentVote {
id String @id @default(cuid())
commentId String
userId String
value Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
comment ResumesComment @relation(fields: [commentId], references: [id], onDelete: Cascade)
id String @id @default(cuid())
resumesProfileId String
commentId String
value Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
resumesProfile ResumesProfile @relation(fields: [resumesProfileId], references: [id], onDelete: Cascade)
comment ResumesComment @relation(fields: [commentId], references: [id], onDelete: Cascade)
@@unique([commentId, resumesProfileId])
}
// End of Resumes project models.
// Start of Offers project models.
// Add Offers project models here, prefix all models with "Offer",
// use camelCase for field names, and try to name them consistently

@ -15,14 +15,23 @@ export const resumesResumeUserRouter = createProtectedRouter().mutation(
}),
async resolve({ ctx, input }) {
const userId = ctx.session?.user.id;
const resumeProfile = await ctx.prisma.resumesProfile.upsert({
create: {
userId,
},
update: {},
where: {
userId,
},
});
// TODO: Store file in file storage and retrieve URL
return await ctx.prisma.resumesResume.create({
data: {
...input,
resumesProfileId: resumeProfile.id,
url: '',
userId,
},
});
},

Loading…
Cancel
Save