change TTL to seconds in ddb
Some checks failed
Build and push image for doorman-homeassistant / docker (push) Successful in 56s
Build and push image for doorman-homeassistant / deploy-gitainer (push) Successful in 5s
Build and push Doorman UI / API / docker (push) Failing after 2m21s

This commit is contained in:
Martin Dimitrov 2025-10-11 14:39:50 -07:00
parent aba2aed396
commit 594d0ec8cd
3 changed files with 13 additions and 4 deletions

View File

@ -6,5 +6,13 @@ export function isTTLInFuture(item?: { TTL: number }) {
// ttl is a UTC ms time
const ttl = item.TTL || 0;
return parseInt("" + ttl) > Date.now();
return parseInt("" + ttl) > getCurrentTimeInSeconds();
}
export function getCurrentTimeInSeconds(): number {
return Date.now() / 1000;
}
export function getFutureTTLInSeconds(timeInFutureSeconds: number): number {
return getCurrentTimeInSeconds() + timeInFutureSeconds;
}

View File

@ -15,6 +15,7 @@ import { LOG_CALL_SK, LogCallSchema } from "../../../schema/LogCall";
import crypto from "crypto";
import { sanitizePhoneNumber } from "../../../utils/phoneUtils";
import { getFutureTTLInSeconds } from "../../../common/TTLHelper";
export const LogCallRequestSchema = z.object({
caller: z.string(),
@ -71,7 +72,7 @@ export const handler: ServerlessFunctionSignature<TwilioContext, LogCallRequestT
PK: otp,
SK: LOG_CALL_SK,
caller,
TTL: Date.now() + 60 * 60 * 1000, // 60 minutes from now
TTL: getFutureTTLInSeconds(60 * 60), // 60 minutes from now
});
await db.entities.logCall.save(logCall);

View File

@ -1,6 +1,6 @@
import { z } from "zod";
import { DynaBridgeEntity } from 'dynabridge';
import { isTTLInFuture } from "../common/TTLHelper";
import { getFutureTTLInSeconds, isTTLInFuture } from "../common/TTLHelper";
export const LOCK_STATUS_SK = "lock";
@ -32,7 +32,7 @@ export const createLockStatusWithTimeout = (door: string, timeoutSeconds: number
return {
PK: door,
SK: LOCK_STATUS_SK,
TTL: Date.now() + timeoutSeconds * 1000,
TTL: getFutureTTLInSeconds(timeoutSeconds),
fingerprint: JSON.stringify(fingerprint),
};
};