-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend.js
More file actions
55 lines (45 loc) · 1.5 KB
/
send.js
File metadata and controls
55 lines (45 loc) · 1.5 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// 연락처 db.json이 있고, db로 임포트 했다는 가정하에
const db = [
{
name: '친구', relation: 'friend', tel: '친구', birth: '4.12',
},
{
name: '가족', relation: 'family', tel: '가족', birth: '4.12',
},
{
name: '기타', relation: 'etc', tel: '기타', birth: '1.10',
},
];
const sendMessage = messages => fetch('sendMessage.com/message', {
method: 'post',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(messages),
});
const getBirthMessage = (birth, year) => {
const [month, date] = birth.split('.');
const birthDate = new Date(year, month - 1, date);
const targetDate = new Date(year, 0, 10);
if (targetDate.getTime() === birthDate.getTime()) return ' 생일 축하 합니다!';
return '';
};
const relations = {
friend: (obj, year) => `${obj.name}아 잘지내지? 다음에 볼때까지 건강해.${getBirthMessage(obj.birth, year)}`,
family: (obj, year) => `사랑합니다. 항상 건강하세요.${getBirthMessage(obj.birth, year)}`,
etc: (obj, year) => `${obj.name}님, 올 한해는 하시는 일 모두 건승하시고, 건강하세요.${getBirthMessage(obj.birth, year)}`,
};
function solution() {
const today = new Date();
const year = new Date().getFullYear();
const target = new Date(year, 0, 10, 11);
if (today.getTime() !== target.getTime()) {
return;
}
const messages = db.map(obj => ({
phone: obj.tel,
msg: relations[obj.relation](obj, year),
}));
sendMessage(messages);
}
solution();