-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1_PlacesService.gs
43 lines (39 loc) · 906 Bytes
/
1_PlacesService.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const PLACES_RANGE_NAME = "Places";
class Place {
/**
* @param {string} code
* @param {string} address
* @param {string} room
*/
constructor(code, address, room) {
this.code = code;
this.address = address;
this.room = room;
}
}
class PlacesService {
constructor(app) {
this.placesSheet = app.sheet.getRangeByName(PLACES_RANGE_NAME);
this.places = null;
}
getPlaces() {
if (this.places === null) {
/**
* @type {Place[]}
*/
this.places = [];
const data = this.placesSheet.getValues();
data.forEach(row => {
if (row.length >= 3) {
this.places.push(new Place(row[0], row[1], row[2]));
}
});
}
return this.places;
}
getByAddressAndRoomNumber(address, room) {
return this.getPlaces().find(function (p) {
return p.address === address && p.room === room;
}) || null;
}
}