forked from polka_billy/porridger
Added api/user request prototype
This commit is contained in:
25
front/src/api/user/index.ts
Normal file
25
front/src/api/user/index.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { API_URL } from '../../config'
|
||||
import { UserResponse, User } from './types'
|
||||
|
||||
import { faker } from '@faker-js/faker/locale/ru'
|
||||
|
||||
|
||||
const initialUser: User = import.meta.env.DEV ? { // Temporary, until api is realized
|
||||
id: Math.random() * 100,
|
||||
name: faker.person.firstName() + ' ' + faker.person.lastName(),
|
||||
regDate: faker.date.anytime().getTime(),
|
||||
} : {
|
||||
id: -1,
|
||||
name: '',
|
||||
regDate: 0,
|
||||
}
|
||||
|
||||
const composeUserURL = () => (
|
||||
API_URL + '/user?'
|
||||
)
|
||||
|
||||
const processUser = (data: UserResponse): User => {
|
||||
return data
|
||||
}
|
||||
|
||||
export { initialUser, composeUserURL, processUser }
|
29
front/src/api/user/types.ts
Normal file
29
front/src/api/user/types.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { isObject } from '../../utils/types'
|
||||
|
||||
type User = {
|
||||
id: number,
|
||||
name: string,
|
||||
regDate: number,
|
||||
}
|
||||
|
||||
const isUser = (obj: unknown): obj is User => (
|
||||
isObject(obj, {
|
||||
'id': 'number',
|
||||
'name': 'string',
|
||||
'regDate': 'number',
|
||||
})
|
||||
)
|
||||
|
||||
type UserResponse = User
|
||||
|
||||
// const isUserResponse = (obj: unknown): obj is UserResponse => (
|
||||
// isObject(obj, {
|
||||
|
||||
// })
|
||||
// )
|
||||
|
||||
const isUserResponse = isUser
|
||||
|
||||
export type { UserResponse, User }
|
||||
|
||||
export { isUserResponse, isUser }
|
Reference in New Issue
Block a user