Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

667 B
Raw Blame
import { and, eq, isNotNull, isNull, lt, or } from "drizzle-orm";
import { schema } from "../database";

export type BanState = {
  banned?: boolean | null;
  banExpires?: Date | string | null;
};

export function isBanActive(user: BanState | null | undefined) {
  if (!user?.banned) {
    return false;
  }
  if (!user.banExpires) {
    return true;
  }
  return new Date(user.banExpires).getTime() >= Date.now();
}

export function notBannedCondition() {
  return or(
    isNull(schema.userTable.banned),
    eq(schema.userTable.banned, false),
    and(
      isNotNull(schema.userTable.banExpires),
      lt(schema.userTable.banExpires, new Date()),
    ),
  );
}