Skip to content

Commit

Permalink
get rid of isUserProfilePicPresent var
Browse files Browse the repository at this point in the history
  • Loading branch information
bl4drnnr committed Apr 16, 2024
1 parent 27cb109 commit 57eb374
Show file tree
Hide file tree
Showing 18 changed files with 26 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class MarketplaceUser {
description: DocsProperty.USER_HASH_DESC,
example: DocsProperty.USER_HASH_EXAMPLE
})
readonly userIdHash: string | null;
readonly userIdHash: string;

@ApiProperty({
type: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ interface UserInfoResponse {
homeAddress: string | null;
homePhone: string | null;
email: string;
isProfilePicPresent: boolean;
isCompanyMember: boolean;
companyName: string | null;
companyId: string | null;
Expand Down Expand Up @@ -47,13 +46,6 @@ export class GetUserInfoResponseDto {
})
readonly email: string;

@ApiProperty({
type: Boolean,
description: DocsProperty.IS_USER_PROFILE_PIC_DESC,
example: DocsProperty.IS_USER_PROFILE_PIC_EXAMPLE
})
readonly isProfilePicPresent: boolean;

@ApiProperty({
type: String,
description: DocsProperty.NAME_PRONUNS_DESC,
Expand Down Expand Up @@ -119,7 +111,6 @@ export class GetUserInfoResponseDto {
homeAddress,
homePhone,
email,
isProfilePicPresent,
isCompanyMember,
companyName,
companyId,
Expand All @@ -133,7 +124,6 @@ export class GetUserInfoResponseDto {
this.homeAddress = homeAddress;
this.homePhone = homePhone;
this.email = email;
this.isProfilePicPresent = isProfilePicPresent;
this.isCompanyMember = isCompanyMember;
this.companyName = companyName;
this.companyId = companyId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ export enum DocsProperty {
USER_ID_EXAMPLE = '4eea51f7-ebf1-4470-b54e-eb3b8c79bf2c',
USER_HASH_DESC = 'User MD5 hashed ID',
USER_HASH_EXAMPLE = '71956c9eea017cb85242a49f416fd859',
IS_USER_PROFILE_PIC_DESC = 'Is user profile picture present',
IS_USER_PROFILE_PIC_EXAMPLE = 'true',
IS_TWO_FA_SET_UP_DESC = 'Is 2FA set up',
IS_TWO_FA_SET_UP_EXAMPLE = 'true',
IS_EMAIL_CHANGED_DESC = 'Is email changed',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,6 @@ export class ProductsService {
algorithm: CryptoHashAlgorithm.MD5
});

// let isProfilePicPresent = true;
//
// const { accessKeyId, secretAccessKey, bucketName } =
// this.configService.awsSdkCredentials;
//
// const s3 = new S3({ accessKeyId, secretAccessKey });
//
// try {
// await s3
// .headObject({
// Bucket: bucketName,
// Key: `users-profile-pictures/${userIdHash}.png`
// })
// .promise();
// } catch (e) {
// isProfilePicPresent = false;
// }

let companyId: string;
let companyName: string;
const onBehalfOfCompany = foundProduct.onBehalfOfCompany;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import { CompanyUser } from '@models/company-user.model';
import { GetUserFavoritesProductsInterface } from '@interfaces/get-user-favorites-products.interface';
import { UpdateUserFavoritesInterface } from '@interfaces/update-user-favorites.interface';
import { GetMarketplaceUserByIdInterface } from '@interfaces/get-marketplace-user-by-id.interface';
import { ProductsService } from '@modules/products.service';
import { UserNotFoundException } from '@exceptions/user-not-found.exception';
import { GetMarketplaceUserByIdDto } from '@dto/get-marketplace-user-by-id.dto';
import { RoleScope } from '@custom-types/role-scope.type';
Expand Down Expand Up @@ -270,29 +269,11 @@ export class UsersService {
}

async getUserInfo({ userId, trx }: GetUserInfoInterface) {
const { accessKeyId, secretAccessKey, bucketName } =
this.configService.awsSdkCredentials;

const s3 = new S3({ accessKeyId, secretAccessKey });

const userIdHash = this.cryptographicService.hash({
data: userId,
algorithm: CryptoHashAlgorithm.MD5
});

let isProfilePicPresent = true;

try {
await s3
.headObject({
Bucket: bucketName,
Key: `users-profile-pictures/${userIdHash}.png`
})
.promise();
} catch (e) {
isProfilePicPresent = false;
}

const {
firstName,
lastName,
Expand Down Expand Up @@ -334,7 +315,6 @@ export class UsersService {
homeAddress,
homePhone,
email,
isProfilePicPresent,
isCompanyMember,
companyName: isCompanyMember ? company.companyName : null,
companyId: isCompanyMember ? company.id : null,
Expand Down Expand Up @@ -394,32 +374,13 @@ export class UsersService {
algorithm: CryptoHashAlgorithm.MD5
});

const { accessKeyId, secretAccessKey, bucketName } =
this.configService.awsSdkCredentials;

const s3 = new S3({ accessKeyId, secretAccessKey });

let isProfilePicPresent = true;

try {
await s3
.headObject({
Bucket: bucketName,
Key: `users-profile-pictures/${userIdHash}.png`
})
.promise();
} catch (e) {
isProfilePicPresent = false;
}

const company = await this.companyService.getCompanyByUserId({
userId: marketplaceUserId,
trx
});

const companyId = company ? company.id : null;
const companyName = company ? company.companyName : null;
const userHash = isProfilePicPresent ? userIdHash : null;

const marketplaceUser = {
email: undefined,
Expand All @@ -429,7 +390,7 @@ export class UsersService {
homePhone: user.homePhone,
namePronunciation: user.namePronunciation,
createdAt: user.createdAt,
userIdHash: userHash,
userIdHash: userIdHash,
companyId,
companyName
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ <h1>{{ t('sidebar.sidebarWelcomeTitle', { firstName: userInfo.firstName, lastNam
<div class="sidebar-user-preview">
<div class="sidebar-user-data">
<img
[src]="userInfo.isProfilePicPresent ? staticStorageLink + '/users-profile-pictures/' + userInfo.userIdHash + '.png' : staticStorageLink + '/users-profile-pictures/default.png'"
[src]="staticStorageLink + '/users-profile-pictures/' + userInfo.userIdHash + '.png'"
class="user-photo"
alt="avatar"
(error)="onImgError($event)"
/>
<div class="sidebar-user-info">
<p>{{ t('sidebar.sidebarUserFullName') }}: <b>{{ userInfo.firstName }} {{ userInfo.lastName }}</b></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export class SidebarComponent {
});
}

onImgError(event: any) {
event.target.src = `${this.staticStorageLink}/users-profile-pictures/default.png`;
}

async logoutUser() {
localStorage.removeItem('_at');
await this.handleRedirect('');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<ng-container *transloco="let t">
<div class="personal-settings-container">
<dashboard-user-photo
[isProfilePicPresent]="isProfilePicPresent"
[userIdHash]="userIdHash"
/>
<div class="personal-settings-inputs">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export class UserInfoSettingsComponent {
@Input() homePhone: string;

@Input() email: string;
@Input() isProfilePicPresent: boolean;
@Output() saveUserInfoEvent = new EventEmitter<UpdateUserInfoPayload>();
@Output() getUserInfoEvent = new EventEmitter<void>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
[src]="userProfilePictureLink"
class="user-photo"
alt="avatar"
(error)="onImgError($event)"
/>

<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import { MessagesTranslation } from '@translations/messages.enum';
})
export class UserPhotoComponent implements OnInit {
@ViewChild('fileInput', { static: false }) fileInput: ElementRef;
@Input() isProfilePicPresent: boolean;
@Input() userIdHash: string;

selectedFiles?: FileList;
preview: string | ArrayBuffer | null = '';
userProfilePictureLink: string;
defaultUserProfilePictureLink: string;
showText: boolean;

staticStorageLink = this.envService.getStaticStorageLink;
Expand Down Expand Up @@ -75,9 +75,12 @@ export class UserPhotoComponent implements OnInit {
return this.validationService.checkBase64PngImage(this.preview as string);
}

onImgError(event: any) {
event.target.src = this.defaultUserProfilePictureLink;
}

ngOnInit() {
this.userProfilePictureLink = this.isProfilePicPresent
? `${this.staticStorageLink}/users-profile-pictures/${this.userIdHash}.png`
: `${this.staticStorageLink}/users-profile-pictures/default.png`;
this.userProfilePictureLink = `${this.staticStorageLink}/users-profile-pictures/${this.userIdHash}.png`;
this.defaultUserProfilePictureLink = `${this.staticStorageLink}/users-profile-pictures/default.png`;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ <h3 class="settings-header-title">{{ t('settings.securitySettings') }}</h3>
[homeAddress]="homeAddress"
[homePhone]="homePhone"
[email]="email"
[isProfilePicPresent]="isProfilePicPresent"
(saveUserInfoEvent)="saveUserInfo($event)"
(getUserInfoEvent)="requestUserInfo()"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export class SettingsComponent implements OnInit {
homeAddress: string;
homePhone: string;
email: string;
isProfilePicPresent: boolean;
isCompanyMember: boolean;

userInfo: UserInfoResponse;
Expand Down Expand Up @@ -132,7 +131,6 @@ export class SettingsComponent implements OnInit {
this.homeAddress = userInfo.homeAddress;
this.homePhone = userInfo.homePhone;
this.email = userInfo.email;
this.isProfilePicPresent = userInfo.isProfilePicPresent;
this.isCompanyMember = userInfo.isCompanyMember;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[src]="userProfilePictureLink"
class="marketplace-user-photo"
alt="user"
(error)="onImgError($event)"
/>
<p class="marketplace-user-registration-date">
{{ t('marketplace.marketplaceUserRegDate', { date: transformDate(createdAt) }) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class MarketplaceUserComponent implements OnInit {
userNotFound: boolean;
isUserLoggedIn: boolean;
userProfilePictureLink: string;
defaultUserProfilePictureLink: string;

privateProductsFlag: boolean = false;
companyProductsFlag: boolean = false;
Expand Down Expand Up @@ -366,16 +367,19 @@ export class MarketplaceUserComponent implements OnInit {
lastName
});

this.userProfilePictureLink = userIdHash
? `${this.staticStorageLink}/users-profile-pictures/${userIdHash}.png`
: `${this.staticStorageLink}/users-profile-pictures/default.png`;
this.userProfilePictureLink = `${this.staticStorageLink}/users-profile-pictures/${userIdHash}.png`;
this.defaultUserProfilePictureLink = `${this.staticStorageLink}/users-profile-pictures/default.png`;

this.getMarketplaceUserProducts();
},
error: () => (this.userNotFound = true)
});
}

onImgError(event: any) {
event.target.src = this.defaultUserProfilePictureLink;
}

transformDate(date: Date) {
return dayjs(date).format('LL');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export class ProductComponent implements OnInit {
});

this.userProfilePictureLink = `${this.staticStorageLink}/users-profile-pictures/${product.ownerIdHash}.png`;

this.defaultUserProfilePictureLink = `${this.staticStorageLink}/users-profile-pictures/default.png`;

this.getSimilarProducts();
},
error: async () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface MarketplaceUser {
homePhone: string | null;
namePronunciation: string | null;
createdAt: Date;
userIdHash: string | null;
userIdHash: string;
companyId: string | null;
companyName: string | null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export interface UserInfoResponse {
homeAddress: string;
homePhone: string;
email: string;
isProfilePicPresent: boolean;
isCompanyMember: boolean;
companyName: string | null;
companyId: string | null;
Expand Down

0 comments on commit 57eb374

Please sign in to comment.