PageSourceSearch

https://office.workvine.nl/chunk-O3HWLQEA.js

js workvine.nl collected 2026-10-09 01:41:12 UTC 6,178 bytes, 166 lines download raw bytes

1import {
2  AuthenticationService,
3  Firestore,
4  collection,
5  collectionSnapshots,
6  doc,
7  docSnapshots,
8  environment,
9  getDocs,
10  query,
11  updateDoc,
12  where,
13  writeBatch
14} from "./chunk-2TSZT3SZ.js";
15import {
16  HttpClient
17} from "./chunk-HE5ARQDU.js";
18import {
19  Injectable,
20  __spreadProps,
21  __spreadValues,
22  from,
23  map,
24  setClassMetadata,
25  switchMap,
26  take,
27  ɵɵdefineInjectable,
28  ɵɵinject
29} from "./chunk-ZGC4HH7K.js";
30
31// src/app/_services/location.service.ts
32var LocationService = class _LocationService {
33  constructor(authService, firestore, http) {
34    this.authService = authService;
35    this.firestore = firestore;
36    this.http = http;
37  }
38  getActiveLocations() {
39    return this.authService.getCurrentSession$().pipe(take(1), switchMap((session) => {
40      const colRef = collection(this.firestore, `organizations/${session.orgId}/locations`);
41      const q = query(colRef, where("active", "==", true));
42      return collectionSnapshots(q);
43    }), map((colSnaps) => colSnaps.map((colSnap) => __spreadProps(__spreadValues({}, colSnap.data()), {
44      exists: colSnap.exists(),
45      id: colSnap.id
46    }))));
47  }
48  getLocations() {
49    return this.authService.getCurrentSession$().pipe(take(1), switchMap((session) => {
50      const colRef = collection(this.firestore, `organizations/${session.orgId}/locations`);
51      return collectionSnapshots(colRef);
52    }), map((colSnaps) => colSnaps.map((colSnap) => __spreadProps(__spreadValues({}, colSnap.data()), {
53      exists: colSnap.exists(),
54      id: colSnap.id
55    }))));
56  }
57  getLocationByLocationId(locationId) {
58    return this.authService.getCurrentSession$().pipe(take(1), switchMap((session) => {
59      const docRef = doc(this.firestore, "organizations", session.orgId, "locations", locationId);
60      return docSnapshots(docRef);
61    }), map((docSnap) => __spreadProps(__spreadValues({}, docSnap.data()), {
62      id: docSnap.id,
63      exists: docSnap.exists()
64    })));
65  }
66  isLocationNameTaken(name, excludeId) {
67    return this.isLocationFieldTaken$("name", name, excludeId);
68  }
69  isLocationAbbreviationTaken(abbreviation, excludeId) {
70    return this.isLocationFieldTaken$("abbreviation", abbreviation, excludeId);
71  }
72  getLocationRoles() {
73    return this.authService.getCurrentSession$().pipe(take(1), switchMap((session) => {
74      const colRef = collection(this.firestore, "organizations", session.orgId, "locationUsers");
75      return collectionSnapshots(colRef);
76    }), map((colSnaps) => colSnaps.map((docSnap) => __spreadProps(__spreadValues({}, docSnap.data()), {
77      id: docSnap.id,
78      exists: docSnap.exists()
79    }))));
80  }
81  saveLocationRole(location, locationUserId) {
82    const url = environment.apiConfig.manageLocationRole;
83    const body = {
84      payload: location,
85      enableDebug: !environment.production
86    };
87    if (locationUserId) {
88      body.locationUserId = locationUserId;
89      body.action = "update";
90    } else {
91      body.action = "create";
92    }
93    return this.http.post(url, body);
94  }
95  deleteLocationRole(locationUserId) {
96    const url = environment.apiConfig.manageLocationRole;
97    const body = {
98      action: "delete",
99      locationUserId,
100      enableDebug: !environment.production
101    };
102    return this.http.post(url, body);
103  }
104  updateLocation(locationId, location) {
105    return this.authService.getCurrentSession$().pipe(take(1), switchMap((session) => {
106      const docRef = doc(this.firestore, "organizations", session.orgId, "locations", locationId);
107      return updateDoc(docRef, location);
108    }));
109  }
110  isLocationFieldTaken$(fieldName, value, excludeId, caseInsensitive = false) {
111    return this.authService.getCurrentSession$().pipe(take(1), switchMap((session) => {
112      const colRef = collection(this.firestore, "organizations", session.orgId, "locations");
113      if (caseInsensitive) {
114        return from(getDocs(colRef)).pipe(map((snapshot) => snapshot.docs.some((d) => d.id !== excludeId && d.data()[fieldName].toLowerCase() === value.toLowerCase())));
115      }
116      const q = query(colRef, where(fieldName, "==", value));
117      return from(getDocs(q)).pipe(map((snapshot) => snapshot.docs.some((d) => d.id !== excludeId)));
118    }));
119  }
120  batchCreateLocationWithSpaces(location, spaces) {
121    return this.authService.getCurrentSession$().pipe(take(1), switchMap((session) => {
122      const batch = writeBatch(this.firestore);
123      const locationDocRef = doc(collection(this.firestore, "organizations", session.orgId, "locations"));
124      batch.set(locationDocRef, __spreadProps(__spreadValues({}, location), {
125        createdBy: session.fullName,
126        createdById: session.employeeId,
127        lastUpdatedBy: session.fullName,
128        lastUpdatedById: session.employeeId
129      }));
130      const spacesColRef = collection(this.firestore, "organizations", session.orgId, "spaces");
131      for (const space of spaces) {
132        const spaceDocRef = doc(spacesColRef);
133        batch.set(spaceDocRef, __spreadProps(__spreadValues({}, space), {
134          locationId: locationDocRef.id,
135          createdBy: session.fullName,
136          createdById: session.employeeId,
137          lastUpdatedBy: session.fullName,
138          lastUpdatedById: session.employeeId
139        }));
140      }
141      return from(batch.commit()).pipe(map(() => locationDocRef.id));
142    }));
143  }
144  static {
145    this.\u0275fac = function LocationService_Factory(__ngFactoryType__) {
146      return new (__ngFactoryType__ || _LocationService)(\u0275\u0275inject(AuthenticationService), \u0275\u0275inject(Firestore), \u0275\u0275inject(HttpClient));
147    };
148  }
149  static {
150    this.\u0275prov = /* @__PURE__ */ \u0275\u0275defineInjectable({ token: _LocationService, factory: _LocationService.\u0275fac, providedIn: "root" });
151  }
152};
153(() => {
154  (typeof ngDevMode === "undefined" || ngDevMode) && setClassMetadata(LocationService, [{
155    type: Injectable,
156    args: [{
157      providedIn: "root"
158    }]
159  }], () => [{ type: AuthenticationService }, { type: Firestore }, { type: HttpClient }], null);
160})();
161
162export {
163  LocationService
164};
165/**i18n:55a58011b6fcf12b70aba021cbe233ce2fe179902ce3502a5c6547ccaba0ed7f*/
166//# sourceMappingURL=chunk-O3HWLQEA.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.