change homeassistant container to use new ddb
This commit is contained in:
parent
ca2cd5286f
commit
aeefd6f5d3
@ -1,8 +1,10 @@
|
||||
import { serve } from "bun";
|
||||
import { Hono } from "hono";
|
||||
import { prettyJSON } from "hono/pretty-json";
|
||||
import { createDDBClient, getDoorConfigCommand, getLockStatusCommand, isLockOpen } from "../../doorman-api/src/utils/ddb";
|
||||
import { createDynaBridgeClient } from "../../doorman-api/src/utils/ddb";
|
||||
import { DoorStatus } from "../../doorman-api/src/types/DoorStatus";
|
||||
import { getLockStatusID, isLockOpen } from "../../doorman-api/src/schema/LockStatus";
|
||||
import { getDoorConfigID } from "../../doorman-api/src/schema/DoorConfig";
|
||||
|
||||
const app = new Hono();
|
||||
|
||||
@ -15,28 +17,23 @@ app.get("/api/door/info", async (c) => {
|
||||
err: "Must specify a door",
|
||||
}, 400);
|
||||
}
|
||||
|
||||
const db = createDynaBridgeClient(Bun.env as any);
|
||||
|
||||
const client = createDDBClient(Bun.env as any);
|
||||
const config = await client.send(getDoorConfigCommand(door));
|
||||
const config = await db.entities.doorConfig.findById(getDoorConfigID(door));
|
||||
|
||||
if (!config.Item) {
|
||||
if (!config) {
|
||||
return c.json({
|
||||
err: "This buzzer is not registered properly",
|
||||
}, 404);
|
||||
}
|
||||
return await client.send(getLockStatusCommand(door))
|
||||
.then(async (lock) => {
|
||||
const status = isLockOpen(lock) ? DoorStatus.OPEN: "CLOSED";
|
||||
return c.json({
|
||||
id: door,
|
||||
status,
|
||||
});
|
||||
}).catch((e) => {
|
||||
console.log(e);
|
||||
return c.json({
|
||||
err: e,
|
||||
}, 500);
|
||||
});
|
||||
|
||||
const lock = await db.entities.lockStatus.findById(getLockStatusID(door));
|
||||
const status = isLockOpen(lock) ? DoorStatus.OPEN: "CLOSED";
|
||||
return c.json({
|
||||
id: door,
|
||||
status,
|
||||
});
|
||||
});
|
||||
|
||||
serve({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user