This repository was archived by the owner on Mar 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfakeApi.js
68 lines (61 loc) · 1.52 KB
/
fakeApi.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const DATA = {
participants: [{
id: '1',
name: 'Bolek',
friendsIds: ['2', '3'],
eventsIds: ['1']
}, {
id: '2',
name: 'Franek',
friendsIds: ['1'],
eventsIds: ['1']
}, {
id: '3',
name: 'Zenek',
friendsIds: [],
eventsIds: ['1', '2']
}],
events: [{
id: '1',
name: 'WarsawJS',
participantsIds: ['1', '2', '3']
}, {
id: '2',
name: 'ReactWarsaw',
participantsIds: ['2']
}, {
id: '3',
name: 'AngularWarsaw',
participantsIds: []
}]
};
const getEvent = (id) => DATA.events.find(participant => participant.id === id);
const getParticipant = (id) => DATA.participants.find(event => event.id === id);
const addEvent = ({ id, name }) => {
DATA.events.push({ id, name, participantsIds: [] });
return getEvent(id);
};
const addParticipant = ({ id, name }) => {
DATA.participants.push({ id, name, eventsIds: [], friendsIds: [] });
return getParticipant(id);
};
const addParticipantToEvent = ({ participantId, eventId }) => {
const participant = getParticipant(participantId);
participant.eventsIds.push(eventId);
getEvent(eventId).participantsIds.push(participantId);
return participant;
};
const addParticipantFriend = ({ participantId, friendId }) => {
const participant = getParticipant(participantId);
participant.friendsIds.push(friendId);
getParticipant(friendId).friendsIds.push(participantId);
return participant;
};
export {
addEvent,
addParticipant,
addParticipantToEvent,
addParticipantFriend,
getEvent,
getParticipant
}