Updated user to use latest api

This commit is contained in:
2023-08-08 18:32:14 +03:00
parent 60779ea489
commit f432193508
5 changed files with 35 additions and 50 deletions

View File

@ -1,19 +1,11 @@
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(),
points: Math.round(Math.random() * 1000),
} : {
id: 1,
name: 'Вася пупкин',
regDate: 0,
points: 100,
const initialUser: User = {
id: -1,
nickname: '',
regDate: '',
points: -1,
}
const composeUserURL = () => (
@ -21,7 +13,10 @@ const composeUserURL = () => (
)
const processUser = (data: UserResponse): User => {
return data
return {
...data,
regDate: data.reg_date,
}
}
export { initialUser, composeUserURL, processUser }

View File

@ -2,30 +2,22 @@ import { isObject } from '../../utils/types'
type User = {
id: number,
name: string,
regDate: number,
nickname: string,
regDate: string,
points: number,
}
const isUser = (obj: unknown): obj is User => (
type UserResponse = Omit<User, 'regDate'> & { reg_date: string }
const isUserResponse = (obj: unknown): obj is UserResponse => (
isObject(obj, {
'id': 'number',
'name': 'string',
'regDate': 'number',
'nickname': 'string',
'reg_date': 'string',
'points': 'number',
})
)
type UserResponse = User
// const isUserResponse = (obj: unknown): obj is UserResponse => (
// isObject(obj, {
// })
// )
const isUserResponse = isUser
export type { UserResponse, User }
export { isUserResponse, isUser }
export { isUserResponse }