diff --git a/apps/portal/prisma/migrations/20221012161857_add_user_to_replies/migration.sql b/apps/portal/prisma/migrations/20221012161857_add_user_to_replies/migration.sql new file mode 100644 index 00000000..bc51e8e1 --- /dev/null +++ b/apps/portal/prisma/migrations/20221012161857_add_user_to_replies/migration.sql @@ -0,0 +1,12 @@ +/* + Warnings: + + - You are about to drop the column `creator` on the `OffersReply` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE "OffersReply" DROP COLUMN "creator", +ADD COLUMN "userId" TEXT; + +-- AddForeignKey +ALTER TABLE "OffersReply" ADD CONSTRAINT "OffersReply_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/apps/portal/prisma/schema.prisma b/apps/portal/prisma/schema.prisma index 1fba7c6a..27a1d7c5 100644 --- a/apps/portal/prisma/schema.prisma +++ b/apps/portal/prisma/schema.prisma @@ -59,6 +59,7 @@ model User { questionsAnswerComments QuestionsAnswerComment[] questionsAnswerCommentVotes QuestionsAnswerCommentVote[] OffersProfile OffersProfile[] + offersDiscussion OffersReply[] } enum Vote { @@ -280,7 +281,6 @@ model OffersEducation { model OffersReply { id String @id @default(cuid()) - creator String createdAt DateTime @default(now()) message String @@ -290,6 +290,9 @@ model OffersReply { profile OffersProfile @relation(fields: [profileId], references: [id], onDelete: Cascade) profileId String + + user User? @relation(fields: [userId], references: [id]) + userId String? } model OffersOffer { diff --git a/apps/portal/src/pages/offers/test/createProfile.tsx b/apps/portal/src/pages/offers/test/createProfile.tsx index 07a20f7f..9c21d52c 100644 --- a/apps/portal/src/pages/offers/test/createProfile.tsx +++ b/apps/portal/src/pages/offers/test/createProfile.tsx @@ -14,10 +14,11 @@ function Test() { // ]); const [createdData, setCreatedData] = useState(''); + const [error, setError] = useState(""); const createMutation = trpc.useMutation(['offers.profile.create'], { - onError(error: any) { - alert(error); + onError(err: any) { + alert(err); }, onSuccess(data) { setCreatedData(JSON.stringify(data)); @@ -38,7 +39,7 @@ function Test() { ], experiences: [ { - companyId: 'cl93patjt0004txew88wkcqpu', + companyId: 'cl95u79f000007im531ysjg79', durationInMonths: 24, jobType: 'FULLTIME', level: 'Junior', @@ -66,7 +67,7 @@ function Test() { offers: [ { // Comments: '', - companyId: 'cl93patjt0004txew88wkcqpu', + companyId: 'cl95u79f000007im531ysjg79', job: { base: { currency: 'SGD', @@ -95,7 +96,7 @@ function Test() { }, { comments: undefined, - companyId: 'cl93patjt0004txew88wkcqpu', + companyId: 'cl95u79f000007im531ysjg79', job: { base: { currency: 'SGD', @@ -126,30 +127,29 @@ function Test() { }); }; - const profileId = 'cl93vnvs1007aw35m9ppn7dsy'; // Remember to change this filed after testing deleting + const profileId = 'cl95u9ju500eo7ipd54kurv8d'; // Remember to change this filed after testing deleting const data = trpc.useQuery([ `offers.profile.listOne`, { profileId, - token: 'e5e1951c9c301ab59bf4cad641e2e7b56c3db58aa852cee755b6ff8dd316cda6', + token: 'dccc05133962013ba8b4ee396e51baee1b53a66051732b48fd015129ae1d593e', }, - ]); + ], { + onError(err) { + setError(err.shape?.message || "") + } + }); const deleteMutation = trpc.useMutation(['offers.profile.delete']); const handleDelete = (id: string) => { deleteMutation.mutate({ profileId: id, - token: 'e5e1951c9c301ab59bf4cad641e2e7b56c3db58aa852cee755b6ff8dd316cda6', + token: 'dccc05133962013ba8b4ee396e51baee1b53a66051732b48fd015129ae1d593e', }); }; return ( - //