2023-01-11 21:34:36 -05:00
|
|
|
import { UserEntity } from '@app/infra';
|
2022-11-07 16:53:47 -05:00
|
|
|
|
|
|
|
function createUserUtils() {
|
|
|
|
const isReadyForDeletion = (user: UserEntity): boolean => {
|
|
|
|
if (user.deletedAt == null) return false;
|
|
|
|
const millisecondsInDay = 86400000;
|
|
|
|
// get this number (7 days) from some configuration perhaps ?
|
|
|
|
const millisecondsDeleteWait = millisecondsInDay * 7;
|
|
|
|
|
2022-12-10 18:01:29 -06:00
|
|
|
const millisecondsSinceDelete = new Date().getTime() - (Date.parse(user.deletedAt.toString()) ?? 0);
|
2022-11-07 16:53:47 -05:00
|
|
|
return millisecondsSinceDelete >= millisecondsDeleteWait;
|
|
|
|
};
|
|
|
|
return { isReadyForDeletion };
|
|
|
|
}
|
|
|
|
|
|
|
|
export const userUtils = createUserUtils();
|