-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddressBookBusinessLogic.js
51 lines (46 loc) · 1.47 KB
/
AddressBookBusinessLogic.js
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
44
45
46
47
48
49
50
51
/**
* Created by rafal on 04.01.2017.
*/
var AddressBook = require('./AddressBook.js');
var AddressBookBusinessLogic = function () {
this.addressBook = new AddressBook();
};
AddressBookBusinessLogic.prototype.saveElement = function (elem) {
if (typeof(elem.id) !== 'undefined') {
if (typeof(elem.id) === 'number' && elem.id >= 0 && this.addressBook.getItem(elem.id) !== null) {
return this.addressBook.updateItem(elem);
}
else {
return null;
}
}
else {
if (typeof(elem.name) !== 'undefined' && elem.name.length > 0) {
return this.addressBook.addItem(elem);
}
else {
return null;
}
}
};
AddressBookBusinessLogic.prototype.getElement = function (elemId) {
if (typeof(elemId) === 'number' && elemId >= 0) {
return this.addressBook.getItem(elemId);
}
return null;
};
AddressBookBusinessLogic.prototype.getElements = function (elemName) {
if (typeof(elemName) === "string" && elemName.length > 0) {
return this.addressBook.getItemsByName(elemName);
}
else {
return this.addressBook.getItems();
}
};
AddressBookBusinessLogic.prototype.deteleElement = function (elemId) {
if (typeof(elemId) !== 'undefined' && typeof(elemId) === 'number' && elemId >= 0 && this.addressBook.getItem(elemId) !== null) {
return this.addressBook.deleteItem(elemId);
}
return null;
};
module.exports = AddressBookBusinessLogic;