83 lines
2.8 KiB
TypeScript
Raw Normal View History

2025-06-06 07:38:11 -03:00
import { Injectable } from '@angular/core';
2025-06-08 00:03:38 -03:00
import { environment } from '../../../../environments/environment';
import { HttpClient } from '@angular/common/http';
import { UserService } from '../common/user.service';
import { map, Observable } from 'rxjs';
import { Location } from '../../models/preparer/location';
2025-06-06 07:38:11 -03:00
@Injectable({
providedIn: 'root'
})
export class LocationService {
2025-06-08 00:03:38 -03:00
private apiUrl = environment.apiUrl;
private apiDb = environment.apiDb;
2025-06-06 07:38:11 -03:00
2025-06-08 00:03:38 -03:00
constructor(private http: HttpClient, private userService: UserService) { }
getLocationsById(id: number): Observable<Location[]> {
return this.http.get<any[]>(`${this.apiUrl}/${this.apiDb}/GetPreparerLocByClientid?p_spid=${this.userService.getUserSpid()}&p_clientid=${id}`).pipe(
map(response => this.mapToLocations(response)));
}
private mapToLocations(data: any[]): Location[] {
return data.map(location => ({
locationid: location.LOCATIONID,
spid: location.SPID,
clientid: location.CLIENTID,
name: location.NAMEOF,
address1: location.ADDRESS1,
address2: location.ADDRESS2,
city: location.CITY,
state: location.STATE,
country: location.COUNTRY,
zip: location.ZIP,
createdBy: location.CREATEDBY || null,
dateCreated: location.DATECREATED || null,
lastUpdatedBy: location.LASTUPDATEDBY || null,
lastUpdatedDate: location.LASTUPDATEDDATE || null,
isInactive: location.INACTIVEFLAG === 'Y' || false,
inactivatedDate: location.INACTIVEDATE || null
}));
}
createLocation(clientid: number, data: Location): Observable<any> {
const location = {
P_SPID: this.userService.getUserSpid(),
P_CLIENTID: clientid,
P_CLIENTLOCADDRESSTABLE: [{
P_NAMEOF: data.name,
P_ADDRESS1: data.address1,
P_ADDRESS2: data.address2,
P_CITY: data.city,
P_STATE: data.state,
P_COUNTRY: data.country,
P_ZIP: data.zip,
}],
P_USERID: this.userService.getUser()
}
return this.http.post(`${this.apiUrl}/${this.apiDb}/CreateClientLocations`, location);
}
updateLocation(locationId: number, data: Location): Observable<any> {
const location = {
P_SPID: this.userService.getUserSpid(),
P_CLIENTLOCATIONID: locationId,
P_LOCATIONNAME: data.name,
P_ADDRESS1: data.address1,
P_ADDRESS2: data.address2,
P_CITY: data.city,
P_STATE: data.state,
P_COUNTRY: data.country,
P_ZIP: data.zip,
P_USERID: this.userService.getUser()
}
return this.http.put(`${this.apiUrl}/${this.apiDb}/UpdateClientLocations`, location);
}
// deleteLocation(clientContactId: string): Observable<any> {
// return this.http.post(`${this.apiUrl}/${this.apiDb}/InactivateSPContact?p_clientcontactid=${clientContactId}`, null);
// }
2025-06-06 07:38:11 -03:00
}