Commit d382ce2b authored by tinhbe's avatar tinhbe

update

parent 945c4ad3
...@@ -34,7 +34,7 @@ import { NzSelectModule } from 'ng-zorro-antd/select'; ...@@ -34,7 +34,7 @@ import { NzSelectModule } from 'ng-zorro-antd/select';
//#endregion //#endregion
export class JobComponent implements OnInit { export class JobComponent implements OnInit {
//#region Variable //#region Variable
selectedJob?: JobModel; selectedJob?: JobModel;
listOfJob: JobModel[] = []; listOfJob: JobModel[] = [];
loading = true; loading = true;
...@@ -52,40 +52,41 @@ export class JobComponent implements OnInit { ...@@ -52,40 +52,41 @@ export class JobComponent implements OnInit {
title: this.fb.control('', [Validators.required]), title: this.fb.control('', [Validators.required]),
description: this.fb.control('', [Validators.required]), description: this.fb.control('', [Validators.required]),
}); });
//#endregion //#endregion
//#region LoadData //#region LoadData
constructor(private fb: FormBuilder,private jobService: JobService, private modal: NzModalService) {} constructor(private fb: FormBuilder, private jobService: JobService, private modal: NzModalService) { }
loadDataFromServer(): void { loadDataFromServer(): void {
console.log("hello");
this.loading = true; this.loading = true;
this.jobService.jobsGet().pipe( this.jobService.jobsGet().pipe(
tap((res) => { tap((res) => {
this.listOfJob = res.responseData.items; console.log(res);
if (res.responseData)
this.listOfJob = res.responseData.rows;
}), }),
catchError((err) => { catchError((err) => {
console.log(err); this.listOfJob = [];
return of(null); return of(null);
}), }),
finalize(() => (this.loading = false)) finalize(() => (this.loading = false))
).subscribe(); ).subscribe();
} }
ngOnInit(): void { ngOnInit(): void {
this.loadDataFromServer(); this.loadDataFromServer();
} }
//#endregion //#endregion
//#region Handler //#region Handler
resetForm() resetForm() {
{
this.validateJobForm.reset(); this.validateJobForm.reset();
this.selectedJob = {} as JobModel; this.selectedJob = {} as JobModel;
} }
EnableForm() EnableForm() {
{
this.validateJobForm.enable(); this.validateJobForm.enable();
} }
DisableForm() DisableForm() {
{
this.validateJobForm.disable(); this.validateJobForm.disable();
} }
onOk(): void { onOk(): void {
...@@ -113,8 +114,7 @@ export class JobComponent implements OnInit { ...@@ -113,8 +114,7 @@ export class JobComponent implements OnInit {
return of(null); return of(null);
}) })
).subscribe(); ).subscribe();
}else if(this.isOnAdd && this.selectedJob) } else if (this.isOnAdd && this.selectedJob) {
{
const newJob: JobModel = { const newJob: JobModel = {
id: this.selectedJob.id, id: this.selectedJob.id,
type: this.validateJobForm.value.type ?? undefined, type: this.validateJobForm.value.type ?? undefined,
...@@ -137,19 +137,19 @@ export class JobComponent implements OnInit { ...@@ -137,19 +137,19 @@ export class JobComponent implements OnInit {
}) })
).subscribe(); ).subscribe();
} }
this.isOpenModal = false; this.isOpenModal = false;
this.isOnEdit = false; this.isOnEdit = false;
this.isOnAdd = false; this.isOnAdd = false;
} }
onCancel(): void { onCancel(): void {
this.isOpenModal = false; this.isOpenModal = false;
this.isOnEdit = false; this.isOnEdit = false;
} }
//#endregion //#endregion
//#region Action //#region Action
JobDetail(id: string) { JobDetail(id: string) {
this.DisableForm(); this.DisableForm();
this.isOnEdit = false; this.isOnEdit = false;
...@@ -157,13 +157,16 @@ export class JobComponent implements OnInit { ...@@ -157,13 +157,16 @@ export class JobComponent implements OnInit {
this.isOnAdd = false; this.isOnAdd = false;
this.jobService.getJob(id).pipe( this.jobService.getJob(id).pipe(
tap((res) => { tap((res) => {
this.selectedJob = res.responseData; console.log(res);
this.selectedJob = res.responseData as JobModel;
}), }),
catchError((err) => { catchError((err) => {
console.log(err); console.log(err);
return of(null); return of(null);
}), }),
finalize(() => this.loading = false)
finalize(() => (
this.loadDataFromServer(), this.loading = false))
).subscribe(); ).subscribe();
} }
onDelete(id: string) { onDelete(id: string) {
...@@ -188,14 +191,14 @@ export class JobComponent implements OnInit { ...@@ -188,14 +191,14 @@ export class JobComponent implements OnInit {
this.isOnAdd = false; this.isOnAdd = false;
this.selectedJob = data; this.selectedJob = data;
} }
addJob(){ addJob() {
this.EnableForm(); this.EnableForm();
this.resetForm(); this.resetForm();
this.isOpenModal = true; this.isOpenModal = true;
this.isOnEdit = false; this.isOnEdit = false;
this.isOnAdd = true; this.isOnAdd = true;
} }
showDeleteConfirm(id : string): void { showDeleteConfirm(id: string): void {
this.modal.confirm({ this.modal.confirm({
nzTitle: 'Bạn có chắc rằng xóa công việc này không?', nzTitle: 'Bạn có chắc rằng xóa công việc này không?',
nzOkText: 'Xóa', nzOkText: 'Xóa',
...@@ -205,5 +208,5 @@ export class JobComponent implements OnInit { ...@@ -205,5 +208,5 @@ export class JobComponent implements OnInit {
nzCancelText: 'trở về', nzCancelText: 'trở về',
}); });
} }
//#endregion //#endregion
} }
...@@ -3,6 +3,7 @@ import { HttpClient, HttpHeaders, HttpParams, HttpRequest } from '@angular/commo ...@@ -3,6 +3,7 @@ import { HttpClient, HttpHeaders, HttpParams, HttpRequest } from '@angular/commo
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { environment } from '../../../../environments/environment.development'; import { environment } from '../../../../environments/environment.development';
import { JobModel } from '../model/jobModel.model'; import { JobModel } from '../model/jobModel.model';
import { ResponseResult, Rows } from '../../../shared/data-access/interface/response.type';
@Injectable({ @Injectable({
...@@ -13,37 +14,41 @@ export class JobService { ...@@ -13,37 +14,41 @@ export class JobService {
apiUrlById = environment.API_DOMAIN + '/jobById'; apiUrlById = environment.API_DOMAIN + '/jobById';
constructor(private http: HttpClient) {} constructor(private http: HttpClient) {}
jobsGet(): Observable<any> { // jobsGet(): Observable<ResponseResult<JobModel[]>> {
// return this.http.get<ResponseResult<JobModel[]>>(this.apiUrl);
// }
jobsGet(): Observable<ResponseResult<Rows<JobModel>>> {
const params = new HttpParams() const params = new HttpParams()
return this.http.get<any>(this.apiUrl, { params }); return this.http.get<ResponseResult<Rows<JobModel>>>(this.apiUrl);
} }
addingNewJob(data: JobModel): Observable<any> {
addingNewJob(data: JobModel): Observable<ResponseResult<JobModel>> {
const headers = new HttpHeaders() const headers = new HttpHeaders()
.set('Content-Type', 'application/json') .set('Content-Type', 'application/json')
.set('authorization', `Bearer ${localStorage.getItem('token')}`); .set('Authorization', `Bearer ${localStorage.getItem('token')}`);
return this.http.post<any>(this.apiUrl, data, { headers }); return this.http.post<ResponseResult<JobModel>>(this.apiUrl, data, { headers });
} }
deleteJob(id: string): Observable<any> { deleteJob(id: string): Observable<ResponseResult<JobModel>> {
const headers = new HttpHeaders() const headers = new HttpHeaders()
.set('Content-Type', 'application/json') .set('Content-Type', 'application/json')
.set('Authorization', `Bearer ${localStorage.getItem('token')}`); .set('Authorization', `Bearer ${localStorage.getItem('token')}`);
const url = `${this.apiUrl}/${id}`; const url = `${this.apiUrl}/${id}`;
return this.http.delete<any>(url, { headers }); return this.http.delete<ResponseResult<JobModel>>(url, { headers });
} }
editJob(data: JobModel): Observable<any> { editJob(data: JobModel): Observable<ResponseResult<JobModel>> {
const headers = new HttpHeaders() const headers = new HttpHeaders()
.set('Content-Type', 'application/json') .set('Content-Type', 'application/json')
.set('Authorization', `Bearer ${localStorage.getItem('token')}`); .set('Authorization', `Bearer ${localStorage.getItem('token')}`);
const url = `${this.apiUrl}/${data.id}`; const url = `${this.apiUrl}/${data.id}`;
return this.http.put<any>(url, data, { headers }); return this.http.put<ResponseResult<JobModel>>(url, data, { headers });
} }
getJob(id: string): Observable<any> { getJob(id: string): Observable<ResponseResult<JobModel>> {
const headers = new HttpHeaders() const headers = new HttpHeaders()
.set('Content-Type', 'application/json') .set('Content-Type', 'application/json')
.set('Authorization', `Bearer ${localStorage.getItem('token')}`); .set('Authorization', `Bearer ${localStorage.getItem('token')}`);
const url = `${this.apiUrlById}/${id}`; const url = `${this.apiUrlById}/${id}`;
console.log(id, url); console.log(id, url);
return this.http.get<any>(url, { headers }); return this.http.get<ResponseResult<JobModel>>(url, { headers });
} }
} }
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<nz-form-item> <nz-form-item>
<nz-form-control nzErrorTip="Please input your Password!"> <nz-form-control nzErrorTip="Please input your Password!">
<nz-input-group nzPrefixIcon="lock"> <nz-input-group nzPrefixIcon="lock">
<input type="password" nz-input formControlName="password" placeholder="Password" /> <input type="password" nz-input formControlName="password" placeholder="Password" minlength="6" />
</nz-input-group> </nz-input-group>
</nz-form-control> </nz-form-control>
</nz-form-item> </nz-form-item>
......
...@@ -13,6 +13,7 @@ import { FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, Validators } ...@@ -13,6 +13,7 @@ import { FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, Validators }
import { catchError, finalize, Observable, of, tap } from 'rxjs'; import { catchError, finalize, Observable, of, tap } from 'rxjs';
import { response } from 'express'; import { response } from 'express';
import { AuthService } from '../data-access/Services/Auth.Service'; import { AuthService } from '../data-access/Services/Auth.Service';
import { userNameRegex } from '../../shared/data-access/const/user-name-regex.const';
@Component({ @Component({
selector: 'meu-login', selector: 'meu-login',
standalone: true, standalone: true,
...@@ -44,11 +45,19 @@ export class LoginComponent implements OnInit { ...@@ -44,11 +45,19 @@ export class LoginComponent implements OnInit {
}); });
} }
ngOnInit() {} ngOnInit() {}
validateUserName(userName: string): boolean {
const regex = new RegExp(userNameRegex);
return regex.test(userName);
}
onSubmit() { onSubmit() {
if (!this.loginForm.valid) { if (!this.loginForm.valid) {
this.MgsError = "Vui lòng nhập thông tin đăng nhập"; this.MgsError = "Vui lòng nhập thông tin đăng nhập";
return; return;
} }
if (!this.validateUserName(this.loginForm.value.userName)) {
this.MgsError = "tài khoản không được thêm các kí tự đặc biệt";
return;
}
this.authService.login(this.loginForm.value.userName, this.loginForm.value.password).pipe( this.authService.login(this.loginForm.value.userName, this.loginForm.value.password).pipe(
catchError((err) => { catchError((err) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment