toggle on auth api also take timeout from query params
Some checks failed
Build and push image for doorman / docker (push) Failing after 2m45s
Some checks failed
Build and push image for doorman / docker (push) Failing after 2m45s
This commit is contained in:
parent
fdb70a9703
commit
0bac206bdd
@ -35,21 +35,45 @@ exports.handler = async function(context, event, callback) {
|
||||
method: "PIN",
|
||||
userAgent: event.request.headers['user-agent'],
|
||||
};
|
||||
const timeout = config.Item.timeout.N;
|
||||
|
||||
await client.send(ddb.setLockStatusCommand(door, timeout, fingerprint))
|
||||
.then(async (item) => {
|
||||
response
|
||||
.setStatusCode(200)
|
||||
.appendHeader('Content-Type', 'application/json')
|
||||
.setBody({ msg: `Opened the door "${door}" for ${timeout}s` });
|
||||
}).catch((e) => {
|
||||
console.log(e);
|
||||
response
|
||||
.setStatusCode(500)
|
||||
.appendHeader('Content-Type', 'application/json')
|
||||
.setBody({ err: e });
|
||||
// take timeout from the query string
|
||||
const timeout = event.timeout ? parseInt(event.timeout) : config.Item.timeout.N;
|
||||
|
||||
// check lock status if locked, then unlock. If unlocked then lock
|
||||
await client.send(ddb.getLockStatusCommand(door))
|
||||
.then(async (lock) => {
|
||||
const isOpen = ddb.isLockOpen(lock);
|
||||
|
||||
if (isOpen) {
|
||||
const fingerprint = JSON.parse(lock.Item.fingerprint.S);
|
||||
|
||||
response
|
||||
.setStatusCode(200)
|
||||
.appendHeader('Content-Type', 'application/json')
|
||||
.setBody({
|
||||
status: "CLOSED",
|
||||
fingerprint,
|
||||
});
|
||||
|
||||
await client.send(ddb.clearLockStatusCommand(lock));
|
||||
return;
|
||||
}
|
||||
|
||||
await client.send(ddb.setLockStatusCommand(door, timeout, fingerprint))
|
||||
.then(async (item) => {
|
||||
response
|
||||
.setStatusCode(200)
|
||||
.appendHeader('Content-Type', 'application/json')
|
||||
.setBody({ msg: `Opened the door "${door}" for ${timeout}s` });
|
||||
}).catch((e) => {
|
||||
console.log(e);
|
||||
response
|
||||
.setStatusCode(500)
|
||||
.appendHeader('Content-Type', 'application/json')
|
||||
.setBody({ err: e });
|
||||
});
|
||||
});
|
||||
|
||||
await client.destroy();
|
||||
return callback(null, response);
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user