Skip to content

Commit 823e88c

Browse files
committed
[PRAC/ret] Correct "server" logic file
Organiz automatic creation "db.json" file at first run/Render (reload). Worth noting: - attempts to configure the display of existing clients. core: B-3 / JS-BL
1 parent 73e0d84 commit 823e88c

File tree

1 file changed

+75
-1
lines changed
  • core-courses/3-js-basic-level/practicum-js-basic-level/sb-crm-server

1 file changed

+75
-1
lines changed

core-courses/3-js-basic-level/practicum-js-basic-level/sb-crm-server/index.js

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,81 @@ function deleteClient(itemId) {
168168
}
169169

170170
// создаём новый файл с базой данных, если он не существует
171-
if (!existsSync(DB_FILE)) writeFileSync(DB_FILE, "[]", { encoding: "utf8" });
171+
// ?? следует раскомментировать
172+
// if (!existsSync(DB_FILE)) writeFileSync(DB_FILE, "[]", { encoding: "utf8" });
173+
174+
// !! [FOR DEMO - Render] автоматическое создание db.json при первом запуске на Render
175+
if (!existsSync(DB_FILE)) {
176+
const defaultData = [
177+
{
178+
surname: "Скворцов",
179+
name: "Денис",
180+
patronymic: "Юрьевич",
181+
contacts: [
182+
{ type: "phone", value: "+7 (987) 333-55-77" },
183+
{ type: "extra-phone", value: "+9 (566) 678-22-11" },
184+
{ type: "email", value: "[email protected]" },
185+
{ type: "vk", value: "id345678" },
186+
{ type: "facebook", value: "dskvor88" },
187+
{ type: "twitter", value: "@skvor" },
188+
],
189+
id: "1738150048864",
190+
updatedAt: "2025-02-03T08:15:58.537Z",
191+
createdAt: "2025-01-29T11:27:28.864Z",
192+
},
193+
{
194+
surname: "Куприянов",
195+
name: "Арсений",
196+
patronymic: "Валерьевич",
197+
contacts: [
198+
{ type: "phone", value: "+9 (211) 543-01-00" },
199+
{ type: "email", value: "[email protected]" },
200+
],
201+
id: "1738156123828",
202+
updatedAt: "2025-01-29T13:08:43.828Z",
203+
createdAt: "2025-01-29T13:08:43.828Z",
204+
},
205+
{
206+
surname: "Константинопольская",
207+
name: "Людмила",
208+
patronymic: "Александровна",
209+
contacts: [
210+
{ type: "phone", value: "+5 (866) 449-13-12" },
211+
{ type: "email", value: "[email protected]" },
212+
{ type: "facebook", value: "kalexa91" },
213+
],
214+
id: "1738156235186",
215+
updatedAt: "2025-01-29T13:10:35.186Z",
216+
createdAt: "2025-01-29T13:10:35.186Z",
217+
},
218+
{
219+
surname: "Дмитриевский",
220+
name: "Олег",
221+
patronymic: "Алексеевич",
222+
contacts: [{ type: "phone", value: "+9 (888) 399-99-91" }],
223+
id: "1738156379829",
224+
updatedAt: "2025-02-04T06:57:27.611Z",
225+
createdAt: "2025-01-29T13:11:19.829Z",
226+
},
227+
{
228+
surname: "Александрова",
229+
name: "Татьяна",
230+
patronymic: "Павловна",
231+
contacts: [
232+
{ type: "phone", value: "+6 (344) 678-00-00" },
233+
{ type: "email", value: "[email protected]" },
234+
{ type: "vk", value: "id891267" },
235+
],
236+
id: "1738156451839",
237+
updatedAt: "2025-02-05T06:12:12.786Z",
238+
createdAt: "2025-01-29T13:12:51.839Z",
239+
},
240+
];
241+
242+
writeFileSync(DB_FILE, JSON.stringify(defaultData, null, 2), {
243+
encoding: "utf8",
244+
});
245+
}
172246

173247
// создаём HTTP сервер, переданная функция будет реагировать на все запросы к нему
174248
module.exports = createServer(async (req, res) => {

0 commit comments

Comments
 (0)