@myrjfa/state 1.0.8 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +18 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -17
- package/dist/lib/actions/actions.d.ts +170 -140
- package/dist/lib/actions/actions.d.ts.map +1 -1
- package/dist/lib/actions/actions.js +307 -307
- package/dist/lib/actions/chat.d.ts +80 -11
- package/dist/lib/actions/chat.d.ts.map +1 -1
- package/dist/lib/actions/chat.js +81 -20
- package/dist/lib/actions/fetcher.js +84 -84
- package/dist/lib/actions/property.d.ts +77 -0
- package/dist/lib/actions/property.d.ts.map +1 -0
- package/dist/lib/actions/property.js +133 -0
- package/dist/lib/actions/user.d.ts +23 -0
- package/dist/lib/actions/user.d.ts.map +1 -0
- package/dist/lib/actions/user.js +55 -0
- package/dist/lib/authSessionManager.js +34 -34
- package/dist/lib/context/ChatContext.d.ts +8 -1
- package/dist/lib/context/ChatContext.d.ts.map +1 -1
- package/dist/lib/context/ChatContext.js +338 -229
- package/dist/lib/models/chat.d.ts +32 -7
- package/dist/lib/models/chat.d.ts.map +1 -1
- package/dist/lib/models/notfications.d.ts +93 -25
- package/dist/lib/models/notfications.d.ts.map +1 -1
- package/dist/lib/models/notfications.js +55 -41
- package/dist/lib/models/portfolio.d.ts +42 -42
- package/dist/lib/models/property.d.ts +79 -0
- package/dist/lib/models/property.d.ts.map +1 -0
- package/dist/lib/models/property.js +134 -0
- package/dist/lib/models/tile.d.ts +28 -28
- package/dist/lib/userAtom.d.ts +198 -198
- package/dist/lib/userAtom.js +127 -127
- package/dist/lib/utils/fileCompression.d.ts +16 -0
- package/dist/lib/utils/fileCompression.d.ts.map +1 -0
- package/dist/lib/utils/fileCompression.js +56 -0
- package/dist/lib/utils/socialMediaUrl.d.ts +25 -0
- package/dist/lib/utils/socialMediaUrl.d.ts.map +1 -0
- package/dist/lib/utils/socialMediaUrl.js +97 -0
- package/package.json +1 -1
|
@@ -1,307 +1,307 @@
|
|
|
1
|
-
import { del, get, patch, post } from "./fetcher";
|
|
2
|
-
// host
|
|
3
|
-
// user/host
|
|
4
|
-
export async function getCurrentUser() {
|
|
5
|
-
try {
|
|
6
|
-
const endpoint = `/users/me`;
|
|
7
|
-
const data = await get(endpoint);
|
|
8
|
-
// console.log(data.message);
|
|
9
|
-
return data?.data;
|
|
10
|
-
}
|
|
11
|
-
catch (error) {
|
|
12
|
-
console.error('Failed to fetch user details: ', error);
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export async function userDetails(query, role) {
|
|
17
|
-
try {
|
|
18
|
-
if (role == "admin")
|
|
19
|
-
role = "user";
|
|
20
|
-
const endpoint = `/${role}s/other-${role}/${query}`;
|
|
21
|
-
const data = await get(endpoint);
|
|
22
|
-
return {
|
|
23
|
-
success: true,
|
|
24
|
-
user: data?.data,
|
|
25
|
-
message: data.message
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
console.error('Failed to fetch user details: ', error);
|
|
30
|
-
return { success: false, user: null, status: error.status, error: error.message };
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export async function subscribeToNewsLetter(email) {
|
|
34
|
-
try {
|
|
35
|
-
const endpoint = `/subscription/create`;
|
|
36
|
-
const data = await post(endpoint, { email: email });
|
|
37
|
-
return { success: true, message: data.message };
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
console.error('Error subscribing to newsletter: ', error);
|
|
41
|
-
return {
|
|
42
|
-
success: false,
|
|
43
|
-
error: error.message,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
export async function toggleUserWishlist(slug, tileType) {
|
|
48
|
-
try {
|
|
49
|
-
const endpoint = `/users/fav/${tileType}/toggle`;
|
|
50
|
-
const data = await post(endpoint, { id: slug });
|
|
51
|
-
return { success: true, message: data.message, wishlist: data.data };
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
console.error(`Failed to add ${tileType} to wishlist: `, error);
|
|
55
|
-
return {
|
|
56
|
-
success: false,
|
|
57
|
-
error: error.message,
|
|
58
|
-
wishlist: []
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
// subscribe
|
|
63
|
-
export async function subscribeToCareersPage(email) {
|
|
64
|
-
try {
|
|
65
|
-
const endpoint = `/subscription/create-job`;
|
|
66
|
-
const data = await post(endpoint, { email: email });
|
|
67
|
-
return { success: true, message: data.message };
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
console.error('Error subscribing to newsletter: ', error);
|
|
71
|
-
return {
|
|
72
|
-
success: false,
|
|
73
|
-
error: error.message,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
export async function contactUs(email, name, subject, message) {
|
|
78
|
-
try {
|
|
79
|
-
const endpoint = `/contactUs`;
|
|
80
|
-
const data = await post(endpoint, { email: email, name: name, subject: subject, message: message });
|
|
81
|
-
return { success: true, message: data.message };
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
console.error('Error contacting trippeaze: ', error);
|
|
85
|
-
return {
|
|
86
|
-
success: false,
|
|
87
|
-
error: error.message,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
// resume
|
|
92
|
-
export async function saveUserResume(file) {
|
|
93
|
-
try {
|
|
94
|
-
const endpoint = `/users/resume-update`;
|
|
95
|
-
const formData = new FormData();
|
|
96
|
-
formData.append('resume', file);
|
|
97
|
-
const data = await patch(endpoint, formData);
|
|
98
|
-
return {
|
|
99
|
-
success: true,
|
|
100
|
-
message: data.message,
|
|
101
|
-
user: data.data,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
return { success: false, error: error.message, user: null };
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
export async function getUserContact(username, role) {
|
|
109
|
-
try {
|
|
110
|
-
const endpoint = `/${role}s/getUserContact/${username}`;
|
|
111
|
-
const data = await get(endpoint);
|
|
112
|
-
return {
|
|
113
|
-
success: true,
|
|
114
|
-
message: data.message,
|
|
115
|
-
details: data.data,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
return {
|
|
120
|
-
success: false,
|
|
121
|
-
error: error.message,
|
|
122
|
-
details: null,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
// rating and reviews
|
|
127
|
-
export async function getReviewsById(id, type) {
|
|
128
|
-
try {
|
|
129
|
-
const endpoint = `/reviews/entity/${id}/${type}`;
|
|
130
|
-
const data = await get(endpoint);
|
|
131
|
-
// const data = { data: sampleReviews, message: "success" };
|
|
132
|
-
return {
|
|
133
|
-
success: true,
|
|
134
|
-
reviews: data.data,
|
|
135
|
-
message: data.message,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
catch (error) {
|
|
139
|
-
console.error('Failed to get reviews: ', error);
|
|
140
|
-
return {
|
|
141
|
-
success: true,
|
|
142
|
-
reviews: [],
|
|
143
|
-
error: error.message,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
export async function getRatingById(id, type) {
|
|
148
|
-
try {
|
|
149
|
-
const endpoint = `/reviews/entity/${id}`;
|
|
150
|
-
const data = await get(endpoint);
|
|
151
|
-
// const data = {
|
|
152
|
-
// data:
|
|
153
|
-
// [{
|
|
154
|
-
// slug: id[0] ?? "",
|
|
155
|
-
// rating: truncateDecimal(sampleReviews.reduce((acc, review) => acc + review.rating, 0) / sampleReviews.length, 1),
|
|
156
|
-
// ratingCount: sampleReviews.length,
|
|
157
|
-
// reviewCount: 100,
|
|
158
|
-
// }],
|
|
159
|
-
// message: "success"
|
|
160
|
-
// }
|
|
161
|
-
return {
|
|
162
|
-
success: true,
|
|
163
|
-
ratings: data.data,
|
|
164
|
-
message: data.message,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
catch (error) {
|
|
168
|
-
console.error('Failed to get reviews: ', error);
|
|
169
|
-
return {
|
|
170
|
-
success: true,
|
|
171
|
-
ratings: [],
|
|
172
|
-
error: error.message,
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
export async function addReview(id, type, formData) {
|
|
177
|
-
try {
|
|
178
|
-
const endpoint = `/reviews/`;
|
|
179
|
-
const data = await post(endpoint, { reviewee: id, revieweeType: type, rating: formData.rating, comment: formData.comment });
|
|
180
|
-
return {
|
|
181
|
-
success: true,
|
|
182
|
-
review: data.data,
|
|
183
|
-
message: data.message,
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
catch (error) {
|
|
187
|
-
console.error('Failed to get reviews: ', error);
|
|
188
|
-
return {
|
|
189
|
-
success: false,
|
|
190
|
-
review: null,
|
|
191
|
-
error: error.message,
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
export async function editReview(id, formData) {
|
|
196
|
-
try {
|
|
197
|
-
const endpoint = `/reviews/${id}`;
|
|
198
|
-
const data = await patch(endpoint, { rating: formData.rating, comment: formData.comment });
|
|
199
|
-
return {
|
|
200
|
-
success: true,
|
|
201
|
-
review: data.data,
|
|
202
|
-
message: data.message,
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
catch (error) {
|
|
206
|
-
console.error('Failed to get reviews: ', error);
|
|
207
|
-
return {
|
|
208
|
-
success: false,
|
|
209
|
-
review: null,
|
|
210
|
-
error: error.message,
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
export async function deleteReview(id) {
|
|
215
|
-
try {
|
|
216
|
-
const endpoint = `/reviews/${id}`;
|
|
217
|
-
const data = await del(endpoint);
|
|
218
|
-
return {
|
|
219
|
-
success: true,
|
|
220
|
-
message: data.message,
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
catch (error) {
|
|
224
|
-
console.error('Failed to get reviews: ', error);
|
|
225
|
-
return {
|
|
226
|
-
success: false,
|
|
227
|
-
error: error.message,
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
// notifications
|
|
232
|
-
export async function getAllNotifications() {
|
|
233
|
-
try {
|
|
234
|
-
const endpoint = `/notification?all=true`;
|
|
235
|
-
const data = await get(endpoint);
|
|
236
|
-
return {
|
|
237
|
-
success: true,
|
|
238
|
-
message: data.message,
|
|
239
|
-
notifs: data.data.notifications,
|
|
240
|
-
unreadCount: data.data.unreadCount,
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
catch (error) {
|
|
244
|
-
console.error('Failed to fetch notifications: ', error);
|
|
245
|
-
return {
|
|
246
|
-
success: false,
|
|
247
|
-
error: error.message,
|
|
248
|
-
notifs: [],
|
|
249
|
-
unreadCount: 0,
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
export async function getNotifications(limit) {
|
|
254
|
-
try {
|
|
255
|
-
const endpoint = `/notification?limit=${limit}`;
|
|
256
|
-
const data = await get(endpoint);
|
|
257
|
-
return {
|
|
258
|
-
success: true,
|
|
259
|
-
message: data.message,
|
|
260
|
-
notifs: data.data.notifications,
|
|
261
|
-
unreadCount: data.data.unreadCount,
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
catch (error) {
|
|
265
|
-
console.error('Failed to fetch notifications: ', error);
|
|
266
|
-
return {
|
|
267
|
-
success: false,
|
|
268
|
-
error: error.message,
|
|
269
|
-
notifs: [],
|
|
270
|
-
unreadCount: 0,
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
export async function toggleNotification(id, read) {
|
|
275
|
-
try {
|
|
276
|
-
const endpoint = `/notfication/${id}`;
|
|
277
|
-
const data = await patch(endpoint, { isRead: read });
|
|
278
|
-
return {
|
|
279
|
-
success: true,
|
|
280
|
-
message: data.message,
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
catch (error) {
|
|
284
|
-
console.error('Failed to toggle notfication: ', error);
|
|
285
|
-
return {
|
|
286
|
-
success: false,
|
|
287
|
-
error: error.message,
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
export async function toggleAllNotification(read) {
|
|
292
|
-
try {
|
|
293
|
-
const endpoint = `/notfication/update/all`;
|
|
294
|
-
const data = await patch(endpoint, { isRead: read });
|
|
295
|
-
return {
|
|
296
|
-
success: true,
|
|
297
|
-
message: data.message,
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
catch (error) {
|
|
301
|
-
console.error('Failed to toggle all notfications: ', error);
|
|
302
|
-
return {
|
|
303
|
-
success: false,
|
|
304
|
-
error: error.message,
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
}
|
|
1
|
+
import { del, get, patch, post } from "./fetcher";
|
|
2
|
+
// host
|
|
3
|
+
// user/host
|
|
4
|
+
export async function getCurrentUser() {
|
|
5
|
+
try {
|
|
6
|
+
const endpoint = `/users/me`;
|
|
7
|
+
const data = await get(endpoint);
|
|
8
|
+
// console.log(data.message);
|
|
9
|
+
return data?.data;
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
console.error('Failed to fetch user details: ', error);
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export async function userDetails(query, role) {
|
|
17
|
+
try {
|
|
18
|
+
if (role == "admin")
|
|
19
|
+
role = "user";
|
|
20
|
+
const endpoint = `/${role}s/other-${role}/${query}`;
|
|
21
|
+
const data = await get(endpoint);
|
|
22
|
+
return {
|
|
23
|
+
success: true,
|
|
24
|
+
user: data?.data,
|
|
25
|
+
message: data.message
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error('Failed to fetch user details: ', error);
|
|
30
|
+
return { success: false, user: null, status: error.status, error: error.message };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export async function subscribeToNewsLetter(email) {
|
|
34
|
+
try {
|
|
35
|
+
const endpoint = `/subscription/create`;
|
|
36
|
+
const data = await post(endpoint, { email: email });
|
|
37
|
+
return { success: true, message: data.message };
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.error('Error subscribing to newsletter: ', error);
|
|
41
|
+
return {
|
|
42
|
+
success: false,
|
|
43
|
+
error: error.message,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export async function toggleUserWishlist(slug, tileType) {
|
|
48
|
+
try {
|
|
49
|
+
const endpoint = `/users/fav/${tileType}/toggle`;
|
|
50
|
+
const data = await post(endpoint, { id: slug });
|
|
51
|
+
return { success: true, message: data.message, wishlist: data.data };
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error(`Failed to add ${tileType} to wishlist: `, error);
|
|
55
|
+
return {
|
|
56
|
+
success: false,
|
|
57
|
+
error: error.message,
|
|
58
|
+
wishlist: []
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// subscribe
|
|
63
|
+
export async function subscribeToCareersPage(email) {
|
|
64
|
+
try {
|
|
65
|
+
const endpoint = `/subscription/create-job`;
|
|
66
|
+
const data = await post(endpoint, { email: email });
|
|
67
|
+
return { success: true, message: data.message };
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.error('Error subscribing to newsletter: ', error);
|
|
71
|
+
return {
|
|
72
|
+
success: false,
|
|
73
|
+
error: error.message,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export async function contactUs(email, name, subject, message) {
|
|
78
|
+
try {
|
|
79
|
+
const endpoint = `/contactUs`;
|
|
80
|
+
const data = await post(endpoint, { email: email, name: name, subject: subject, message: message });
|
|
81
|
+
return { success: true, message: data.message };
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
console.error('Error contacting trippeaze: ', error);
|
|
85
|
+
return {
|
|
86
|
+
success: false,
|
|
87
|
+
error: error.message,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// resume
|
|
92
|
+
export async function saveUserResume(file) {
|
|
93
|
+
try {
|
|
94
|
+
const endpoint = `/users/resume-update`;
|
|
95
|
+
const formData = new FormData();
|
|
96
|
+
formData.append('resume', file);
|
|
97
|
+
const data = await patch(endpoint, formData);
|
|
98
|
+
return {
|
|
99
|
+
success: true,
|
|
100
|
+
message: data.message,
|
|
101
|
+
user: data.data,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
return { success: false, error: error.message, user: null };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export async function getUserContact(username, role) {
|
|
109
|
+
try {
|
|
110
|
+
const endpoint = `/${role}s/getUserContact/${username}`;
|
|
111
|
+
const data = await get(endpoint);
|
|
112
|
+
return {
|
|
113
|
+
success: true,
|
|
114
|
+
message: data.message,
|
|
115
|
+
details: data.data,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
return {
|
|
120
|
+
success: false,
|
|
121
|
+
error: error.message,
|
|
122
|
+
details: null,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// rating and reviews
|
|
127
|
+
export async function getReviewsById(id, type) {
|
|
128
|
+
try {
|
|
129
|
+
const endpoint = `/reviews/entity/${id}/${type}`;
|
|
130
|
+
const data = await get(endpoint);
|
|
131
|
+
// const data = { data: sampleReviews, message: "success" };
|
|
132
|
+
return {
|
|
133
|
+
success: true,
|
|
134
|
+
reviews: data.data,
|
|
135
|
+
message: data.message,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
console.error('Failed to get reviews: ', error);
|
|
140
|
+
return {
|
|
141
|
+
success: true,
|
|
142
|
+
reviews: [],
|
|
143
|
+
error: error.message,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
export async function getRatingById(id, type) {
|
|
148
|
+
try {
|
|
149
|
+
const endpoint = `/reviews/entity/${id}`;
|
|
150
|
+
const data = await get(endpoint);
|
|
151
|
+
// const data = {
|
|
152
|
+
// data:
|
|
153
|
+
// [{
|
|
154
|
+
// slug: id[0] ?? "",
|
|
155
|
+
// rating: truncateDecimal(sampleReviews.reduce((acc, review) => acc + review.rating, 0) / sampleReviews.length, 1),
|
|
156
|
+
// ratingCount: sampleReviews.length,
|
|
157
|
+
// reviewCount: 100,
|
|
158
|
+
// }],
|
|
159
|
+
// message: "success"
|
|
160
|
+
// }
|
|
161
|
+
return {
|
|
162
|
+
success: true,
|
|
163
|
+
ratings: data.data,
|
|
164
|
+
message: data.message,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
console.error('Failed to get reviews: ', error);
|
|
169
|
+
return {
|
|
170
|
+
success: true,
|
|
171
|
+
ratings: [],
|
|
172
|
+
error: error.message,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
export async function addReview(id, type, formData) {
|
|
177
|
+
try {
|
|
178
|
+
const endpoint = `/reviews/`;
|
|
179
|
+
const data = await post(endpoint, { reviewee: id, revieweeType: type, rating: formData.rating, comment: formData.comment });
|
|
180
|
+
return {
|
|
181
|
+
success: true,
|
|
182
|
+
review: data.data,
|
|
183
|
+
message: data.message,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
console.error('Failed to get reviews: ', error);
|
|
188
|
+
return {
|
|
189
|
+
success: false,
|
|
190
|
+
review: null,
|
|
191
|
+
error: error.message,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
export async function editReview(id, formData) {
|
|
196
|
+
try {
|
|
197
|
+
const endpoint = `/reviews/${id}`;
|
|
198
|
+
const data = await patch(endpoint, { rating: formData.rating, comment: formData.comment });
|
|
199
|
+
return {
|
|
200
|
+
success: true,
|
|
201
|
+
review: data.data,
|
|
202
|
+
message: data.message,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
console.error('Failed to get reviews: ', error);
|
|
207
|
+
return {
|
|
208
|
+
success: false,
|
|
209
|
+
review: null,
|
|
210
|
+
error: error.message,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
export async function deleteReview(id) {
|
|
215
|
+
try {
|
|
216
|
+
const endpoint = `/reviews/${id}`;
|
|
217
|
+
const data = await del(endpoint);
|
|
218
|
+
return {
|
|
219
|
+
success: true,
|
|
220
|
+
message: data.message,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
console.error('Failed to get reviews: ', error);
|
|
225
|
+
return {
|
|
226
|
+
success: false,
|
|
227
|
+
error: error.message,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
// notifications
|
|
232
|
+
export async function getAllNotifications() {
|
|
233
|
+
try {
|
|
234
|
+
const endpoint = `/notification?all=true`;
|
|
235
|
+
const data = await get(endpoint);
|
|
236
|
+
return {
|
|
237
|
+
success: true,
|
|
238
|
+
message: data.message,
|
|
239
|
+
notifs: data.data.notifications,
|
|
240
|
+
unreadCount: data.data.unreadCount,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
console.error('Failed to fetch notifications: ', error);
|
|
245
|
+
return {
|
|
246
|
+
success: false,
|
|
247
|
+
error: error.message,
|
|
248
|
+
notifs: [],
|
|
249
|
+
unreadCount: 0,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
export async function getNotifications(limit) {
|
|
254
|
+
try {
|
|
255
|
+
const endpoint = `/notification?limit=${limit}`;
|
|
256
|
+
const data = await get(endpoint);
|
|
257
|
+
return {
|
|
258
|
+
success: true,
|
|
259
|
+
message: data.message,
|
|
260
|
+
notifs: data.data.notifications,
|
|
261
|
+
unreadCount: data.data.unreadCount,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
console.error('Failed to fetch notifications: ', error);
|
|
266
|
+
return {
|
|
267
|
+
success: false,
|
|
268
|
+
error: error.message,
|
|
269
|
+
notifs: [],
|
|
270
|
+
unreadCount: 0,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
export async function toggleNotification(id, read) {
|
|
275
|
+
try {
|
|
276
|
+
const endpoint = `/notfication/${id}`;
|
|
277
|
+
const data = await patch(endpoint, { isRead: read });
|
|
278
|
+
return {
|
|
279
|
+
success: true,
|
|
280
|
+
message: data.message,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
catch (error) {
|
|
284
|
+
console.error('Failed to toggle notfication: ', error);
|
|
285
|
+
return {
|
|
286
|
+
success: false,
|
|
287
|
+
error: error.message,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
export async function toggleAllNotification(read) {
|
|
292
|
+
try {
|
|
293
|
+
const endpoint = `/notfication/update/all`;
|
|
294
|
+
const data = await patch(endpoint, { isRead: read });
|
|
295
|
+
return {
|
|
296
|
+
success: true,
|
|
297
|
+
message: data.message,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
catch (error) {
|
|
301
|
+
console.error('Failed to toggle all notfications: ', error);
|
|
302
|
+
return {
|
|
303
|
+
success: false,
|
|
304
|
+
error: error.message,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
}
|