chore: eslint
This commit is contained in:
parent
6cb6eb503b
commit
7045e582c7
6 changed files with 43 additions and 21 deletions
|
|
@ -18,9 +18,11 @@ router.get("/", async (req, res) => {
|
||||||
|
|
||||||
const result = await getProducts(page, limit);
|
const result = await getProducts(page, limit);
|
||||||
res.status(200).json(result);
|
res.status(200).json(result);
|
||||||
} catch (e: any) {
|
} catch (e: unknown) {
|
||||||
console.log("Error fetching products:", e);
|
console.log("Error fetching products:", e);
|
||||||
res.status(500).json({ error: e.message });
|
res.status(500).json({
|
||||||
|
error: e instanceof Error ? e.message : "Unknown error",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -30,9 +32,11 @@ router.post("/", async (req, res) => {
|
||||||
const { name, price, description } = req.body;
|
const { name, price, description } = req.body;
|
||||||
await createProduct({ name, price, description });
|
await createProduct({ name, price, description });
|
||||||
res.status(201).json({ ok: true });
|
res.status(201).json({ ok: true });
|
||||||
} catch (e: any) {
|
} catch (e: unknown) {
|
||||||
console.error("Error creating product:", e);
|
console.error("Error creating product:", e);
|
||||||
res.status(500).json({ error: e.message });
|
res.status(500).json({
|
||||||
|
error: e instanceof Error ? e.message : "Unknown error",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,11 @@ router.get("/", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const users = await getUsers();
|
const users = await getUsers();
|
||||||
res.json(users);
|
res.json(users);
|
||||||
} catch (error: any) {
|
} catch (error: unknown) {
|
||||||
console.error("Error fetching users:", error);
|
console.error("Error fetching users:", error);
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
error: "Failed to fetch users",
|
error: "Failed to fetch users",
|
||||||
message: error.message,
|
message: error instanceof Error ? error.message : "Unknown error",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -21,7 +21,7 @@ router.get("/", async (req, res) => {
|
||||||
// POST /api/users - Create new user
|
// POST /api/users - Create new user
|
||||||
router.post("/", async (req, res) => {
|
router.post("/", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { name, email, password, role, isActive } = req.body;
|
const { name, email, password, role } = req.body;
|
||||||
|
|
||||||
// Validation
|
// Validation
|
||||||
if (!name || !email || !password) {
|
if (!name || !email || !password) {
|
||||||
|
|
@ -60,17 +60,21 @@ router.post("/", async (req, res) => {
|
||||||
const newUser = await createUser(userData);
|
const newUser = await createUser(userData);
|
||||||
|
|
||||||
res.status(201).json(newUser);
|
res.status(201).json(newUser);
|
||||||
} catch (error: any) {
|
} catch (error: unknown) {
|
||||||
console.error("Error creating user:", error);
|
console.error("Error creating user:", error);
|
||||||
|
|
||||||
// Handle unique constraint violation (duplicate email)
|
// Handle unique constraint violation (duplicate email)
|
||||||
if (error.message?.includes("duplicate") || error.code === "23505") {
|
if (
|
||||||
|
error instanceof Error &&
|
||||||
|
(error.message?.includes("duplicate") ||
|
||||||
|
(error as any).code === "23505")
|
||||||
|
) {
|
||||||
return res.status(409).json({ error: "Email already exists" });
|
return res.status(409).json({ error: "Email already exists" });
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
error: "Failed to create user",
|
error: "Failed to create user",
|
||||||
message: error.message,
|
message: error instanceof Error ? error.message : "Unknown error",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,8 @@ const ProductIndex: React.FC = () => {
|
||||||
const result = await fetchProducts(page);
|
const result = await fetchProducts(page);
|
||||||
setPaginatedProducts(result);
|
setPaginatedProducts(result);
|
||||||
setError(null);
|
setError(null);
|
||||||
} catch (err: any) {
|
} catch (err: unknown) {
|
||||||
setError(err.message);
|
setError(err instanceof Error ? err.message : "An error occurred");
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
|
@ -90,9 +90,11 @@ const ProductIndex: React.FC = () => {
|
||||||
|
|
||||||
// Refresh current page
|
// Refresh current page
|
||||||
loadProducts(paginatedProducts.pagination.page);
|
loadProducts(paginatedProducts.pagination.page);
|
||||||
} catch (err: any) {
|
} catch (err: unknown) {
|
||||||
console.error("Delete error:", err.message);
|
const errorMessage =
|
||||||
alert("Failed to delete product: " + err.message);
|
err instanceof Error ? err.message : "An error occurred";
|
||||||
|
console.error("Delete error:", errorMessage);
|
||||||
|
alert("Failed to delete product: " + errorMessage);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ dotenv.config({ path: ".env" });
|
||||||
let db_url = process.env.DATABASE_URL!;
|
let db_url = process.env.DATABASE_URL!;
|
||||||
try {
|
try {
|
||||||
db_url = decodeURI(db_url);
|
db_url = decodeURI(db_url);
|
||||||
} catch (e) {
|
} catch {
|
||||||
console.warn("Failed to decode DATABASE_URL, using as is.");
|
console.warn("Failed to decode DATABASE_URL, using as is.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ export interface FormField {
|
||||||
|
|
||||||
// Generic form data interface
|
// Generic form data interface
|
||||||
export interface FormData {
|
export interface FormData {
|
||||||
[key: string]: any;
|
[key: string]: string | number | boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CreateFormProps {
|
interface CreateFormProps {
|
||||||
|
|
@ -78,7 +78,10 @@ export function CreateForm({
|
||||||
const [errors, setErrors] = useState<Record<string, string>>({});
|
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
|
||||||
const validateField = (field: FormField, value: any): string | null => {
|
const validateField = (
|
||||||
|
field: FormField,
|
||||||
|
value: string | number | boolean
|
||||||
|
): string | null => {
|
||||||
if (
|
if (
|
||||||
field.required &&
|
field.required &&
|
||||||
(!value || (typeof value === "string" && !value.trim()))
|
(!value || (typeof value === "string" && !value.trim()))
|
||||||
|
|
@ -129,7 +132,10 @@ export function CreateForm({
|
||||||
return Object.keys(newErrors).length === 0;
|
return Object.keys(newErrors).length === 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleInputChange = (key: string, value: any) => {
|
const handleInputChange = (
|
||||||
|
key: string,
|
||||||
|
value: string | number | boolean
|
||||||
|
) => {
|
||||||
setFormData((prev) => ({ ...prev, [key]: value }));
|
setFormData((prev) => ({ ...prev, [key]: value }));
|
||||||
|
|
||||||
// Clear error when user starts typing
|
// Clear error when user starts typing
|
||||||
|
|
@ -161,8 +167,13 @@ export function CreateForm({
|
||||||
});
|
});
|
||||||
setFormData(resetData);
|
setFormData(resetData);
|
||||||
setErrors({});
|
setErrors({});
|
||||||
} catch (error: any) {
|
} catch (error: unknown) {
|
||||||
setErrors({ submit: error.message || "An error occurred" });
|
setErrors({
|
||||||
|
submit:
|
||||||
|
error instanceof Error
|
||||||
|
? error.message
|
||||||
|
: "An error occurred",
|
||||||
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setIsSubmitting(false);
|
setIsSubmitting(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"$schema": "https://turborepo.com/schema.json",
|
"$schema": "https://turborepo.com/schema.json",
|
||||||
"ui": "tui",
|
"ui": "tui",
|
||||||
|
"globalEnv": ["DATABASE_URL"],
|
||||||
"tasks": {
|
"tasks": {
|
||||||
"build": {
|
"build": {
|
||||||
"inputs": ["$TURBO_DEFAULT$", ".env*"],
|
"inputs": ["$TURBO_DEFAULT$", ".env*"],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue