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,7 +35,29 @@ exports.handler = async function(context, event, callback) {
|
|||||||
method: "PIN",
|
method: "PIN",
|
||||||
userAgent: event.request.headers['user-agent'],
|
userAgent: event.request.headers['user-agent'],
|
||||||
};
|
};
|
||||||
const timeout = config.Item.timeout.N;
|
|
||||||
|
// 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))
|
await client.send(ddb.setLockStatusCommand(door, timeout, fingerprint))
|
||||||
.then(async (item) => {
|
.then(async (item) => {
|
||||||
@ -50,6 +72,8 @@ exports.handler = async function(context, event, callback) {
|
|||||||
.appendHeader('Content-Type', 'application/json')
|
.appendHeader('Content-Type', 'application/json')
|
||||||
.setBody({ err: e });
|
.setBody({ err: e });
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
await client.destroy();
|
await client.destroy();
|
||||||
return callback(null, response);
|
return callback(null, response);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user