[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 = () => {
createCommentMutation.mutate({
message: 'hello',
profileId: 'cl96stky5002ew32gx2kale2x',
// UserId: 'cl97dl51k001e7iygd5v5gt58'
message: 'wassup bro',
profileId: 'cl9efyn9p004ww3u42mjgl1vn',
replyingToId: 'cl9el4xj10001w3w21o3p2iny',
userId: 'cl9ehvpng0000w3ec2mpx0bdd'
});
};
const handleLink = () => {
addToUserProfileMutation.mutate({
profileId: 'cl96stky5002ew32gx2kale2x',
profileId: 'cl9efyn9p004ww3u42mjgl1vn',
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 handleDelete = (id: string) => {
@ -600,7 +602,7 @@ function Test() {
return (
<>
<div>{createdData}</div>
<div>{JSON.stringify(replies.data)}</div>
<div>{JSON.stringify(replies.data?.data)}</div>
<button type="button" onClick={handleClick}>
Click Me!
</button>

@ -36,8 +36,11 @@ export const offersCommentsRouter = createRouter()
},
});
result?.discussion
.filter((x) => x.replyingToId === null)
const discussions: OffersDiscussion = {
data: result?.discussion
.filter((x) => {
return x.replyingToId === null
})
.map((x) => {
if (x.user == null) {
x.user = {
@ -60,11 +63,27 @@ export const offersCommentsRouter = createRouter()
};
}
});
return x;
});
const discussions: OffersDiscussion = {
data: result ? result.discussion : []
const replyType: Reply = {
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

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

Loading…
Cancel
Save