refactor: remove PUT
This commit is contained in:
@@ -7,6 +7,14 @@ export const CustomerFormCreateSchema = z.object({
|
||||
|
||||
export type CustomerFormCreate = z.infer<typeof CustomerFormCreateSchema>;
|
||||
|
||||
export const CustomerFormUpdateSchema = z.object({
|
||||
id: z.string(),
|
||||
type: z.string().optional(),
|
||||
text: z.string().optional()
|
||||
});
|
||||
|
||||
export type CustomerFormUpdate = z.infer<typeof CustomerFormUpdateSchema>;
|
||||
|
||||
export const CustomerFormSchema = z.object({
|
||||
id: z.string(),
|
||||
type: z.string(),
|
||||
@@ -19,8 +27,10 @@ export const CustomerFormListSchema = z.array(CustomerFormSchema);
|
||||
|
||||
export type CustomerForm = z.infer<typeof CustomerFormSchema>;
|
||||
|
||||
export const ContextSchema = z.object({
|
||||
export const ApiResponseContextSchema = z.object({
|
||||
params: z.object({
|
||||
id: z.string()
|
||||
id: z.string(),
|
||||
type: z.string().optional(),
|
||||
text: z.string().optional()
|
||||
})
|
||||
});
|
||||
|
||||
11
utils/validateApiRequestContext.ts
Normal file
11
utils/validateApiRequestContext.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { ApiResponseContextSchema } from '@utils/types';
|
||||
|
||||
export function validateApiRequestContext(context: any) {
|
||||
const validatedContext = ApiResponseContextSchema.safeParse(context);
|
||||
|
||||
if (!validatedContext.success) {
|
||||
throw new Error('Invalid context');
|
||||
}
|
||||
|
||||
return validatedContext.data.params;
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { ContextSchema } from '@utils/types';
|
||||
|
||||
export function validateContext(context: any) {
|
||||
const validatedContext = ContextSchema.safeParse(context);
|
||||
if (!validatedContext.success) {
|
||||
throw new Error('Invalid context');
|
||||
}
|
||||
|
||||
const { id } = validatedContext.data.params;
|
||||
|
||||
return id;
|
||||
}
|
||||
Reference in New Issue
Block a user