feat(staff column order in aptmpt page)
This commit is contained in:
@@ -1,15 +1,12 @@
|
||||
import { Router } from "express";
|
||||
import type { Request, Response } from "express";
|
||||
import { storage } from "../storage";
|
||||
import { z } from "zod";
|
||||
import { StaffUncheckedCreateInputObjectSchema } from "@repo/db/usedSchemas";
|
||||
|
||||
type Staff = z.infer<typeof StaffUncheckedCreateInputObjectSchema>;
|
||||
|
||||
const staffCreateSchema = StaffUncheckedCreateInputObjectSchema;
|
||||
const staffUpdateSchema = (
|
||||
StaffUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
|
||||
).partial();
|
||||
import {
|
||||
StaffCreateBody,
|
||||
StaffCreateInput,
|
||||
staffCreateSchema,
|
||||
staffUpdateSchema,
|
||||
} from "@repo/db/types";
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -17,12 +14,14 @@ router.post("/", async (req: Request, res: Response): Promise<any> => {
|
||||
try {
|
||||
const userId = req.user!.id; // from auth middleware
|
||||
|
||||
const validatedData = staffCreateSchema.parse({
|
||||
...req.body,
|
||||
const body = staffCreateSchema.parse(req.body) as StaffCreateBody;
|
||||
|
||||
const data: StaffCreateInput = {
|
||||
...body,
|
||||
userId,
|
||||
});
|
||||
|
||||
const newStaff = await storage.createStaff(validatedData);
|
||||
};
|
||||
|
||||
const newStaff = await storage.createStaff(data);
|
||||
res.status(200).json(newStaff);
|
||||
} catch (error) {
|
||||
console.error("Failed to create staff:", error);
|
||||
@@ -52,12 +51,17 @@ router.put("/:id", async (req: Request, res: Response): Promise<any> => {
|
||||
const validatedData = staffUpdateSchema.parse(req.body);
|
||||
const updatedStaff = await storage.updateStaff(
|
||||
parsedStaffId,
|
||||
validatedData
|
||||
validatedData,
|
||||
);
|
||||
if (!updatedStaff) return res.status(404).send("Staff not found");
|
||||
|
||||
res.json(updatedStaff);
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
if (error.message?.includes("displayOrder")) {
|
||||
return res.status(400).json({
|
||||
message: error.message,
|
||||
});
|
||||
}
|
||||
console.error("Failed to update staff:", error);
|
||||
res.status(500).send("Failed to update staff");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user