♻️ Regenerate client to use UUID instead of id integers and update frontend (#1281)

This commit is contained in:
Abdul
2024-08-01 11:48:00 -07:00
committed by GitHub
parent 19049f2a74
commit 36767344aa
5 changed files with 80 additions and 41 deletions

View File

@@ -1,9 +1,9 @@
import axios from "axios" import axios from "axios"
import type { import type {
AxiosError, AxiosError,
AxiosInstance,
AxiosRequestConfig, AxiosRequestConfig,
AxiosResponse, AxiosResponse,
AxiosInstance,
} from "axios" } from "axios"
import { ApiError } from "./ApiError" import { ApiError } from "./ApiError"
@@ -151,12 +151,12 @@ export const getHeaders = async (
) )
if (isStringWithValue(token)) { if (isStringWithValue(token)) {
headers["Authorization"] = `Bearer ${token}` headers.Authorization = `Bearer ${token}`
} }
if (isStringWithValue(username) && isStringWithValue(password)) { if (isStringWithValue(username) && isStringWithValue(password)) {
const credentials = base64(`${username}:${password}`) const credentials = base64(`${username}:${password}`)
headers["Authorization"] = `Basic ${credentials}` headers.Authorization = `Basic ${credentials}`
} }
if (options.body !== undefined) { if (options.body !== undefined) {

View File

@@ -19,8 +19,8 @@ export type ItemCreate = {
export type ItemPublic = { export type ItemPublic = {
title: string title: string
description?: string | null description?: string | null
id: number id: string
owner_id: number owner_id: string
} }
export type ItemUpdate = { export type ItemUpdate = {
@@ -65,7 +65,7 @@ export type UserPublic = {
is_active?: boolean is_active?: boolean
is_superuser?: boolean is_superuser?: boolean
full_name?: string | null full_name?: string | null
id: number id: string
} }
export type UserRegister = { export type UserRegister = {

View File

@@ -65,12 +65,15 @@ export const $ItemCreate = {
title: { title: {
type: "string", type: "string",
isRequired: true, isRequired: true,
maxLength: 255,
minLength: 1,
}, },
description: { description: {
type: "any-of", type: "any-of",
contains: [ contains: [
{ {
type: "string", type: "string",
maxLength: 255,
}, },
{ {
type: "null", type: "null",
@@ -85,12 +88,15 @@ export const $ItemPublic = {
title: { title: {
type: "string", type: "string",
isRequired: true, isRequired: true,
maxLength: 255,
minLength: 1,
}, },
description: { description: {
type: "any-of", type: "any-of",
contains: [ contains: [
{ {
type: "string", type: "string",
maxLength: 255,
}, },
{ {
type: "null", type: "null",
@@ -98,12 +104,14 @@ export const $ItemPublic = {
], ],
}, },
id: { id: {
type: "number", type: "string",
isRequired: true, isRequired: true,
format: "uuid",
}, },
owner_id: { owner_id: {
type: "number", type: "string",
isRequired: true, isRequired: true,
format: "uuid",
}, },
}, },
} as const } as const
@@ -115,6 +123,8 @@ export const $ItemUpdate = {
contains: [ contains: [
{ {
type: "string", type: "string",
maxLength: 255,
minLength: 1,
}, },
{ {
type: "null", type: "null",
@@ -126,6 +136,7 @@ export const $ItemUpdate = {
contains: [ contains: [
{ {
type: "string", type: "string",
maxLength: 255,
}, },
{ {
type: "null", type: "null",
@@ -169,6 +180,8 @@ export const $NewPassword = {
new_password: { new_password: {
type: "string", type: "string",
isRequired: true, isRequired: true,
maxLength: 40,
minLength: 8,
}, },
}, },
} as const } as const
@@ -191,10 +204,14 @@ export const $UpdatePassword = {
current_password: { current_password: {
type: "string", type: "string",
isRequired: true, isRequired: true,
maxLength: 40,
minLength: 8,
}, },
new_password: { new_password: {
type: "string", type: "string",
isRequired: true, isRequired: true,
maxLength: 40,
minLength: 8,
}, },
}, },
} as const } as const
@@ -204,6 +221,8 @@ export const $UserCreate = {
email: { email: {
type: "string", type: "string",
isRequired: true, isRequired: true,
format: "email",
maxLength: 255,
}, },
is_active: { is_active: {
type: "boolean", type: "boolean",
@@ -218,6 +237,7 @@ export const $UserCreate = {
contains: [ contains: [
{ {
type: "string", type: "string",
maxLength: 255,
}, },
{ {
type: "null", type: "null",
@@ -227,6 +247,8 @@ export const $UserCreate = {
password: { password: {
type: "string", type: "string",
isRequired: true, isRequired: true,
maxLength: 40,
minLength: 8,
}, },
}, },
} as const } as const
@@ -236,6 +258,8 @@ export const $UserPublic = {
email: { email: {
type: "string", type: "string",
isRequired: true, isRequired: true,
format: "email",
maxLength: 255,
}, },
is_active: { is_active: {
type: "boolean", type: "boolean",
@@ -250,6 +274,7 @@ export const $UserPublic = {
contains: [ contains: [
{ {
type: "string", type: "string",
maxLength: 255,
}, },
{ {
type: "null", type: "null",
@@ -257,8 +282,9 @@ export const $UserPublic = {
], ],
}, },
id: { id: {
type: "number", type: "string",
isRequired: true, isRequired: true,
format: "uuid",
}, },
}, },
} as const } as const
@@ -268,16 +294,21 @@ export const $UserRegister = {
email: { email: {
type: "string", type: "string",
isRequired: true, isRequired: true,
format: "email",
maxLength: 255,
}, },
password: { password: {
type: "string", type: "string",
isRequired: true, isRequired: true,
maxLength: 40,
minLength: 8,
}, },
full_name: { full_name: {
type: "any-of", type: "any-of",
contains: [ contains: [
{ {
type: "string", type: "string",
maxLength: 255,
}, },
{ {
type: "null", type: "null",
@@ -294,6 +325,8 @@ export const $UserUpdate = {
contains: [ contains: [
{ {
type: "string", type: "string",
format: "email",
maxLength: 255,
}, },
{ {
type: "null", type: "null",
@@ -313,6 +346,7 @@ export const $UserUpdate = {
contains: [ contains: [
{ {
type: "string", type: "string",
maxLength: 255,
}, },
{ {
type: "null", type: "null",
@@ -324,6 +358,8 @@ export const $UserUpdate = {
contains: [ contains: [
{ {
type: "string", type: "string",
maxLength: 40,
minLength: 8,
}, },
{ {
type: "null", type: "null",
@@ -340,6 +376,7 @@ export const $UserUpdateMe = {
contains: [ contains: [
{ {
type: "string", type: "string",
maxLength: 255,
}, },
{ {
type: "null", type: "null",
@@ -351,6 +388,8 @@ export const $UserUpdateMe = {
contains: [ contains: [
{ {
type: "string", type: "string",
format: "email",
maxLength: 255,
}, },
{ {
type: "null", type: "null",

View File

@@ -4,20 +4,20 @@ import { request as __request } from "./core/request"
import type { import type {
Body_login_login_access_token, Body_login_login_access_token,
ItemCreate,
ItemPublic,
ItemUpdate,
ItemsPublic,
Message, Message,
NewPassword, NewPassword,
Token, Token,
UserPublic,
UpdatePassword, UpdatePassword,
UserCreate, UserCreate,
UserPublic,
UserRegister, UserRegister,
UsersPublic,
UserUpdate, UserUpdate,
UserUpdateMe, UserUpdateMe,
ItemCreate, UsersPublic,
ItemPublic,
ItemsPublic,
ItemUpdate,
} from "./models" } from "./models"
export type TDataLoginAccessToken = { export type TDataLoginAccessToken = {
@@ -50,7 +50,7 @@ export class LoginService {
formData: formData, formData: formData,
mediaType: "application/x-www-form-urlencoded", mediaType: "application/x-www-form-urlencoded",
errors: { errors: {
422: `Validation Error`, 422: "Validation Error",
}, },
}) })
} }
@@ -85,7 +85,7 @@ export class LoginService {
email, email,
}, },
errors: { errors: {
422: `Validation Error`, 422: "Validation Error",
}, },
}) })
} }
@@ -106,7 +106,7 @@ export class LoginService {
body: requestBody, body: requestBody,
mediaType: "application/json", mediaType: "application/json",
errors: { errors: {
422: `Validation Error`, 422: "Validation Error",
}, },
}) })
} }
@@ -128,7 +128,7 @@ export class LoginService {
email, email,
}, },
errors: { errors: {
422: `Validation Error`, 422: "Validation Error",
}, },
}) })
} }
@@ -151,14 +151,14 @@ export type TDataRegisterUser = {
requestBody: UserRegister requestBody: UserRegister
} }
export type TDataReadUserById = { export type TDataReadUserById = {
userId: number userId: string
} }
export type TDataUpdateUser = { export type TDataUpdateUser = {
requestBody: UserUpdate requestBody: UserUpdate
userId: number userId: string
} }
export type TDataDeleteUser = { export type TDataDeleteUser = {
userId: number userId: string
} }
export class UsersService { export class UsersService {
@@ -180,7 +180,7 @@ export class UsersService {
limit, limit,
}, },
errors: { errors: {
422: `Validation Error`, 422: "Validation Error",
}, },
}) })
} }
@@ -201,7 +201,7 @@ export class UsersService {
body: requestBody, body: requestBody,
mediaType: "application/json", mediaType: "application/json",
errors: { errors: {
422: `Validation Error`, 422: "Validation Error",
}, },
}) })
} }
@@ -248,7 +248,7 @@ export class UsersService {
body: requestBody, body: requestBody,
mediaType: "application/json", mediaType: "application/json",
errors: { errors: {
422: `Validation Error`, 422: "Validation Error",
}, },
}) })
} }
@@ -269,7 +269,7 @@ export class UsersService {
body: requestBody, body: requestBody,
mediaType: "application/json", mediaType: "application/json",
errors: { errors: {
422: `Validation Error`, 422: "Validation Error",
}, },
}) })
} }
@@ -290,7 +290,7 @@ export class UsersService {
body: requestBody, body: requestBody,
mediaType: "application/json", mediaType: "application/json",
errors: { errors: {
422: `Validation Error`, 422: "Validation Error",
}, },
}) })
} }
@@ -312,7 +312,7 @@ export class UsersService {
user_id: userId, user_id: userId,
}, },
errors: { errors: {
422: `Validation Error`, 422: "Validation Error",
}, },
}) })
} }
@@ -336,7 +336,7 @@ export class UsersService {
body: requestBody, body: requestBody,
mediaType: "application/json", mediaType: "application/json",
errors: { errors: {
422: `Validation Error`, 422: "Validation Error",
}, },
}) })
} }
@@ -356,7 +356,7 @@ export class UsersService {
user_id: userId, user_id: userId,
}, },
errors: { errors: {
422: `Validation Error`, 422: "Validation Error",
}, },
}) })
} }
@@ -382,7 +382,7 @@ export class UtilsService {
email_to: emailTo, email_to: emailTo,
}, },
errors: { errors: {
422: `Validation Error`, 422: "Validation Error",
}, },
}) })
} }
@@ -396,14 +396,14 @@ export type TDataCreateItem = {
requestBody: ItemCreate requestBody: ItemCreate
} }
export type TDataReadItem = { export type TDataReadItem = {
id: number id: string
} }
export type TDataUpdateItem = { export type TDataUpdateItem = {
id: number id: string
requestBody: ItemUpdate requestBody: ItemUpdate
} }
export type TDataDeleteItem = { export type TDataDeleteItem = {
id: number id: string
} }
export class ItemsService { export class ItemsService {
@@ -425,7 +425,7 @@ export class ItemsService {
limit, limit,
}, },
errors: { errors: {
422: `Validation Error`, 422: "Validation Error",
}, },
}) })
} }
@@ -446,7 +446,7 @@ export class ItemsService {
body: requestBody, body: requestBody,
mediaType: "application/json", mediaType: "application/json",
errors: { errors: {
422: `Validation Error`, 422: "Validation Error",
}, },
}) })
} }
@@ -466,7 +466,7 @@ export class ItemsService {
id, id,
}, },
errors: { errors: {
422: `Validation Error`, 422: "Validation Error",
}, },
}) })
} }
@@ -490,7 +490,7 @@ export class ItemsService {
body: requestBody, body: requestBody,
mediaType: "application/json", mediaType: "application/json",
errors: { errors: {
422: `Validation Error`, 422: "Validation Error",
}, },
}) })
} }
@@ -510,7 +510,7 @@ export class ItemsService {
id, id,
}, },
errors: { errors: {
422: `Validation Error`, 422: "Validation Error",
}, },
}) })
} }

View File

@@ -16,7 +16,7 @@ import useCustomToast from "../../hooks/useCustomToast"
interface DeleteProps { interface DeleteProps {
type: string type: string
id: number id: string
isOpen: boolean isOpen: boolean
onClose: () => void onClose: () => void
} }
@@ -30,7 +30,7 @@ const Delete = ({ type, id, isOpen, onClose }: DeleteProps) => {
formState: { isSubmitting }, formState: { isSubmitting },
} = useForm() } = useForm()
const deleteEntity = async (id: number) => { const deleteEntity = async (id: string) => {
if (type === "Item") { if (type === "Item") {
await ItemsService.deleteItem({ id: id }) await ItemsService.deleteItem({ id: id })
} else if (type === "User") { } else if (type === "User") {