No Description

comment.ts 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import axios from "axios";
  2. import { converObj } from "@/helper";
  3. import { COMMENT_API } from "@/components/comment/config/constant";
  4. type CommonListResponse = {
  5. list: Array<any>;
  6. total: number;
  7. page: number;
  8. };
  9. interface CommonResponse {
  10. config: any;
  11. data: CommonListResponse;
  12. headers: any;
  13. request: any;
  14. status: number;
  15. statusText: string;
  16. }
  17. export const getComment = async ({
  18. type,
  19. businessId,
  20. isSpeak,
  21. page,
  22. limit,
  23. }: {
  24. type: string;
  25. businessId: string;
  26. isSpeak?: boolean;
  27. page: string;
  28. limit: string;
  29. }): Promise<any> => {
  30. const r: CommonResponse = await axios.get(
  31. `${COMMENT_API}/comments?${converObj({
  32. type,
  33. business_id: businessId,
  34. page,
  35. limit,
  36. })}`,
  37. { withCredentials: true }
  38. );
  39. return r.data;
  40. };
  41. export const createComment = async ({
  42. type,
  43. businessId,
  44. businessUserId,
  45. content,
  46. }: {
  47. type: string;
  48. businessId: string;
  49. businessUserId: string;
  50. content: string;
  51. }): Promise<any> => {
  52. const r = await axios.post(`${COMMENT_API}/comments`, {
  53. method: "post",
  54. withCredentials: true,
  55. data: {
  56. type,
  57. businessId,
  58. businessUserId,
  59. content,
  60. },
  61. });
  62. return r;
  63. };
  64. export const updateComment = async ({
  65. id,
  66. content,
  67. }: {
  68. id: string;
  69. content: string;
  70. }) => {
  71. const r = await axios.post(`${COMMENT_API}/comments/${id}`, {
  72. method: "post",
  73. withCredentials: true,
  74. data: {
  75. content,
  76. },
  77. });
  78. return r;
  79. };
  80. export const deleteComment = async ({ id }: { id: string }) => {
  81. const r = await axios.delete(`${COMMENT_API}/comments/${id}`);
  82. return r;
  83. };
  84. export const favorComment = async ({
  85. id,
  86. commentId,
  87. userId,
  88. }: {
  89. id: string;
  90. commentId: string;
  91. userId: number;
  92. }) => {
  93. const r = await axios(`${COMMENT_API}/comments/${id}/favor`, {
  94. method: "put",
  95. withCredentials: true,
  96. data: {
  97. commentID: commentId,
  98. userID: userId,
  99. },
  100. });
  101. return r;
  102. };
  103. export const unFavorComment = async ({
  104. id,
  105. commentId,
  106. userId,
  107. }: {
  108. id: string;
  109. commentId: string;
  110. userId: number;
  111. }) => {
  112. const r = await axios(`${COMMENT_API}/comments/${id}/favor`, {
  113. method: "delete",
  114. withCredentials: true,
  115. data: {
  116. commentID: commentId,
  117. userID: userId,
  118. },
  119. });
  120. return r;
  121. };
  122. // export const getFavorUserList = async () => {}