Update ESLint configuration and schemas to use Zod library

- Changed ESLint configuration to target TypeScript files and added parser options for better integration.
- Updated various schemas across the application to replace `nestjs-zod/z` imports with `zod` for consistency.
- Refactored password validation in authentication schemas to use `z.string()` instead of `z.password()`.
- Enhanced date handling in user and resume schemas by introducing a new `dateSchema` utility.
- Updated `.ncurc.json` to target minor upgrades for dependencies.
This commit is contained in:
Amruth Pillai
2025-01-12 17:34:45 +01:00
parent 6fb0a72a56
commit 0053d696ff
28 changed files with 103 additions and 41 deletions

View File

@ -12,6 +12,7 @@
"@reactive-resume/utils": "*",
"@reactive-resume/schema": "*",
"nestjs-zod": "^3.0.0",
"@swc/helpers": "~0.5.11"
"@swc/helpers": "~0.5.11",
"zod": "^3.24.1"
}
}

View File

@ -1,5 +1,5 @@
import { createZodDto } from "nestjs-zod/dto";
import { z } from "nestjs-zod/z";
import { z } from "zod";
export const forgotPasswordSchema = z.object({ email: z.string().email() });

View File

@ -1,12 +1,12 @@
import { createZodDto } from "nestjs-zod/dto";
import { z } from "nestjs-zod/z";
import { z } from "zod";
import { usernameSchema } from "../user";
export const loginSchema = z
.object({
identifier: z.string().transform((value) => value.toLowerCase()),
password: z.password().min(6),
password: z.string().min(6),
})
.refine(
(value) => {

View File

@ -1,5 +1,5 @@
import { createZodDto } from "nestjs-zod/dto";
import { z } from "nestjs-zod/z";
import { z } from "zod";
export const messageSchema = z.object({ message: z.string() });

View File

@ -1,5 +1,5 @@
import { createZodDto } from "nestjs-zod/dto";
import { z } from "nestjs-zod/z";
import { z } from "zod";
const authProvidersSchema = z.array(z.enum(["email", "github", "google"]));

View File

@ -1,10 +1,10 @@
import { createZodDto } from "nestjs-zod/dto";
import { z } from "nestjs-zod/z";
import { z } from "zod";
import { userSchema } from "../user";
export const registerSchema = userSchema
.pick({ name: true, email: true, username: true, locale: true })
.extend({ password: z.password().min(6) });
.extend({ password: z.string().min(6) });
export class RegisterDto extends createZodDto(registerSchema) {}

View File

@ -1,9 +1,9 @@
import { createZodDto } from "nestjs-zod/dto";
import { z } from "nestjs-zod/z";
import { z } from "zod";
export const resetPasswordSchema = z.object({
token: z.string(),
password: z.password().min(6),
password: z.string().min(6),
});
export class ResetPasswordDto extends createZodDto(resetPasswordSchema) {}

View File

@ -1,5 +1,5 @@
import { createZodDto } from "nestjs-zod/dto";
import { z } from "nestjs-zod/z";
import { z } from "zod";
import { userSchema } from "../user";

View File

@ -1,5 +1,5 @@
import { createZodDto } from "nestjs-zod/dto";
import { z } from "nestjs-zod/z";
import { z } from "zod";
export const twoFactorSchema = z.object({
code: z

View File

@ -1,5 +1,5 @@
import { createZodDto } from "nestjs-zod/dto";
import { z } from "nestjs-zod/z";
import { z } from "zod";
export const updatePasswordSchema = z.object({
password: z.string().min(6),

View File

@ -1,5 +1,5 @@
import { createZodDto } from "nestjs-zod/dto";
import { z } from "nestjs-zod/z";
import { z } from "zod";
export const contributorSchema = z.object({
id: z.number(),

View File

@ -1,5 +1,5 @@
import { createZodDto } from "nestjs-zod/dto";
import { z } from "nestjs-zod/z";
import { z } from "zod";
export const featureSchema = z.object({
isSignupsDisabled: z.boolean().default(false),

View File

@ -1,6 +1,6 @@
import { kebabCase } from "@reactive-resume/utils";
import { createZodDto } from "nestjs-zod/dto";
import { z } from "nestjs-zod/z";
import { z } from "zod";
export const createResumeSchema = z.object({
title: z.string().min(1),

View File

@ -1,6 +1,6 @@
import { idSchema } from "@reactive-resume/schema";
import { createZodDto } from "nestjs-zod/dto";
import { z } from "nestjs-zod/z";
import { z } from "zod";
export const deleteResumeSchema = z.object({
id: idSchema,

View File

@ -1,7 +1,7 @@
import { resumeDataSchema } from "@reactive-resume/schema";
import { kebabCase } from "@reactive-resume/utils";
import { createZodDto } from "nestjs-zod/dto";
import { z } from "nestjs-zod/z";
import { z } from "zod";
export const importResumeSchema = z.object({
title: z.string().optional(),

View File

@ -1,6 +1,7 @@
import { defaultResumeData, idSchema, resumeDataSchema } from "@reactive-resume/schema";
import { dateSchema } from "@reactive-resume/utils";
import { createZodDto } from "nestjs-zod/dto";
import { z } from "nestjs-zod/z";
import { z } from "zod";
import { userSchema } from "../user";
@ -13,8 +14,8 @@ export const resumeSchema = z.object({
locked: z.boolean().default(false),
userId: idSchema,
user: userSchema.optional(),
createdAt: z.date().or(z.dateString()),
updatedAt: z.date().or(z.dateString()),
createdAt: dateSchema,
updatedAt: dateSchema,
});
export class ResumeDto extends createZodDto(resumeSchema) {}

View File

@ -1,5 +1,5 @@
import { createZodDto } from "nestjs-zod/dto";
import { z } from "nestjs-zod/z";
import { z } from "zod";
export const urlSchema = z.object({ url: z.string().url() });

View File

@ -1,5 +1,5 @@
import { idSchema } from "@reactive-resume/schema";
import { z } from "nestjs-zod/z";
import { z } from "zod";
export const secretsSchema = z.object({
id: idSchema,

View File

@ -1,5 +1,5 @@
import { createZodDto } from "nestjs-zod/dto";
import { z } from "nestjs-zod/z";
import { z } from "zod";
export const statisticsSchema = z.object({
views: z.number().int().default(0),

View File

@ -1,6 +1,7 @@
import { idSchema } from "@reactive-resume/schema";
import { dateSchema } from "@reactive-resume/utils";
import { createZodDto } from "nestjs-zod/dto";
import { z } from "nestjs-zod/z";
import { z } from "zod";
import { secretsSchema } from "../secrets";
@ -26,8 +27,8 @@ export const userSchema = z.object({
emailVerified: z.boolean().default(false),
twoFactorEnabled: z.boolean().default(false),
provider: z.enum(["email", "github", "google"]).default("email"),
createdAt: z.date().or(z.dateString()),
updatedAt: z.date().or(z.dateString()),
createdAt: dateSchema,
updatedAt: dateSchema,
});
export class UserDto extends createZodDto(userSchema) {}

View File

@ -14,6 +14,7 @@
"unique-names-generator": "^4.7.1",
"clsx": "^2.1.1",
"tailwind-merge": "^2.3.0",
"@swc/helpers": "~0.5.11"
"@swc/helpers": "~0.5.11",
"zod": "^3.24.1"
}
}

View File

@ -1,4 +1,10 @@
import dayjs from "dayjs";
import { z } from "zod";
export const dateSchema = z.union([z.date(), z.string().datetime()]).transform((value) => {
if (typeof value === "string") return dayjs(value).toDate();
return value;
});
export const sortByDate = <T>(a: T, b: T, key: keyof T, desc = true) => {
if (!a[key] || !b[key]) return 0;