'use server';
import { Project } from "@/models";
import { ActionResult } from "../../ActionResult";
import { Attributes } from "@sequelize/core";
import { userIsAdmin } from "../../actions";

export async function getProjects(): Promise<ActionResult<Attributes<Project>[]>> {
  if (! await userIsAdmin()) return { error: 'Unauthorized, not fetching Projects' }
  const posts = await Project.findAll();
  return { result: JSON.parse(JSON.stringify(posts)) };
}
