account.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. 'use server';
  2. import { ChangeEmailRequest, ChangeNameRequest, ChangeApproveRequest, ChangeSummaryRequest, ChangeIntroRequest, ChangePasswordRequest } from '@/dtos/request/account';
  3. import { MemberResponse } from '@/dtos/response/account/member';
  4. import { ResultDto } from '@/dtos/response/common';
  5. import { fetchJson } from '@/lib/utils/server';
  6. // 회원정보 조회
  7. export async function fetchMemberInfo(): Promise<ResultDto<MemberResponse>> {
  8. return await fetchJson<MemberResponse>('/api/auth/profile', {
  9. method: 'GET'
  10. });
  11. }
  12. // 이메일 변경 인증 메일 발송
  13. export async function fetchChangeEmail(params: ChangeEmailRequest) {
  14. return await fetchJson('/api/mypage/email', {
  15. method: 'POST',
  16. headers: {
  17. 'Accept': 'application/json',
  18. 'Content-Type': 'application/json'
  19. },
  20. body: JSON.stringify(params)
  21. });
  22. }
  23. // 이메일 변경 인증 확인
  24. export async function fetchValidEmail(token: string) {
  25. return await fetchJson(`/api/mypage/email/verify?token=${token}`, {
  26. method: 'GET',
  27. headers: {
  28. 'Accept': 'application/json'
  29. }
  30. });
  31. }
  32. // 별명 변경
  33. export async function fetchChangeName(params: ChangeNameRequest) {
  34. return await fetchJson('/api/mypage/name', {
  35. method: 'POST',
  36. headers: {
  37. 'Accept': 'application/json',
  38. 'Content-Type': 'application/json'
  39. },
  40. body: JSON.stringify(params)
  41. });
  42. }
  43. // 별명 삭제
  44. export async function fetchRemoveName() {
  45. return await fetchJson('/api/mypage/name', {
  46. method: 'DELETE',
  47. headers: {
  48. 'Accept': 'application/json',
  49. 'Content-Type': 'application/json'
  50. }
  51. });
  52. }
  53. // 수신 설정
  54. export async function fetchChangeApprove(params: ChangeApproveRequest) {
  55. return await fetchJson('/api/mypage/receive-settings', {
  56. method: 'POST',
  57. headers: {
  58. 'Accept': 'application/json',
  59. 'Content-Type': 'application/json'
  60. },
  61. body: JSON.stringify(params)
  62. });
  63. }
  64. // 한마디 변경
  65. export async function fetchChangeSummary(params: ChangeSummaryRequest) {
  66. return await fetchJson('/api/mypage/summary', {
  67. method: 'POST',
  68. headers: {
  69. 'Accept': 'application/json',
  70. 'Content-Type': 'application/json'
  71. },
  72. body: JSON.stringify(params)
  73. });
  74. }
  75. // 한마디 삭제
  76. export async function fetchRemoveSummary() {
  77. return await fetchJson('/api/mypage/summary', {
  78. method: 'DELETE',
  79. headers: {
  80. 'Accept': 'application/json',
  81. 'Content-Type': 'application/json'
  82. }
  83. });
  84. }
  85. // 자기소개 변경
  86. export async function fetchChangeIntro(params: ChangeIntroRequest) {
  87. return await fetchJson('/api/mypage/intro', {
  88. method: 'POST',
  89. headers: {
  90. 'Accept': 'application/json',
  91. 'Content-Type': 'application/json'
  92. },
  93. body: JSON.stringify(params)
  94. });
  95. }
  96. // 자기소개 삭제
  97. export async function fetchRemoveIntro() {
  98. return await fetchJson('/api/mypage/intro', {
  99. method: 'DELETE',
  100. headers: {
  101. 'Accept': 'application/json',
  102. 'Content-Type': 'application/json'
  103. }
  104. });
  105. }
  106. // 회원 사진 변경
  107. export async function fetchChangeThumb(f: File|null): Promise<ResultDto<{thumbUrl: string}>> {
  108. const formData = new FormData();
  109. formData.append('thumb', f || '');
  110. return await fetchJson<{thumbUrl: string}>('/api/mypage/thumb', {
  111. method: 'POST',
  112. headers: {
  113. 'Accept': 'application/json'
  114. },
  115. body: formData
  116. });
  117. }
  118. // 비밀번호 변경
  119. export async function fetchChangePassword(params: ChangePasswordRequest) {
  120. return await fetchJson('/api/mypage/password', {
  121. method: 'POST',
  122. headers: {
  123. 'Accept': 'application/json',
  124. 'Content-Type': 'application/json'
  125. },
  126. body: JSON.stringify(params)
  127. });
  128. }
  129. // 회원탈퇴
  130. export async function fetchWithdraw() {
  131. return await fetchJson('/api/mypage/withdraw', {
  132. method: 'POST',
  133. headers: {
  134. 'Accept': 'application/json',
  135. 'Content-Type': 'application/json'
  136. }
  137. });
  138. }
  139. // 로그인 기록
  140. export async function fetchLoginLog(page: number, type: string = 'today', pageSize: number = 20) {
  141. return await fetchJson(`/api/mypage/login-logs?page=${page}&type=${type}&pageSize=${pageSize}`, {
  142. method: 'GET',
  143. headers: {
  144. 'Accept': 'application/json'
  145. }
  146. });
  147. }