This repository has been archived by the owner on Nov 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lobby-example.js
133 lines (112 loc) · 5.01 KB
/
lobby-example.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const Visitor = require('../dist/lib/model/lobby/Visitor');
require('dotenv').config();
var SAMApi = require('../dist/index').SAMApi;
var ListPersonLookupIn = require('../dist/index').ListPersonLookupIn;
var LobbyCredentialTechnologiesIn = require('../dist/index').LobbyCredentialTechnologiesIn;
var CardTechnology = require('../dist/index').CardTechnology;
var CreatePersonProvisoryCredential = require('../dist/index').CreatePersonProvisoryCredential;
var CreateVisitorProvisoryCredential = require('../dist/index').CreateVisitorProvisoryCredential;
var InformationCardCredentialRecord = require('../dist/index').InformationCardCredentialRecord;
var username = process.env.SENIOR_USERNAME;
var password = process.env.PASS;
var personId = process.env.PERSON_ID;
var lobbyId = process.env.LOBBY_ID;
var roleId = process.env.ROLE_ID;
var visitor = new Visitor(process.env.VISITOR_ID);
var schedulingId = process.env.SCHEDULING_ID;
if(username == undefined) {
console.error("É necessário um nome de usuário");
}
if(password == undefined) {
console.error("É necessário uma senha de usuário");
}
if(personId == undefined) {
console.error("O identificador da pessoa que receberá a credencial, cadastro em sam-aplicacao-backend/entities/person");
}
if(lobbyId == undefined){
console.error("O identificador da portaria, cadastro pela entidade lobby");
}
if (roleId == undefined) {
console.error("O papel da credencial que o visitante vai assumir, usado principalmente para visitantes sem cadastro prévio, cadastro em sam-aplicacao-backend/entities/role");
}
if (visitor == undefined) {
console.error("O visitante que receberá a credencial");
}
if (schedulingId == undefined) {
console.error("O agendamento relacionado à credencial, id da entidade scheduling, apenas para visitas agendadas");
}
var samApi = new SAMApi();
samApi.environment = "DEV";
var listPersonLookupIn = new ListPersonLookupIn();
var lobbyCredentialTechnologiesIn = new LobbyCredentialTechnologiesIn();
var createPersonProvisoryCredential;
var createVisitorProvisoryCredential;
samApi.authentication.login({username, password}).then(function (json) {
samApi.accessToken = JSON.parse(json.body.jsonToken).access_token;
listPersonLookupIn.searchText = 'Teste Versao';
samApi.lobby.listPersonLookup(listPersonLookupIn).then(function (json) {
if (json.statusCode != 200) {
console.error(json);
} else {
console.log(json.body);
}
}).catch(function (error) {
console.error("Erro na tentativa de listar dependente: ", error);
});
const parentId = 1;
lobbyCredentialTechnologiesIn.cardTechnology = CardTechnology.BARCODE_CARD;
samApi.lobby.lobbyCredentialTechnologies(parentId, lobbyCredentialTechnologiesIn).then(function (json) {
if (json.statusCode != 200) {
console.error(json);
} else {
console.log(json.body);
}
}).catch(function (error) {
console.error("Erro na tentativa de listar dependente: ", error);
});
var endDate = adicionarDiasData(1);
informationCardCredentialRecord = new InformationCardCredentialRecord(CardTechnology.SMART_CARD, 7);
createPersonProvisoryCredential =
new CreatePersonProvisoryCredential(true,[informationCardCredentialRecord], endDate, personId, lobbyId);
samApi.lobby.createPersonProvisoryCredentialCard(createPersonProvisoryCredential).then(function (json) {
if (json.statusCode != 200) {
console.error(json);
} else {
console.log(json.body);
}
}).catch(function (error) {
console.error("Erro na tentativa de listar dependente: ", error);
});
createVisitorProvisoryCredential =
new CreateVisitorProvisoryCredential(false, [informationCardCredentialRecord], endDate, roleId, visitor, schedulingId);
samApi.lobby.createVisitorProvisoryCredentialCard(createVisitorProvisoryCredential).then(function (json) {
if (json.statusCode != 200) {
console.error(json);
} else {
console.log(json.body);
}
}).catch(function (error) {
console.error("Erro na tentativa de criar credencial provisória: ", error);
});
samApi.lobby.getCredentials(personId, listPersonLookupIn).then(function (json) {
if (json.statusCode != 200) {
console.error(json);
} else {
console.log(json.body);
}
}).catch(function (error) {
console.error("Erro na tentativa de listar credenciais: ", error);
});
if (samApi.accessToken) {
samApi.authentication.logout().catch(function (error) {
console.error("Erro na tentativa de efetuar logout: ", error);
});
}
}).catch(function (error) {
console.error('ENV: ' + samApi.environment);
console.error("Erro na tentativa de efetuar login: ", error);
});
function adicionarDiasData(dias){
var hoje = new Date();
return new Date(hoje.getTime() + (dias * 24 * 60 * 60 * 1000));
}