fix: open-api doc generation failing, post patch and delete not exported (#1565)
This commit is contained in:
@@ -503,7 +503,7 @@ export const userRouter = createTRPCRouter({
|
||||
}),
|
||||
});
|
||||
|
||||
const createUserAsync = async (db: Database, input: z.infer<typeof validation.user.baseCreate>) => {
|
||||
const createUserAsync = async (db: Database, input: Omit<z.infer<typeof validation.user.baseCreate>, "groupIds">) => {
|
||||
const salt = await createSaltAsync();
|
||||
const hashedPassword = await hashPasswordAsync(input.password, salt);
|
||||
|
||||
|
||||
16
packages/api/src/test/open-api.spec.ts
Normal file
16
packages/api/src/test/open-api.spec.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { expect, test, vi } from "vitest";
|
||||
|
||||
import { openApiDocument } from "../open-api";
|
||||
|
||||
vi.mock("@homarr/auth", () => ({}));
|
||||
|
||||
test("OpenAPI documentation should be generated", () => {
|
||||
// Arrange
|
||||
const base = "https://homarr.dev";
|
||||
|
||||
// Act
|
||||
const act = () => openApiDocument(base);
|
||||
|
||||
// Assert
|
||||
expect(act).not.toThrow();
|
||||
});
|
||||
@@ -37,43 +37,43 @@ const passwordSchema = z
|
||||
},
|
||||
);
|
||||
|
||||
const confirmPasswordRefine = [
|
||||
(data: { password: string; confirmPassword: string }) => data.password === data.confirmPassword,
|
||||
{
|
||||
const addConfirmPasswordRefinement = <TObj extends { password: string; confirmPassword: string }>(
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
schema: z.ZodObject<any, "strip", z.ZodTypeAny, TObj>,
|
||||
) => {
|
||||
return schema.refine((data) => data.password === data.confirmPassword, {
|
||||
path: ["confirmPassword"],
|
||||
params: createCustomErrorParams({
|
||||
key: "passwordsDoNotMatch",
|
||||
params: {},
|
||||
}),
|
||||
},
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
] satisfies [(args: any) => boolean, unknown];
|
||||
});
|
||||
};
|
||||
|
||||
const baseCreateUserSchema = z
|
||||
.object({
|
||||
username: usernameSchema,
|
||||
password: passwordSchema,
|
||||
confirmPassword: z.string(),
|
||||
email: z.string().email().or(z.string().length(0).optional()),
|
||||
})
|
||||
.refine(confirmPasswordRefine[0], confirmPasswordRefine[1]);
|
||||
const baseCreateUserSchema = z.object({
|
||||
username: usernameSchema,
|
||||
password: passwordSchema,
|
||||
confirmPassword: z.string(),
|
||||
email: z.string().email().or(z.string().length(0).optional()),
|
||||
groupIds: z.array(z.string()),
|
||||
});
|
||||
|
||||
const createUserSchema = baseCreateUserSchema.and(z.object({ groupIds: z.array(z.string()) }));
|
||||
const createUserSchema = addConfirmPasswordRefinement(baseCreateUserSchema);
|
||||
|
||||
const initUserSchema = baseCreateUserSchema;
|
||||
const initUserSchema = addConfirmPasswordRefinement(baseCreateUserSchema.omit({ groupIds: true }));
|
||||
|
||||
const signInSchema = z.object({
|
||||
name: z.string().min(1),
|
||||
password: z.string().min(1),
|
||||
});
|
||||
|
||||
const registrationSchema = z
|
||||
.object({
|
||||
const registrationSchema = addConfirmPasswordRefinement(
|
||||
z.object({
|
||||
username: usernameSchema,
|
||||
password: passwordSchema,
|
||||
confirmPassword: z.string(),
|
||||
})
|
||||
.refine(confirmPasswordRefine[0], confirmPasswordRefine[1]);
|
||||
}),
|
||||
);
|
||||
|
||||
const registrationSchemaApi = registrationSchema.and(
|
||||
z.object({
|
||||
@@ -94,15 +94,16 @@ const editProfileSchema = z.object({
|
||||
.nullable(),
|
||||
});
|
||||
|
||||
const changePasswordSchema = z
|
||||
.object({
|
||||
previousPassword: z.string().min(1),
|
||||
password: passwordSchema,
|
||||
confirmPassword: z.string(),
|
||||
})
|
||||
.refine(confirmPasswordRefine[0], confirmPasswordRefine[1]);
|
||||
const baseChangePasswordSchema = z.object({
|
||||
previousPassword: z.string().min(1),
|
||||
password: passwordSchema,
|
||||
confirmPassword: z.string(),
|
||||
userId: z.string(),
|
||||
});
|
||||
|
||||
const changePasswordApiSchema = changePasswordSchema.and(z.object({ userId: z.string() }));
|
||||
const changePasswordSchema = addConfirmPasswordRefinement(baseChangePasswordSchema.omit({ userId: true }));
|
||||
|
||||
const changePasswordApiSchema = addConfirmPasswordRefinement(baseChangePasswordSchema);
|
||||
|
||||
const changeHomeBoardSchema = z.object({
|
||||
homeBoardId: z.string().min(1),
|
||||
|
||||
Reference in New Issue
Block a user