Chuyển tới nội dung chính

huong-dan-cham-cau-12

id: huong-dan-cham-cau-12 title: Huong dan cham Cau 12 slug: /dap-an/huong-dan-cham-cau-12

Huong dan cham Cau 12

Dap an tham khao:

const updateUserSchema = z
.object({
name: z.string().min(1).max(100).optional(),
phone: z.string().min(8).max(20).optional(),
})
.strict();

async function updateUser(req, res, next) {
try {
const input = updateUserSchema.parse(req.body);

const user = await userRepository.updateById(
req.params.id,
input,
);

if (!user) {
return res.status(404).json({
code: "USER_NOT_FOUND",
message: "User not found",
});
}

return res.status(200).json({
data: user,
});
} catch (error) {
return next(error);
}
}

Ung vien khong bat buoc phai dung Zod. Co the chap nhan Joi, class-validator hoac tu viet validation neu hop ly.

Thang diem

Tieu chiDiem
Co runtime validation3
Chi whitelist name va phone3
Khong cho cap nhat role3
Xu ly dung 4042
Chuyen loi ve middleware tap trung2
Khong tra loi noi bo hoac stack trace2