updateProductSchema added
This commit is contained in:
@@ -19,3 +19,7 @@ export const createProductSchema = createInsertSchema(productsTable).omit({
|
|||||||
id: true,
|
id: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const updateProductSchema = createUpdateSchema(productsTable).omit({
|
||||||
|
id: true,
|
||||||
|
})
|
||||||
|
.partial();
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { listProducts,
|
|||||||
} from "./productsController";
|
} from "./productsController";
|
||||||
import { validateData } from "../../middlewares/validationMiddleware";
|
import { validateData } from "../../middlewares/validationMiddleware";
|
||||||
import { z, ZodObject, ZodTypeAny } from 'zod/v4';
|
import { z, ZodObject, ZodTypeAny } from 'zod/v4';
|
||||||
import { productsTable, createProductSchema } from "../../db/productsSchema";
|
import { productsTable, createProductSchema, updateProductSchema } from "../../db/productsSchema";
|
||||||
|
|
||||||
|
|
||||||
type ProductType = z.infer<typeof createProductSchema>;
|
type ProductType = z.infer<typeof createProductSchema>;
|
||||||
@@ -18,7 +18,7 @@ const router = Router();
|
|||||||
router.get('/', listProducts);
|
router.get('/', listProducts);
|
||||||
router.get('/:id', getProductById);
|
router.get('/:id', getProductById);
|
||||||
router.post('/', validateData(createProductSchema), createProduct);
|
router.post('/', validateData(createProductSchema), createProduct);
|
||||||
router.put('/:id', updateProduct);
|
router.put('/:id', validateData(updateProductSchema), updateProduct);
|
||||||
router.delete('/:id', deleteProduct);
|
router.delete('/:id', deleteProduct);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
@@ -52,7 +52,7 @@ export async function createProduct(req: Request, res: Response) {
|
|||||||
export async function updateProduct(req: Request, res: Response) {
|
export async function updateProduct(req: Request, res: Response) {
|
||||||
try{
|
try{
|
||||||
const id = Number(req.params.id);
|
const id = Number(req.params.id);
|
||||||
const updatedFields = req.body;
|
const updatedFields = req.cleanBody;
|
||||||
|
|
||||||
const result = await db
|
const result = await db
|
||||||
.update(productsTable)
|
.update(productsTable)
|
||||||
|
|||||||
Reference in New Issue
Block a user