Skip to content

Commit

Permalink
Remove code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielaTiago committed Dec 12, 2023
1 parent 32d5dab commit 7a4b644
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 83 deletions.
30 changes: 18 additions & 12 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import { OAuthModule, OAuthStorage } from 'angular-oauth2-oidc';
import { InputTextModule } from 'primeng/inputtext';
import { DropdownModule } from 'primeng/dropdown';
import { ButtonModule } from 'primeng/button';
import { SocialLoginModule, SocialAuthServiceConfig } from '@abacritt/angularx-social-login';
import { GoogleLoginProvider, FacebookLoginProvider } from '@abacritt/angularx-social-login';

import {
SocialLoginModule,
SocialAuthServiceConfig,
GoogleLoginProvider,
FacebookLoginProvider,
} from '@abacritt/angularx-social-login';

// Declaration
import { NgModule } from '@angular/core';
Expand All @@ -34,15 +37,18 @@ import { AuthService } from './services/auth.service';
import { EditUserComponent } from './pages/edit-user/edit-user.component';
import { StreamViewComponent } from './pages/stream-view/stream-view.component';
import { UpdateRoleComponent } from './pages/update-role/update-role.component';
import {MatPaginatorModule} from '@angular/material/paginator';
import { MatPaginatorModule } from '@angular/material/paginator';
import { MenuModule } from 'primeng/menu';
import { VideoCommentComponent } from './components/video-comment/video-comment.component';
import { SuggestAgendaComponent } from './pages/suggest-agenda/suggest-agenda.component';
import { ParticipateComponent } from './pages/participate/participate.component';
import { GridComponent } from './pages/grid/grid.component';
import { GridDaysComponent } from './pages/grid-days/grid-days.component';
import { ProgressSpinnerModule } from 'primeng/progressspinner';
import { NgxGoogleAnalyticsModule, NgxGoogleAnalyticsRouterModule } from 'ngx-google-analytics';
import {
NgxGoogleAnalyticsModule,
NgxGoogleAnalyticsRouterModule,
} from 'ngx-google-analytics';
import { CatalogComponent } from './pages/catalog/catalog.component';

@NgModule({
Expand All @@ -64,7 +70,7 @@ import { CatalogComponent } from './pages/catalog/catalog.component';
MatPaginatorModule,
SocialLoginModule,
NgxGoogleAnalyticsModule.forRoot('G-XL7Z0L7VM8'),
NgxGoogleAnalyticsRouterModule
NgxGoogleAnalyticsRouterModule,
],

declarations: [
Expand All @@ -87,7 +93,7 @@ import { CatalogComponent } from './pages/catalog/catalog.component';
GridComponent,
GridDaysComponent,
VideoCommentComponent,
CatalogComponent
CatalogComponent,
],

providers: [
Expand All @@ -110,18 +116,18 @@ import { CatalogComponent } from './pages/catalog/catalog.component';
id: GoogleLoginProvider.PROVIDER_ID,
provider: new GoogleLoginProvider(
'254484469180-1imr4ds36p8rq4fe7udkja212tu0p7jl.apps.googleusercontent.com'
)
),
},
{
id: FacebookLoginProvider.PROVIDER_ID,
provider: new FacebookLoginProvider('2640880742734858')
}
provider: new FacebookLoginProvider('2640880742734858'),
},
],
onError: (err) => {
console.error(err);
}
},
} as SocialAuthServiceConfig,
}
},
],
bootstrap: [AppComponent],
})
Expand Down
4 changes: 1 addition & 3 deletions src/app/components/background/background.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { MenuItem, MessageService } from 'primeng/api';
import { AppComponent } from 'src/app/app.component';

@Component({
selector: 'app-background',
Expand All @@ -12,8 +11,6 @@ export class BackgroundComponent implements OnInit {
items: MenuItem[] = [];
mobileDevide: boolean = true;

constructor() {}

ngOnInit(): void {
this.items = [
{
Expand All @@ -38,6 +35,7 @@ export class BackgroundComponent implements OnInit {
this.mobileDevide = false;
}
}

getActualRoute(): string {
return window.location.pathname;
}
Expand Down
7 changes: 5 additions & 2 deletions src/app/pages/login-social/login-social.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Component, OnInit } from '@angular/core';
import { SocialAuthService, SocialUser } from '@abacritt/angularx-social-login';
import { FacebookLoginProvider } from '@abacritt/angularx-social-login';
import {
SocialAuthService,
SocialUser,
FacebookLoginProvider,
} from '@abacritt/angularx-social-login';
import { HttpClient } from '@angular/common/http';
import { Router } from '@angular/router';
import { AuthService } from '../../services/auth.service';
Expand Down
41 changes: 21 additions & 20 deletions src/app/pages/login/login.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { MustMatch } from 'src/app/helper/must-match.validator';
import { AuthService } from '../../services/auth.service';
import { AlertService } from 'src/app/services/alert.service';
import { HttpErrorResponse } from '@angular/common/http';
Expand All @@ -21,35 +20,37 @@ export class LoginComponent implements OnInit {
private router: Router,
private fb: FormBuilder,
private authService: AuthService,
private alertService: AlertService,
) { }
private alertService: AlertService
) {}

ngOnInit(): void {
this.userForm = this.fb.group({
email: ['', [Validators.required]],
password: ['', [Validators.required]],
},
);
});
}

login() {
if (this.userForm.valid) {
this.authService
.loginUser(this.userForm.value).subscribe({
next: (data) => {
localStorage.setItem('token', data.access_token);
this.navigator('/catalog');
},
error: (error: ErrorResponseType) => {
this.alertService.errorMessage(error.error);
let errorDetail: IDetails = { ...error.error };
if (errorDetail.detail === 'A sua conta ainda não foi ativada.') {
this.navigator('/activeAccount');
}
},
});
this.authService.loginUser(this.userForm.value).subscribe({
next: (data) => {
localStorage.setItem('token', data.access_token);
this.navigator('/catalog');
},
error: (error: ErrorResponseType) => {
this.alertService.errorMessage(error.error);
let errorDetail: IDetails = { ...error.error };
if (errorDetail.detail === 'A sua conta ainda não foi ativada.') {
this.navigator('/activeAccount');
}
},
});
} else {
this.alertService.showMessage("info", "Alerta", "Preencha todos os campos corretamente!");
this.alertService.showMessage(
'info',
'Alerta',
'Preencha todos os campos corretamente!'
);
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/app/pages/profile/profile.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Component } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { NavigationExtras, Router } from '@angular/router';
import { FormBuilder } from '@angular/forms';
import { Router } from '@angular/router';
import { UserService } from 'src/app/services/user.service';
import jwt_decode from 'jwt-decode';
import { AlertService } from 'src/app/services/alert.service';
import { ConfirmationService, MessageService } from 'primeng/api';
import { ConfirmationService } from 'primeng/api';
import { AuthService } from 'src/app/services/auth.service';
import { HttpErrorResponse } from '@angular/common/http';
import { take, timer } from 'rxjs';
Expand Down Expand Up @@ -34,10 +34,10 @@ export class ProfileComponent {
this.setUserIdFromToken(localStorage.getItem('token') as string);
this.getUser();
timer(15 * 60 * 1000)
.pipe(take(1))
.subscribe(() => {
this.showRenewTokenDialog();
});
.pipe(take(1))
.subscribe(() => {
this.showRenewTokenDialog();
});
}

setUserIdFromToken(token: string) {
Expand Down Expand Up @@ -122,10 +122,10 @@ export class ProfileComponent {
error: (error: ErrorResponseType) => {
console.error('Failed to refresh token:', error);
this.authService.logout();
}
},
});
}

navigatorEdit(): void {
this.router.navigate([`/editUser/${this.user.id}`]);
}
Expand Down
53 changes: 27 additions & 26 deletions src/app/pages/update-role/update-role.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Component, OnInit } from '@angular/core';
import { PageEvent } from '@angular/material/paginator';
import jwt_decode from 'jwt-decode';


@Component({
selector: 'app-update-role',
templateUrl: './update-role.component.html',
Expand All @@ -13,9 +12,9 @@ export class UpdateRoleComponent implements OnInit {
users: any = [];
userId: number = 0;

filterInputValue: string = "";
filterConnectionValue: string = ""
filterInputValue: string = '';
filterConnectionValue: string = '';

total: number = 0;
pageSize: number = 10;
pageIndex: number = 0;
Expand All @@ -25,7 +24,7 @@ export class UpdateRoleComponent implements OnInit {
ngOnInit(): void {
this.getUserid();
this.getAllUsers();
};
}

updateUserRole(id: number) {
this.userService.updateUserRole(id).subscribe({
Expand All @@ -36,44 +35,46 @@ export class UpdateRoleComponent implements OnInit {
console.error('Erro', erro);
},
});
};
}

getUserid() {
const decodedToken: any = jwt_decode(
localStorage.getItem('token') as string
);
this.userId = decodedToken.id;
};
}

filterUser() {
this.pageIndex = 0;
this.getAllUsers();
};
}

onPaginateChange(event: PageEvent) {
this.pageSize = event.pageSize;
this.pageIndex = event.pageIndex;

this.getAllUsers();
};
}

getAllUsers() {
this.userService.getAllUsers({
nameEmail: this.filterInputValue,
connection: this.filterConnectionValue,
limit: this.pageSize,
offset: (this.pageIndex * this.pageSize)
}).subscribe({
next: (data: Response) => {
this.users = data.body;
if (data && data.headers && data.headers.has("x-total-count")) {
const totalCountHeader = data.headers.get("x-total-count");
this.total = Number.parseInt(totalCountHeader || '0', 10);
}
},
error: (erro) => {
console.error('Erro', erro);
},
});
this.userService
.getAllUsers({
nameEmail: this.filterInputValue,
connection: this.filterConnectionValue,
limit: this.pageSize,
offset: this.pageIndex * this.pageSize,
})
.subscribe({
next: (data: Response) => {
this.users = data.body;
if (data && data.headers && data.headers.has('x-total-count')) {
const totalCountHeader = data.headers.get('x-total-count');
this.total = Number.parseInt(totalCountHeader ?? '0', 10);
}
},
error: (erro) => {
console.error('Erro', erro);
},
});
}
}
Loading

0 comments on commit 7a4b644

Please sign in to comment.