diff --git a/components/ProfileData/ProfileData.ts b/components/ProfileData/ProfileData.ts
index c81e3376..d48b3814 100644
--- a/components/ProfileData/ProfileData.ts
+++ b/components/ProfileData/ProfileData.ts
@@ -111,16 +111,16 @@ class ProfileData {
if (response.ok) {
const data = await response.json();
this.#profileData.name = data.name;
- this.#profileData.username = data.Username;
- this.#profileData.email = data.Email;
- this.#profileData.isHost = data.IsHost;
- this.#profileData.avatar = data.Avatar;
- this.#profileData.birthdate = data.Birthdate.slice(0, 10);
+ this.#profileData.username = data.username;
+ this.#profileData.email = data.email;
+ this.#profileData.isHost = data.isHost;
+ this.#profileData.avatar = data.avatar;
+ this.#profileData.birthdate = data.birthDate.slice(0, 10);
if (this.#profileData.birthdate != '0001-01-01')
this.#showBirthdate = true;
- this.#profileData.address = data.Address;
- this.#profileData.sex = this.#calculateSex(data.Sex);
- this.#rememberSexValue(data.Sex);
+ this.#profileData.address = data.address;
+ this.#profileData.sex = this.#calculateSex(data.sex);
+ this.#rememberSexValue(data.sex);
} else if (response.status !== 401) {
console.error('Wrong response from server', response);
}
diff --git a/components/ProfileInfo/ProfileInfo.hbs b/components/ProfileInfo/ProfileInfo.hbs
index 1099a41a..800979bf 100644
--- a/components/ProfileInfo/ProfileInfo.hbs
+++ b/components/ProfileInfo/ProfileInfo.hbs
@@ -1,10 +1,10 @@
-
+
-
{{name}}
-
{{city}}
+
{{data.name}}
+
{{data.city}}
@@ -13,29 +13,29 @@
- {{score}}
+ {{data.score}}
Пол:
-
{{sex}}
+
{{data.sex}}
Возраст:
-
{{age}}
+
{{#if isCorrectAge}} {{age}} {{else}}Не указано{{/if}}
Хост:
-
{{#if isHost}}Да{{else}}Нет{{/if}}
+
{{#if data.isHost}}Да{{else}}Нет{{/if}}
Адрес:
-
{{address}}
+
{{data.address}}
Серферы:
-
{{guestCount}}
+
{{data.guestCount}}
diff --git a/components/ProfileInfo/ProfileInfo.ts b/components/ProfileInfo/ProfileInfo.ts
index 901cce57..5019e69f 100644
--- a/components/ProfileInfo/ProfileInfo.ts
+++ b/components/ProfileInfo/ProfileInfo.ts
@@ -1,10 +1,12 @@
'use strict';
class ProfileInfo {
- #data;
+ #data: object;
+ #showAge: boolean;
- constructor(data: object){
+ constructor(data: object, showAge: boolean){
this.#data = data;
+ this.#showAge = showAge;
}
/**
@@ -13,7 +15,7 @@ class ProfileInfo {
*/
render(parent: HTMLElement){
const template = Handlebars.templates['ProfileInfo.hbs'];
- parent.insertAdjacentHTML('afterbegin', template(this.#data));
+ parent.insertAdjacentHTML('afterbegin', template({data: this.#data, isCorrectAge: this.#showAge}));
}
}
diff --git a/components/ProfilePage/ProfilePage.ts b/components/ProfilePage/ProfilePage.ts
index 4bee91de..107b3a38 100644
--- a/components/ProfilePage/ProfilePage.ts
+++ b/components/ProfilePage/ProfilePage.ts
@@ -17,6 +17,7 @@ class ProfilePage{
#isHost: boolean | undefined;
#age: number | undefined;
#avatar: string | undefined;
+ #showAge: boolean;
#renderProfileInfoCallback;
@@ -28,6 +29,7 @@ class ProfilePage{
await this.#renderProfileInfo(profileInfoContainer);
}
};
+ this.#showAge = true;
}
/**
@@ -40,18 +42,18 @@ class ProfilePage{
const data = await response.json();
this.#name = data.name;
- this.#username = data.Username;
- this.#email = data.Email;
- this.#guestCount = data.GuestCount;
- this.#score = data.Score;
- this.#isHost = data.IsHost;
- this.#avatar = data.Avatar;
- this.#birthdate = data.Birthdate;
-
- this.#sex = this.#calculateSex(data.Sex);
- this.#age = this.#calculateAge(data.Birthdate);
-
- const splitedAddress = this.#splitAddress(data.Address);
+ this.#username = data.username;
+ this.#email = data.email;
+ this.#guestCount = data.guestCount;
+ this.#score = data.score;
+ this.#isHost = data.isHost;
+ this.#avatar = data.avatar;
+ this.#birthdate = data.birthDate;
+
+ this.#sex = this.#calculateSex(data.sex);
+ this.#age = this.#calculateAge(data.birthDate);
+
+ const splitedAddress = this.#splitAddress(data.address);
this.#city = splitedAddress.city;
this.#address = splitedAddress.address;
} else if (response.status !== 401) {
@@ -65,6 +67,10 @@ class ProfilePage{
* @returns {number}
*/
#calculateAge(birthdate: string): number {
+ if (birthdate.slice(0,10) === '0001-01-01') {
+ return -1;
+ }
+
const birthDate = new Date(birthdate);
const today = new Date();
@@ -119,6 +125,11 @@ class ProfilePage{
*/
async #renderProfileInfo(parent: HTMLElement) {
await this.#getProfileData();
+ if (this.#age == -1) {
+ this.#showAge = false;
+ } else {
+ this.#showAge = true;
+ }
const profileData = {
name: this.#name,
username: this.#username,
@@ -134,7 +145,7 @@ class ProfilePage{
avatar: this.#avatar,
};
- const profileInfo = new ProfileInfo(profileData);
+ const profileInfo = new ProfileInfo(profileData, this.#showAge);
profileInfo.render(parent);
}
@@ -154,6 +165,7 @@ class ProfilePage{
* @param {HTMLElement} parent
*/
async render(parent: HTMLElement) {
+ parent.replaceChildren();
const profileContent = document.createElement('div');
profileContent.id = 'profile-content';
diff --git a/modules/Ajax.ts b/modules/Ajax.ts
index 9663420a..2efedfe5 100644
--- a/modules/Ajax.ts
+++ b/modules/Ajax.ts
@@ -33,6 +33,14 @@ class Ajax {
return this.#makeRequest({ method: 'POST', url, body });
}
+ /**
+ * @public
+ * @param {PostParams} postParams
+ */
+ static put({ url, body }: PostParams) {
+ return this.#makeRequest({ method: 'PUT', url, body });
+ }
+
/**
* @public
* @param {string} url
diff --git a/modules/ApiClient.ts b/modules/ApiClient.ts
index 23a8102d..91b69fb8 100644
--- a/modules/ApiClient.ts
+++ b/modules/ApiClient.ts
@@ -2,6 +2,7 @@
import Ajax from './Ajax';
import { RegisterParams, AdsFilters, LoginParams, EditParams } from './Types';
+import { getCookie } from './Utils';
class APIClient {
BASE_URL = `http://${window.location.hostname}:8008/api`;
@@ -112,7 +113,8 @@ class APIClient {
}
async profile() {
- const url = this.BASE_URL + '/getUserById';
+ const uuid = getCookie('session_id');
+ const url = this.BASE_URL + `/users/${uuid}`;
return Ajax.get(url);
}
@@ -127,7 +129,8 @@ class APIClient {
password,
avatar,
}: EditParams) {
- const url = this.BASE_URL + '/putUser';
+ const uuid = getCookie('session_id');
+ const url = this.BASE_URL + `/users/${uuid}`;
const formData = new FormData();
const metadata = {