import { expire_time } from "@cocalc/util/misc";
import { PostgreSQL } from "./types";
import { get_server_settings } from "./server-settings";
export function pii_retention_to_future<T extends object>(
pii_retention: number | false,
data?: T & { expire?: Date }
): Date | undefined {
if (!pii_retention) return;
const future: Date = expire_time(pii_retention);
if (data != null) {
data.expire = future;
}
return future;
}
export async function pii_expire<T extends object>(
db: PostgreSQL,
data?: T & { expire?: Date }
): Promise<Date | undefined> {
const settings = await get_server_settings(db);
return pii_retention_to_future<T>(settings.pii_retention, data);
}