mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-29 21:23:14 +08:00
[resumes][feat] add resumeprofiles model (#316)
* [resumes][feat] add resumeprofiles model * [resumes][fix] fix typo * [resumes][chore] update migration file
This commit is contained in:
@ -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 {
|
model User {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
name String?
|
name String?
|
||||||
email String? @unique
|
email String? @unique
|
||||||
emailVerified DateTime?
|
emailVerified DateTime?
|
||||||
image String?
|
image String?
|
||||||
accounts Account[]
|
accounts Account[]
|
||||||
sessions Session[]
|
sessions Session[]
|
||||||
todos Todo[]
|
todos Todo[]
|
||||||
resumesResumes ResumesResume[]
|
resumesProfile ResumesProfile?
|
||||||
resumesStars ResumesStar[]
|
|
||||||
resumesComments ResumesComment[]
|
|
||||||
resumesCommentVotes ResumesCommentVote[]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
model VerificationToken {
|
model VerificationToken {
|
||||||
@ -88,45 +85,56 @@ model Company {
|
|||||||
// Add Resumes project models here, prefix all models with "Resumes",
|
// Add Resumes project models here, prefix all models with "Resumes",
|
||||||
// use camelCase for field names, and try to name them consistently
|
// use camelCase for field names, and try to name them consistently
|
||||||
// across all models in this file.
|
// 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 {
|
model ResumesResume {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
userId String
|
resumesProfileId String
|
||||||
title String @db.Text
|
title String @db.Text
|
||||||
// TODO: Update role, experience, location to use Enums
|
// TODO: Update role, experience, location to use Enums
|
||||||
role String @db.Text
|
role String @db.Text
|
||||||
experience String @db.Text
|
experience String @db.Text
|
||||||
location String @db.Text
|
location String @db.Text
|
||||||
url String
|
url String
|
||||||
additionalInfo String? @db.Text
|
additionalInfo String? @db.Text
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
resumesProfile ResumesProfile @relation(fields: [resumesProfileId], references: [id], onDelete: Cascade)
|
||||||
stars ResumesStar[]
|
stars ResumesStar[]
|
||||||
comments ResumesComment[]
|
comments ResumesComment[]
|
||||||
}
|
}
|
||||||
|
|
||||||
model ResumesStar {
|
model ResumesStar {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
resumeId String
|
resumesProfileId String
|
||||||
userId String
|
resumeId String
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
resumesProfile ResumesProfile @relation(fields: [resumesProfileId], references: [id], onDelete: Cascade)
|
||||||
resume ResumesResume @relation(fields: [resumeId], references: [id], onDelete: Cascade)
|
resume ResumesResume @relation(fields: [resumeId], references: [id], onDelete: Cascade)
|
||||||
|
|
||||||
|
@@unique([resumeId, resumesProfileId])
|
||||||
}
|
}
|
||||||
|
|
||||||
model ResumesComment {
|
model ResumesComment {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
resumeId String
|
resumesProfileId String
|
||||||
userId String
|
resumeId String
|
||||||
description String @db.Text
|
description String @db.Text
|
||||||
section ResumesSection
|
section ResumesSection
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
resumesProfile ResumesProfile @relation(fields: [resumesProfileId], references: [id], onDelete: Cascade)
|
||||||
resume ResumesResume @relation(fields: [resumeId], references: [id], onDelete: Cascade)
|
resume ResumesResume @relation(fields: [resumeId], references: [id], onDelete: Cascade)
|
||||||
votes ResumesCommentVote[]
|
votes ResumesCommentVote[]
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ResumesSection {
|
enum ResumesSection {
|
||||||
@ -138,16 +146,20 @@ enum ResumesSection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model ResumesCommentVote {
|
model ResumesCommentVote {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
commentId String
|
resumesProfileId String
|
||||||
userId String
|
commentId String
|
||||||
value Int
|
value Int
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
resumesProfile ResumesProfile @relation(fields: [resumesProfileId], references: [id], onDelete: Cascade)
|
||||||
comment ResumesComment @relation(fields: [commentId], 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.
|
// Start of Offers project models.
|
||||||
// Add Offers project models here, prefix all models with "Offer",
|
// Add Offers project models here, prefix all models with "Offer",
|
||||||
// use camelCase for field names, and try to name them consistently
|
// use camelCase for field names, and try to name them consistently
|
||||||
|
@ -15,14 +15,23 @@ export const resumesResumeUserRouter = createProtectedRouter().mutation(
|
|||||||
}),
|
}),
|
||||||
async resolve({ ctx, input }) {
|
async resolve({ ctx, input }) {
|
||||||
const userId = ctx.session?.user.id;
|
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
|
// TODO: Store file in file storage and retrieve URL
|
||||||
|
|
||||||
return await ctx.prisma.resumesResume.create({
|
return await ctx.prisma.resumesResume.create({
|
||||||
data: {
|
data: {
|
||||||
...input,
|
...input,
|
||||||
|
resumesProfileId: resumeProfile.id,
|
||||||
url: '',
|
url: '',
|
||||||
userId,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user