mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-28 20:52:00 +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[]
|
||||
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 {
|
||||
|
@ -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 (
|
||||
// <ul>
|
||||
// {createdData.map((x) => {
|
||||
// return <li key={x.id}>{JSON.stringify(x)}</li>;
|
||||
// })}
|
||||
// </ul>
|
||||
<>
|
||||
<div>{createdData}</div>
|
||||
<button type="button" onClick={handleClick}>
|
||||
@ -164,8 +164,7 @@ function Test() {
|
||||
DELETE THIS PROFILE
|
||||
</button>
|
||||
<div>{JSON.stringify(data.data)}</div>
|
||||
|
||||
{/* <button type="button" onClick}>Get One</button> */}
|
||||
<div>{JSON.stringify(error)}</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ function Test() {
|
||||
const data = trpc.useQuery([
|
||||
'offers.list',
|
||||
{
|
||||
companyId: 'cl93patjt0004txew88wkcqpu',
|
||||
companyId: 'cl95u79f000007im531ysjg79',
|
||||
limit: 20,
|
||||
location: 'Singapore, Singapore',
|
||||
offset: 0,
|
||||
|
@ -1,6 +1,7 @@
|
||||
import crypto, { randomUUID } from 'crypto';
|
||||
import { z } from 'zod';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import * as trpc from '@trpc/server';
|
||||
|
||||
import { createRouter } from '../context';
|
||||
|
||||
@ -128,9 +129,14 @@ export const offersProfileRouter = createRouter()
|
||||
},
|
||||
});
|
||||
|
||||
return result
|
||||
? exclude(computeIsEditable(result, input.token), 'editToken')
|
||||
: result;
|
||||
if (result) {
|
||||
return exclude(computeIsEditable(result, input.token), 'editToken')
|
||||
}
|
||||
|
||||
throw new trpc.TRPCError({
|
||||
code: 'NOT_FOUND',
|
||||
message: 'Profile does not exist',
|
||||
});
|
||||
},
|
||||
})
|
||||
.mutation('create', {
|
||||
@ -421,3 +427,6 @@ export const offersProfileRouter = createRouter()
|
||||
// TODO: Throw 401
|
||||
},
|
||||
});
|
||||
// .mutation('update', {
|
||||
|
||||
// });
|
||||
|
Reference in New Issue
Block a user