[offers][chore] add types to get comments api

pull/390/head
Stuart Long Chay Boon 3 years ago
parent 52d13b8e28
commit ecad270d33

@ -74,17 +74,18 @@ function Test() {
const handleCreate = () => { const handleCreate = () => {
createCommentMutation.mutate({ createCommentMutation.mutate({
message: 'hello', message: 'wassup bro',
profileId: 'cl96stky5002ew32gx2kale2x', profileId: 'cl9efyn9p004ww3u42mjgl1vn',
// UserId: 'cl97dl51k001e7iygd5v5gt58' replyingToId: 'cl9el4xj10001w3w21o3p2iny',
userId: 'cl9ehvpng0000w3ec2mpx0bdd'
}); });
}; };
const handleLink = () => { const handleLink = () => {
addToUserProfileMutation.mutate({ addToUserProfileMutation.mutate({
profileId: 'cl96stky5002ew32gx2kale2x', profileId: 'cl9efyn9p004ww3u42mjgl1vn',
token: 'afca11e436d21bde24543718fa957c6c625335439dc504f24ee35eae7b5ef1ba', token: 'afca11e436d21bde24543718fa957c6c625335439dc504f24ee35eae7b5ef1ba',
userId: 'cl97dl51k001e7iygd5v5gt58', userId: 'cl9ehvpng0000w3ec2mpx0bdd',
}); });
}; };
@ -216,6 +217,7 @@ function Test() {
}, },
); );
// Console.log(replies.data?.data)
const deleteMutation = trpc.useMutation(['offers.profile.delete']); const deleteMutation = trpc.useMutation(['offers.profile.delete']);
const handleDelete = (id: string) => { const handleDelete = (id: string) => {
@ -600,7 +602,7 @@ function Test() {
return ( return (
<> <>
<div>{createdData}</div> <div>{createdData}</div>
<div>{JSON.stringify(replies.data)}</div> <div>{JSON.stringify(replies.data?.data)}</div>
<button type="button" onClick={handleClick}> <button type="button" onClick={handleClick}>
Click Me! Click Me!
</button> </button>

@ -36,8 +36,11 @@ export const offersCommentsRouter = createRouter()
}, },
}); });
result?.discussion const discussions: OffersDiscussion = {
.filter((x) => x.replyingToId === null) data: result?.discussion
.filter((x) => {
return x.replyingToId === null
})
.map((x) => { .map((x) => {
if (x.user == null) { if (x.user == null) {
x.user = { x.user = {
@ -60,11 +63,27 @@ export const offersCommentsRouter = createRouter()
}; };
} }
}); });
return x;
});
const discussions: OffersDiscussion = { const replyType: Reply = {
data: result ? result.discussion : [] createdAt: x.createdAt,
id: x.id,
message: x.message,
replies: x.replies.map((reply) => {
return {
createdAt: reply.createdAt,
id: reply.id,
message: reply.message,
replies: [],
replyingToId: reply.replyingToId,
user: reply.user
}
}),
replyingToId: x.replyingToId,
user: x.user
}
return replyType
}) ?? []
} }
return discussions return discussions

@ -138,7 +138,7 @@ export type CreateOfferProfileResponse = {
}; };
export type OffersDiscussion = { export type OffersDiscussion = {
data: Array<OffersReply>; data: Array<OReply>;
}; };
export type OffersAnalysis = { export type OffersAnalysis = {

Loading…
Cancel
Save