Skip to content

Commit

Permalink
sonar fix
Browse files Browse the repository at this point in the history
  • Loading branch information
furknyavuz committed Aug 28, 2021
1 parent 2745818 commit 8d4aab6
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ export class PublicProfileComponent implements OnInit, OnDestroy {
this.numberOfEventsTaken = result[0].numberOfEventsTaken
})

this.numberOfEventsMade = undefined;
this.rateObject = undefined;
this.topContributor = undefined;

if ( visitedUserInfo.payload?.userProfileActivated ) {
this.userActivityService.getNumberOfEventsMade( visitedUserInfo.username ).subscribe( result => {
this.numberOfEventsMade = result.numberOfEventsMade
Expand All @@ -132,28 +136,8 @@ export class PublicProfileComponent implements OnInit, OnDestroy {
}
} );
})
} else {
this.numberOfEventsMade = undefined
this.rateObject = undefined
this.topContributor = undefined
}
// check if currentUser follows publicProfile
this.basicInfoService.userInfo.subscribe( currentUserInfo => {
this.currentUserInfo = currentUserInfo;
if ( currentUserInfo && this.username !== currentUserInfo?.username )
this.followerService.isFollowing( this.username ).subscribe( result => {
this.isFollowing = result[ 0 ].isFollowing;
} );
} );

// get follower and followed count
this.followerService.count( this.username ).subscribe( followerCount => {
this.followerCount = followerCount[ 0 ].count;
} );

this.followeeService.count( this.username ).subscribe( followeeCount => {
this.followeeCount = followeeCount[ 0 ].count;
} );
this.fillFollowInfo();

if ( this.userInfo?.payload?.profileImageId ) {
this.fileStorageService.downloadVisitedProfileImage( this.userInfo.payload.profileImageId ).subscribe( profileImg => {
Expand All @@ -177,6 +161,26 @@ export class PublicProfileComponent implements OnInit, OnDestroy {
} );
}

private fillFollowInfo() {
// check if currentUser follows publicProfile
this.basicInfoService.userInfo.subscribe( currentUserInfo => {
this.currentUserInfo = currentUserInfo;
if ( currentUserInfo && this.username !== currentUserInfo?.username )
this.followerService.isFollowing( this.username ).subscribe( result => {
this.isFollowing = result[ 0 ].isFollowing;
} );
} );

// get follower and followed count
this.followerService.count( this.username ).subscribe( followerCount => {
this.followerCount = followerCount[ 0 ].count;
} );

this.followeeService.count( this.username ).subscribe( followeeCount => {
this.followeeCount = followeeCount[ 0 ].count;
} );
}

ngOnInit(): void {
this.isPublic = this.route.snapshot.data.isPublic;
}
Expand Down
67 changes: 37 additions & 30 deletions src/app/page/landing-layout/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ export class LoginComponent implements OnInit, OnDestroy {
}
return;
}
this.login();
}

private login() {
this.authenticationService.login(
this.form.controls.username.value,
this.form.controls.password.value,
Expand All @@ -92,40 +95,44 @@ export class LoginComponent implements OnInit, OnDestroy {
.subscribe(
() => {
if ( this.returnUrl !== URLS.dashboard.root ) {
// Special case for initialization (if return url is else than dashboard)
this.basicInfoService.me()
.subscribe( userInfo => {
this.router.navigateByUrl( this.returnUrl );
if ( !userInfo.payload ) {
this.basicInfoService.createMyInfo()
.subscribe( () => {
this.router.navigate( [ URLS.settings.welcome ] );
}
);
} else {
this.fileStorageService.downloadProfileImage( userInfo.payload.profileImageId ).subscribe();

const userInterests = userInfo?.payload?.interests;
const categories: any[] = [];

if ( userInterests && userInterests.length > 0 ) {
for ( const interest of userInterests ) {
categories.push(
{
category: interest.category,
subCategory: interest.subCategory,
leafCategory: interest.leafCategory
}
);
}
}
this.loginWithoutOpeningDashboard();
} else {
this.router.navigate( [ this.returnUrl ] );
}
}
);
}

this.eventService.initSearchEvents( categories );
}
private loginWithoutOpeningDashboard() {
// Special case for initialization (if return url is else than dashboard)
this.basicInfoService.me()
.subscribe( userInfo => {
this.router.navigateByUrl( this.returnUrl );
if ( !userInfo.payload ) {
this.basicInfoService.createMyInfo()
.subscribe( () => {
this.router.navigate( [ URLS.settings.welcome ] );
}
);
} else {
this.router.navigate( [ this.returnUrl ] );
this.fileStorageService.downloadProfileImage( userInfo.payload.profileImageId ).subscribe();

const userInterests = userInfo?.payload?.interests;
const categories: any[] = [];

if ( userInterests && userInterests.length > 0 ) {
for ( const interest of userInterests ) {
categories.push(
{
category: interest.category,
subCategory: interest.subCategory,
leafCategory: interest.leafCategory
}
);
}
}

this.eventService.initSearchEvents( categories );
}
}
);
Expand Down
26 changes: 15 additions & 11 deletions src/app/service/category/category.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,29 @@ import { CATEGORIES, CATEGORIES_MAP } from '../../util/constant';
} )
export class CategoryService {
search( q: string ) {
const categories = [];
const categoriesSet = new Set();

q = '^' + q;
const re = new RegExp( q, 'gi' );
const regExp = new RegExp( q, 'gi' );

for ( const category of CATEGORIES ) {
if ( re.test( category.name ) && !categories.includes( { category } ) ) {
categories.push( { category } );
if ( regExp.test( category.name ) ) {
categoriesSet.add( { category } );
}

for ( const subCategory of category.payload?.subCategories ) {
if ( subCategory.name.match( re ) && !categories.includes( { category, subCategory } ) ) {
categories.push( { category, subCategory } );
if ( subCategory.name.match( regExp ) ) {
categoriesSet.add( { category, subCategory } );
}

for ( const leafCategory of subCategory.leafCategories ) {
if ( leafCategory?.name.match( re ) && !categories.includes( { category, subCategory, leafCategory } ) ) {
categories.push( { category, subCategory, leafCategory } );
if ( leafCategory?.name.match( regExp ) ) {
categoriesSet.add( { category, subCategory, leafCategory } );
}
}
}
}
return of( categories );
return of( Array.from( categoriesSet ) );
}

getCategoryIdFromCategories( categories ) {
Expand Down Expand Up @@ -65,7 +69,7 @@ export class CategoryService {

CATEGORIES_MAP.get( categoryId ).subCategories.forEach( ( category: any, id: number ) => {
categories.push( { name: category.name, id } );
} )
} );

return of( categories );
}
Expand All @@ -75,7 +79,7 @@ export class CategoryService {

CATEGORIES_MAP.get( categoryId ).subCategories.get( subCategoryId ).leafCategories.forEach( ( category: any, id: number ) => {
categories.push( { name: category.name, id } );
} )
} );

return of( categories );
}
Expand Down
53 changes: 18 additions & 35 deletions src/app/service/event/event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,26 +191,7 @@ export class EventService {
}

searchProcess( searchedEvents: any, eventType: EventTypes ) {
searchedEvents.map( event => {
const categoryResult = this.categoryService.getCategoryFromId( event.payload?.category,
event.payload?.subCategory, event.payload?.leafCategory );

if ( categoryResult.category ) {
event.payload.category = categoryResult.category;
}

if ( categoryResult.subCategory ) {
event.payload.subCategory = categoryResult.subCategory;
}

if ( categoryResult.leafCategory ) {
event.payload.leafCategory = categoryResult.leafCategory;
}

this.checkInProgress( event )

event.date = formatDate( new Date( event.date ), 'yyyy/MM/dd HH:mm Z', 'en-US' );
} );
searchedEvents.map( event => this.fillEvent(event));

if ( eventType === EventTypes.Recommended ) {
this.recommendedEventsSubject.next( searchedEvents );
Expand Down Expand Up @@ -321,26 +302,28 @@ export class EventService {
}
}

getAttendedEventsProcess( attendedData: any, startDate?: string, endDate?: string ) {
attendedData.map( event => {
const categoryResult = this.categoryService.getCategoryFromId( event.payload?.category,
fillEvent(event) {
const categoryResult = this.categoryService.getCategoryFromId( event.payload?.category,
event.payload?.subCategory, event.payload?.leafCategory );

if ( categoryResult.category ) {
event.payload.category = categoryResult.category;
}
if ( categoryResult.category ) {
event.payload.category = categoryResult.category;
}

if ( categoryResult.subCategory ) {
event.payload.subCategory = categoryResult.subCategory;
}
if ( categoryResult.subCategory ) {
event.payload.subCategory = categoryResult.subCategory;
}

if ( categoryResult.leafCategory ) {
event.payload.leafCategory = categoryResult.leafCategory;
}
if ( categoryResult.leafCategory ) {
event.payload.leafCategory = categoryResult.leafCategory;
}

this.checkInProgress( event )
event.date = formatDate( new Date( event.date ), 'yyyy/MM/dd HH:mm Z', 'en-US' );
} );
this.checkInProgress( event )
event.date = formatDate( new Date( event.date ), 'yyyy/MM/dd HH:mm Z', 'en-US' );
}

getAttendedEventsProcess( attendedData: any, startDate?: string, endDate?: string ) {
attendedData.map( event => this.fillEvent(event));

if ( startDate && endDate ) {
return attendedData
Expand Down

0 comments on commit 8d4aab6

Please sign in to comment.