import { Injectable } from '@angular/core' ; import { HttpClient } from '@angular/common/http' ; import { IEmployee , IEmployeeFindInput , IEmployeeCreateInput , IEmployeeUpdateInput } from '@gauzy/contracts' ; import { firstValueFrom , Observable } from 'rxjs' ; import { toParams } from '@gauzy/common-angular' ; import { API_PREFIX } from '../constants/app.constants' ; @ Injectable ( ) export class EmployeesService { constructor ( private http ) { } getAllPublic ( relations ? , findInput ? ) { const data = JSON . stringify ( { relations , findInput } ) ; return this . http . get < { items : IEmployee [ ] ; total : number ; } > ( `${ API_PREFIX }/employee/public` , { params : { data } } ) ; } getPublicById ( id , relations ? ) { const data = JSON . stringify ( { relations } ) ; return this . http . get < IEmployee > ( `${ API_PREFIX }/employee/public/${ id }` , { params : { data } } ) ; } getAll ( relations ? , findInput ? ) { const data = JSON . stringify ( { relations , findInput } ) ; return this . http . get < { items : IEmployee [ ] ; total : number ; } > ( `${ API_PREFIX }/employee` , { params : { data } } ) ; } getWorking ( organizationId , tenantId , forMonth , withUser ) { const query = { organizationId , tenantId , forMonth , withUser } ; const data = JSON . stringify ( { findInput : query } ) ; return firstValueFrom ( this . http . get < { items : IEmployee [ ] ; total : number ; } > ( `${ API_PREFIX }/employee/working` , { params : { data } } ) ) ; } getWorkingCount ( organizationId , tenantId , forMonth , withUser ) { const query = { organizationId , tenantId , forMonth , withUser } ; const data = JSON . stringify ( { findInput : query } ) ; return firstValueFrom ( this . http . get < { items : IEmployee [ ] ; total : number ; } > ( `${ API_PREFIX }/employee/working/count` , { params : { data } } ) ) ; } getEmployeeByUserId ( userId , relations ? , findInput ? ) { const data = JSON . stringify ( { relations , findInput } ) ; return firstValueFrom ( this . http . get < { success : boolean ; result : IEmployee ; } > ( `${ API_PREFIX }/employee/user/${ userId }` , { params : { data } } ) ) ; } getEmployeeById ( id , relations ? , useTenant ? ) { const data = JSON . stringify ( { relations , useTenant } ) ; return firstValueFrom ( this . http . get < IEmployee > ( `${ API_PREFIX }/employee/${ id }` , { params : { data } } ) ) ; } setEmployeeAsInactive ( id ) { return firstValueFrom ( this . http . put < IEmployee > ( `${ API_PREFIX }/employee/${ id }` , { isActive : false } ) ) ; } setEmployeeAsActive ( id ) { return firstValueFrom ( this . http . put < IEmployee > ( `${ API_PREFIX }/employee/${ id }` , { isActive : true } ) ) ; } setEmployeeEndWork ( id , date ) { return firstValueFrom ( this . http . put < IEmployee > ( `${ API_PREFIX }/employee/${ id }` , { endWork : date } ) ) ; } update ( id , updateInput ) { return firstValueFrom ( this . http . put ( `${ API_PREFIX }/employee/${ id }` , updateInput ) ) ; } getEmployeeJobsStatistics ( request ) { return firstValueFrom ( this . http . get ( `${ API_PREFIX }/employee/job-statistics` , { params : toParams ( request ) } ) ) ; } updateJobSearchStatus ( id , isJobSearchActive ) { return firstValueFrom ( this . http . put ( `${ API_PREFIX }/employee/${ id }/job-search-status` , { isJobSearchActive } ) ) ; } create ( createInput ) { return this . http . post < IEmployee > ( `${ API_PREFIX }/employee` , createInput ) ; } createBulk ( createInput ) { return this . http . post < IEmployee [ ] > ( `${ API_PREFIX }/employee/bulk` , createInput ) ; } }