-
Notifications
You must be signed in to change notification settings - Fork 2
/
cover.js
202 lines (174 loc) · 5.54 KB
/
cover.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// getState is used to get the value of a state path
// setState is used to set the value of a state path
import { getState, setState } from "statezero";
export const newCover = title => {
const url = "/covers/new";
let userCover = JSON.stringify({
owner: getState("userID"),
title: title,
data: ""
})
// Create our request constructor with all the parameters we need
const request = new Request(url, {
method: "post",
body: userCover,
headers: {
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json"
}
});
// Send the request with fetch()
fetch(request)
.then(res => {
if (res.status === 200) {
setState("coverSuccess", true);
setTimeout(function() {
setState("coverSuccess", false);
}, 3250);
getUserCovers();
setState("cover", userCover);
return res.json();
}
})
.catch(error => {
console.log(error);
});
};
export const getUserCovers = () => {
// the URL for the request
const url = "/covers/" + getState("userID");
// Since this is a GET request, simply call fetch on the URL
fetch(url)
.then(res => {
if (res.status === 200) {
// return a promise that resolves with the JSON body
return res.json();
} else {
alert("Could not get anything");
}
})
.then(json => {
// the resolved promise with the JSON body
setState("userCovers", json);
})
.catch(error => {
console.log(error);
});
};
export const saveUserCover = async () => {
// Wait 0.5 seconds to make sure the state is updated
await new Promise(resolve => setTimeout(resolve, 500));
const cover = getState("cover");
// Oddly, it's _id for some, id for others
let url;
if (cover._id !== undefined) {
url = "/covers/" + cover._id;
} else {
url = "/covers/" + cover.id;
}
const request = new Request(url, {
method: "PATCH",
body: JSON.stringify({
data: cover.data
}),
headers: {
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json"
}
});
// Send the request with fetch()
fetch(request)
.then(res => {
if (res.status === 200) {
setState("saveSuccess", true);
setTimeout(function() {
setState("saveSuccess", false);
}, 3250);
return res.json();
} else {
console.log(res);
}
})
.catch(error => {
console.log(error);
});
};
export const deleteUserCover = async () => {
// Wait 0.5 seconds to make sure the state is updated
await new Promise(resolve => setTimeout(resolve, 500));
const cover = getState("cover");
// Oddly, it's _id for some, id for others
let url;
if (cover._id !== undefined) {
url = "/covers/" + cover._id;
} else {
url = "/covers/" + cover.id;
}
const request = new Request(url, {
method: "DELETE",
body: JSON.stringify({
data: cover.data
}),
headers: {
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json"
}
});
// Send the request with fetch()
fetch(request)
.then(res => {
if (res.status === 200) {
setState("deleteSuccess", true);
setTimeout(function() {
setState("deleteSuccess", false);
}, 3250);
getUserCovers();
return res.json();
} else {
console.log(res);
}
})
.catch(error => {
console.log(error);
});
};
export const defaultCover = userID => {
const url = "/covers/new";
let data = `Dear {_},
I'm excited to be applying to {_} for the position of {_}! I found your job posting over at {_}, and I believe that my skills and experience match well with the requirements outlined.
With over {_} years of experience working as a {_} in {_}, I am seeking a challenging role that enables me to tap my full potential.
I have a {proven track record of professionalism and efficiency to foster customer satisfaction/great problem resolution insight resulting in customer retention}
{*}
Please find my resume attached with this cover letter. I hope to have a personal meeting to discuss how I can make a difference through this new opportunity.
Thank you for your time. I look forward to meeting with you.
Best Regards,
{_}
{Bank Work|In addition to the above distinguishing factors, I have always focused on providing exceptional customer service; I have performed transactions in complete accordance to the policies and procedures of the bank, and I have put my best efforts forward to offer insight in streamlining operations and assist customer retention.}
{Personal|What I like most about my current job is that it gives me the opportunity to learn and be creative, and it looks like this position would do the same. I feel that I could be a valuable asset to your team, and I bring to the table all of the skills that you require in an editor.}`;
// Create our request constructor with all the parameters we need
const request = new Request(url, {
method: "post",
body: JSON.stringify({
owner: userID,
title: "Sample Cover",
data: data
}),
headers: {
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json"
}
});
// Send the request with fetch()
fetch(request)
.then(res => {
if (res.status === 200) {
setTimeout(function() {
getUserCovers();
}, 2000);
return res.json();
}
})
.catch(error => {
console.log(error);
});
};