Commit d382ce2b authored by tinhbe's avatar tinhbe

update

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