events-api.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. import { request } from '../../../utils';
  2. import { API } from '../../../types';
  3. import { ResponseType } from '../response-type';
  4. import { AxiosRequestConfig } from 'axios';
  5. export interface PostGetEventsListReturn extends ResponseType {
  6. data: SingleEvent[];
  7. }
  8. export type SingleEvent = {
  9. id: number;
  10. active: 0 | 1;
  11. full: 0 | 1;
  12. name: string;
  13. url: string;
  14. date: string;
  15. date_from: string;
  16. date_to: string;
  17. address1: string;
  18. location: string;
  19. capacity?: number;
  20. participants?: number;
  21. registrations_info: 1 | 2 | 3 | 4 | 5;
  22. type: 1 | 2 | 3;
  23. photo: 0 | 1;
  24. available?: number;
  25. joined: 0 | 1;
  26. visible?: 0 | 1;
  27. archived?: 0 | 1;
  28. time?: string;
  29. };
  30. export type Participants = {
  31. uid: number;
  32. name: string;
  33. avatar: string | null;
  34. flag: string | null;
  35. };
  36. export type EventSettings = {
  37. name: string;
  38. url: string;
  39. date: string;
  40. date_from: string;
  41. date_to: string;
  42. address1: string;
  43. location: string;
  44. capacity: number;
  45. type: 1 | 2 | 3;
  46. registrations_info: 1 | 2 | 3 | 4 | 5;
  47. address2: string;
  48. details: string;
  49. free: 0 | 1;
  50. host: string;
  51. host_profile: number | null;
  52. price: string;
  53. shop_url: string;
  54. chat_token: string | null;
  55. all_participants_visible: 0 | 1;
  56. participants_can_add_photos: 0 | 1 | null;
  57. participants_can_add_files: 0 | 1 | null;
  58. host_data: {
  59. first_name: string;
  60. last_name: string;
  61. avatar: string | null;
  62. nm: number | null;
  63. un: number | null;
  64. };
  65. };
  66. export type EventAttachments = {
  67. id: number;
  68. filename: string;
  69. filetype: string;
  70. description: string;
  71. data: 0 | 1;
  72. preview: 0 | 1;
  73. type: 1 | 2 | 3;
  74. };
  75. export type EventPhotos = {
  76. id: number;
  77. filetype: string;
  78. data: 0 | 1;
  79. preview: 0 | 1;
  80. uid: number;
  81. name: string;
  82. avatar: string | null;
  83. };
  84. export type EventData = SingleEvent & {
  85. event_chat: string | null;
  86. settings: EventSettings;
  87. participants_data: Participants[];
  88. joined: 0 | 1;
  89. attachments: EventAttachments[];
  90. files: EventAttachments[];
  91. photos: EventPhotos[];
  92. user_id: number | boolean;
  93. photo_available: 0 | 1;
  94. photo_main: 0 | 1;
  95. photos_left: number;
  96. };
  97. export interface PostGetEventReturn extends ResponseType {
  98. data: EventData;
  99. }
  100. export interface PostGetMorePhotosReturn extends ResponseType {
  101. photos: EventPhotos[];
  102. photos_left: number;
  103. }
  104. export interface PostUploadTempFileReturn extends ResponseType {
  105. filetype: string;
  106. name: string;
  107. temp_name: string;
  108. }
  109. export interface PostGetCanAddEventReturn extends ResponseType {
  110. can: boolean;
  111. }
  112. export interface PostGetPhotosForRegionReturn extends ResponseType {
  113. photos: number[];
  114. }
  115. export interface PostJoinEvent {
  116. token: string;
  117. id: number;
  118. }
  119. export interface PostUploadTemp {
  120. token: string;
  121. file: {
  122. type: string;
  123. uri: string;
  124. name: string;
  125. };
  126. }
  127. export interface PostUploadPhoto {
  128. token: string;
  129. event_id: number;
  130. file: {
  131. type: string;
  132. uri: string;
  133. name: string;
  134. };
  135. }
  136. export interface PostEventAddFile {
  137. token: string;
  138. type: 1 | 2 | 3;
  139. description: string;
  140. event_id: number;
  141. filetype: string;
  142. filename: string;
  143. temp_filename: string;
  144. }
  145. export interface PostDeleteFile {
  146. token: string;
  147. id: number;
  148. event_id: number;
  149. }
  150. export interface PostAddEvent {
  151. token: string;
  152. event: any;
  153. }
  154. export const eventsApi = {
  155. getEventsList: (token: string) =>
  156. request.postForm<PostGetEventsListReturn>(API.GET_EVENTS_LIST, { token }),
  157. getEvent: (token: string, url: string) =>
  158. request.postForm<PostGetEventReturn>(API.GET_EVENT, { token, url }),
  159. joinEvent: (data: PostJoinEvent) => request.postForm<ResponseType>(API.JOIN_EVENT, data),
  160. unjoinEvent: (data: PostJoinEvent) => request.postForm<ResponseType>(API.UNJOIN_EVENT, data),
  161. uploadTempFile: (data: PostUploadTemp, config?: AxiosRequestConfig) => {
  162. const formData = new FormData();
  163. formData.append('token', data.token);
  164. formData.append('file', {
  165. ...data.file
  166. } as unknown as Blob);
  167. return request.postForm<PostUploadTempFileReturn>(API.UPLOAD_TEMP_FILE, formData, {
  168. ...config
  169. });
  170. },
  171. eventAddFile: (data: PostEventAddFile) =>
  172. request.postForm<ResponseType>(API.EVENT_ADD_FILE, data),
  173. deleteFile: (data: PostDeleteFile) => request.postForm<ResponseType>(API.DELETE_FILE, data),
  174. uploadPhoto: (data: PostUploadPhoto, config?: AxiosRequestConfig) => {
  175. const formData = new FormData();
  176. formData.append('token', data.token);
  177. formData.append('event_id', JSON.stringify(data.event_id));
  178. formData.append('file', {
  179. ...data.file
  180. } as unknown as Blob);
  181. return request.postForm<PostUploadTempFileReturn>(API.UPLOAD_PHOTO_EVENT, formData, {
  182. ...config
  183. });
  184. },
  185. getMorePhotos: (token: string, event_id: number, last_id: number) =>
  186. request.postForm<PostGetMorePhotosReturn>(API.GET_MORE_PHOTOS, { token, event_id, last_id }),
  187. canAddEvent: (token: string) =>
  188. request.postForm<PostGetCanAddEventReturn>(API.CAN_ADD_EVENT, { token }),
  189. getPhotosForRegion: (region_id: number) =>
  190. request.postForm<PostGetPhotosForRegionReturn>(API.GET_PHOTOS_FOR_REGION, { region_id }),
  191. addEvent: (data: PostAddEvent) => request.postForm<ResponseType>(API.ADD_EVENT, data)
  192. };