-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotificationsController.js
More file actions
41 lines (37 loc) · 1.17 KB
/
NotificationsController.js
File metadata and controls
41 lines (37 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class Notifications {
static async insertReward(rewardData) {
// console.log(rewardData);
const title = rewardData.title;
const amount = rewardData.amount;
const userId = rewardData.userId;
const campaignId = rewardData.campaignId;
await fetch(`http://localhost:3000/rewards`, {
method: "post",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title,
amount,
userId,
campaignId,
date: new Date(),
}),
});
}
static async fetchLatestRewards(date, sort = "desc", col = "date") {
const response = await fetch(
`http://localhost:3000/rewards?_sort=${col}&_order=${sort}&_expand=user&_expand=campaign&_limit=5&date_gte=${date}`
);
const data = await response.json();
return data;
}
static async fetchAllNotifications(userId) {
const API = `http://localhost:3000/rewards?_expand=campaign&_expand=user&_sort=date&_order=desc`;
console.log("API", API);
const response = await fetch(API);
const data = await response.json();
return data.filter((reward) => reward.campaign.userId == userId);
}
}
export default Notifications;