fix- staff deletion
This commit is contained in:
@@ -15,7 +15,13 @@ const router = Router();
|
|||||||
|
|
||||||
router.post("/", async (req: Request, res: Response): Promise<any> => {
|
router.post("/", async (req: Request, res: Response): Promise<any> => {
|
||||||
try {
|
try {
|
||||||
const validatedData = staffCreateSchema.parse(req.body);
|
const userId = req.user!.id; // from auth middleware
|
||||||
|
|
||||||
|
const validatedData = staffCreateSchema.parse({
|
||||||
|
...req.body,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
|
||||||
const newStaff = await storage.createStaff(validatedData);
|
const newStaff = await storage.createStaff(validatedData);
|
||||||
res.status(200).json(newStaff);
|
res.status(200).json(newStaff);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const API_BASE_URL = import.meta.env.VITE_API_BASE_URL_BACKEND ?? "";
|
|||||||
|
|
||||||
async function throwIfResNotOk(res: Response) {
|
async function throwIfResNotOk(res: Response) {
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
if (res.status === 401 || res.status === 403) {
|
if (res.status === 401) {
|
||||||
localStorage.removeItem("token");
|
localStorage.removeItem("token");
|
||||||
if (!window.location.pathname.startsWith("/auth")) {
|
if (!window.location.pathname.startsWith("/auth")) {
|
||||||
window.location.href = "/auth";
|
window.location.href = "/auth";
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ model Appointment {
|
|||||||
|
|
||||||
model Staff {
|
model Staff {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
userId Int?
|
userId Int
|
||||||
name String
|
name String
|
||||||
email String?
|
email String?
|
||||||
role String // e.g., "Dentist", "Hygienist", "Assistant"
|
role String // e.g., "Dentist", "Hygienist", "Assistant"
|
||||||
|
|||||||
Reference in New Issue
Block a user