account.ts 3.8 KB

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