change TTL to seconds in ddb
This commit is contained in:
parent
aba2aed396
commit
594d0ec8cd
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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),
|
||||
};
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user