|
| 1 | +import client from './client'; |
| 2 | + |
| 3 | +const getReports = async ( |
| 4 | + setReports: React.Dispatch<React.SetStateAction<Report[]>>, |
| 5 | + queryString: string = '', |
| 6 | + callBack?: () => void, |
| 7 | +) => { |
| 8 | + try { |
| 9 | + const res = await client.get(`/api/reports${queryString}`); |
| 10 | + setReports(res.data.data); |
| 11 | + if (callBack) callBack(); |
| 12 | + console.log(res.data.data); |
| 13 | + } catch (error) { |
| 14 | + console.error(error); |
| 15 | + } |
| 16 | +}; |
| 17 | + |
| 18 | +const patchReport = async (reportId: number, reportRequest: ReportRequest) => { |
| 19 | + try { |
| 20 | + console.log(`/api/reports/${reportId}`, reportRequest); |
| 21 | + const res = await client.patch(`/api/reports/${reportId}`, reportRequest); |
| 22 | + console.log(res); |
| 23 | + } catch (error) { |
| 24 | + console.error(error); |
| 25 | + } |
| 26 | +}; |
| 27 | + |
| 28 | +// badwords |
| 29 | +const getBadWords = async (setBadWords: React.Dispatch<React.SetStateAction<BadWords[]>>) => { |
| 30 | + try { |
| 31 | + const res = await client.get('/api/bad-words'); |
| 32 | + setBadWords(res.data.data); |
| 33 | + console.log(res); |
| 34 | + } catch (error) { |
| 35 | + console.error(error); |
| 36 | + } |
| 37 | +}; |
| 38 | + |
| 39 | +const postBadWords = async (badWordsRequest: BadWords, callBack?: () => void) => { |
| 40 | + try { |
| 41 | + const res = await client.post('/api/bad-words', badWordsRequest); |
| 42 | + if (callBack) callBack(); |
| 43 | + console.log(res); |
| 44 | + } catch (error) { |
| 45 | + console.error(error); |
| 46 | + } |
| 47 | +}; |
| 48 | + |
| 49 | +// 내 상상대로 만든 필터링 단어 취소 버튼 |
| 50 | +const patchBadWords = async ( |
| 51 | + badWordId: number, |
| 52 | + badWordsRequest: BadWords, |
| 53 | + callBack?: () => void, |
| 54 | +) => { |
| 55 | + try { |
| 56 | + const res = await client.patch(`/api/bad-words/${badWordId}/status`, badWordsRequest); |
| 57 | + if (callBack) callBack(); |
| 58 | + console.log(res); |
| 59 | + } catch (error) { |
| 60 | + console.error(error); |
| 61 | + } |
| 62 | +}; |
| 63 | + |
| 64 | +export { getReports, patchReport, getBadWords, postBadWords, patchBadWords }; |
0 commit comments