mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-29 21:23:14 +08:00
[offers][chore] add user to replies and return error if profile not found
This commit is contained in:
@ -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;
|
@ -59,6 +59,7 @@ model User {
|
|||||||
questionsAnswerComments QuestionsAnswerComment[]
|
questionsAnswerComments QuestionsAnswerComment[]
|
||||||
questionsAnswerCommentVotes QuestionsAnswerCommentVote[]
|
questionsAnswerCommentVotes QuestionsAnswerCommentVote[]
|
||||||
OffersProfile OffersProfile[]
|
OffersProfile OffersProfile[]
|
||||||
|
offersDiscussion OffersReply[]
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Vote {
|
enum Vote {
|
||||||
@ -280,7 +281,6 @@ model OffersEducation {
|
|||||||
|
|
||||||
model OffersReply {
|
model OffersReply {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
creator String
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
message String
|
message String
|
||||||
|
|
||||||
@ -290,6 +290,9 @@ model OffersReply {
|
|||||||
|
|
||||||
profile OffersProfile @relation(fields: [profileId], references: [id], onDelete: Cascade)
|
profile OffersProfile @relation(fields: [profileId], references: [id], onDelete: Cascade)
|
||||||
profileId String
|
profileId String
|
||||||
|
|
||||||
|
user User? @relation(fields: [userId], references: [id])
|
||||||
|
userId String?
|
||||||
}
|
}
|
||||||
|
|
||||||
model OffersOffer {
|
model OffersOffer {
|
||||||
|
@ -14,10 +14,11 @@ function Test() {
|
|||||||
// ]);
|
// ]);
|
||||||
|
|
||||||
const [createdData, setCreatedData] = useState('');
|
const [createdData, setCreatedData] = useState('');
|
||||||
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
const createMutation = trpc.useMutation(['offers.profile.create'], {
|
const createMutation = trpc.useMutation(['offers.profile.create'], {
|
||||||
onError(error: any) {
|
onError(err: any) {
|
||||||
alert(error);
|
alert(err);
|
||||||
},
|
},
|
||||||
onSuccess(data) {
|
onSuccess(data) {
|
||||||
setCreatedData(JSON.stringify(data));
|
setCreatedData(JSON.stringify(data));
|
||||||
@ -38,7 +39,7 @@ function Test() {
|
|||||||
],
|
],
|
||||||
experiences: [
|
experiences: [
|
||||||
{
|
{
|
||||||
companyId: 'cl93patjt0004txew88wkcqpu',
|
companyId: 'cl95u79f000007im531ysjg79',
|
||||||
durationInMonths: 24,
|
durationInMonths: 24,
|
||||||
jobType: 'FULLTIME',
|
jobType: 'FULLTIME',
|
||||||
level: 'Junior',
|
level: 'Junior',
|
||||||
@ -66,7 +67,7 @@ function Test() {
|
|||||||
offers: [
|
offers: [
|
||||||
{
|
{
|
||||||
// Comments: '',
|
// Comments: '',
|
||||||
companyId: 'cl93patjt0004txew88wkcqpu',
|
companyId: 'cl95u79f000007im531ysjg79',
|
||||||
job: {
|
job: {
|
||||||
base: {
|
base: {
|
||||||
currency: 'SGD',
|
currency: 'SGD',
|
||||||
@ -95,7 +96,7 @@ function Test() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
comments: undefined,
|
comments: undefined,
|
||||||
companyId: 'cl93patjt0004txew88wkcqpu',
|
companyId: 'cl95u79f000007im531ysjg79',
|
||||||
job: {
|
job: {
|
||||||
base: {
|
base: {
|
||||||
currency: 'SGD',
|
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([
|
const data = trpc.useQuery([
|
||||||
`offers.profile.listOne`,
|
`offers.profile.listOne`,
|
||||||
{
|
{
|
||||||
profileId,
|
profileId,
|
||||||
token: 'e5e1951c9c301ab59bf4cad641e2e7b56c3db58aa852cee755b6ff8dd316cda6',
|
token: 'dccc05133962013ba8b4ee396e51baee1b53a66051732b48fd015129ae1d593e',
|
||||||
},
|
},
|
||||||
]);
|
], {
|
||||||
|
onError(err) {
|
||||||
|
setError(err.shape?.message || "")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const deleteMutation = trpc.useMutation(['offers.profile.delete']);
|
const deleteMutation = trpc.useMutation(['offers.profile.delete']);
|
||||||
|
|
||||||
const handleDelete = (id: string) => {
|
const handleDelete = (id: string) => {
|
||||||
deleteMutation.mutate({
|
deleteMutation.mutate({
|
||||||
profileId: id,
|
profileId: id,
|
||||||
token: 'e5e1951c9c301ab59bf4cad641e2e7b56c3db58aa852cee755b6ff8dd316cda6',
|
token: 'dccc05133962013ba8b4ee396e51baee1b53a66051732b48fd015129ae1d593e',
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
// <ul>
|
|
||||||
// {createdData.map((x) => {
|
|
||||||
// return <li key={x.id}>{JSON.stringify(x)}</li>;
|
|
||||||
// })}
|
|
||||||
// </ul>
|
|
||||||
<>
|
<>
|
||||||
<div>{createdData}</div>
|
<div>{createdData}</div>
|
||||||
<button type="button" onClick={handleClick}>
|
<button type="button" onClick={handleClick}>
|
||||||
@ -164,8 +164,7 @@ function Test() {
|
|||||||
DELETE THIS PROFILE
|
DELETE THIS PROFILE
|
||||||
</button>
|
</button>
|
||||||
<div>{JSON.stringify(data.data)}</div>
|
<div>{JSON.stringify(data.data)}</div>
|
||||||
|
<div>{JSON.stringify(error)}</div>
|
||||||
{/* <button type="button" onClick}>Get One</button> */}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ function Test() {
|
|||||||
const data = trpc.useQuery([
|
const data = trpc.useQuery([
|
||||||
'offers.list',
|
'offers.list',
|
||||||
{
|
{
|
||||||
companyId: 'cl93patjt0004txew88wkcqpu',
|
companyId: 'cl95u79f000007im531ysjg79',
|
||||||
limit: 20,
|
limit: 20,
|
||||||
location: 'Singapore, Singapore',
|
location: 'Singapore, Singapore',
|
||||||
offset: 0,
|
offset: 0,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import crypto, { randomUUID } from 'crypto';
|
import crypto, { randomUUID } from 'crypto';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { Prisma } from '@prisma/client';
|
import { Prisma } from '@prisma/client';
|
||||||
|
import * as trpc from '@trpc/server';
|
||||||
|
|
||||||
import { createRouter } from '../context';
|
import { createRouter } from '../context';
|
||||||
|
|
||||||
@ -128,9 +129,14 @@ export const offersProfileRouter = createRouter()
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return result
|
if (result) {
|
||||||
? exclude(computeIsEditable(result, input.token), 'editToken')
|
return exclude(computeIsEditable(result, input.token), 'editToken')
|
||||||
: result;
|
}
|
||||||
|
|
||||||
|
throw new trpc.TRPCError({
|
||||||
|
code: 'NOT_FOUND',
|
||||||
|
message: 'Profile does not exist',
|
||||||
|
});
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.mutation('create', {
|
.mutation('create', {
|
||||||
@ -421,3 +427,6 @@ export const offersProfileRouter = createRouter()
|
|||||||
// TODO: Throw 401
|
// TODO: Throw 401
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
// .mutation('update', {
|
||||||
|
|
||||||
|
// });
|
||||||
|
Reference in New Issue
Block a user