-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsucursalprovider-memory.js
executable file
·48 lines (36 loc) · 1.17 KB
/
sucursalprovider-memory.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
var sucursalCounter = 1;
SucursalProvider = function(){};
SucursalProvider.prototype.dummyData = [];
SucursalProvider.prototype.findAll = function(callback){
callback(null, this.dummyData);
};
SucursalProvider.prototype.findById = function(id, callback){
var result = null;
for(var i = 0; i < this.dummyData.length; i++){
if(this.dummyData[i]._id == id){
retult = this.dummyData[i];
break;
}
}
callback(null, result);
};
SucursalProvider.prototype.save = function(sucursales, callback){
var sucursal = null;
if(typeof(sucursales.length) == "undefined")
sucursales = [sucursales];
for(var i = 0; i < sucursales.length; i++){
sucursal = sucursales[i];
sucursal._id = sucursalCounter++;
sucursal.created_at = new Date();
this.dummyData[this.dummyData.length] = sucursal;
}
callback(null, sucursales);
};
new SucursalProvider().save([
{numero: 1, direccion: 'Calle real'},
{numero: 2, direccion: 'Censos'},
{numero: 3, direccion: 'Ciudad mendoza'},
{numero: 4, direccion: 'Ixtazoquitlan'},
{numero: 5, direccion: 'Cordoba'}
], function(error, sucursales){});
exports.SucursalProvider = SucursalProvider;