Added users rating in announcement details
This commit is contained in:
12
front/src/api/sendRate/index.ts
Normal file
12
front/src/api/sendRate/index.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { API_URL } from '../../config'
|
||||
import { SendRateResponse, SendRate } from './types'
|
||||
|
||||
const composeSendRateURL = () => (
|
||||
API_URL + '/user/rating?'
|
||||
)
|
||||
|
||||
const processSendRate = (data: SendRateResponse): SendRate => {
|
||||
return data.Success
|
||||
}
|
||||
|
||||
export { composeSendRateURL, processSendRate }
|
17
front/src/api/sendRate/types.ts
Normal file
17
front/src/api/sendRate/types.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { isObject } from '../../utils/types'
|
||||
|
||||
type SendRateResponse = {
|
||||
Success: boolean
|
||||
}
|
||||
|
||||
const isSendRateResponse = (obj: unknown): obj is SendRateResponse => (
|
||||
isObject(obj, {
|
||||
'Success': 'boolean',
|
||||
})
|
||||
)
|
||||
|
||||
type SendRate = boolean
|
||||
|
||||
export type { SendRateResponse, SendRate }
|
||||
|
||||
export { isSendRateResponse }
|
14
front/src/api/userRating/index.ts
Normal file
14
front/src/api/userRating/index.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { API_URL } from '../../config'
|
||||
import { UserRatingResponse, UserRating } from './types'
|
||||
|
||||
const initialUserRating: UserRating = 0
|
||||
|
||||
const composeUserRatingURL = (userId: number) => (
|
||||
API_URL + '/user/rating?' + (new URLSearchParams({ user_id: userId.toString() })).toString()
|
||||
)
|
||||
|
||||
const processUserRating = (data: UserRatingResponse): UserRating => {
|
||||
return data.rating
|
||||
}
|
||||
|
||||
export { initialUserRating, composeUserRatingURL, processUserRating }
|
17
front/src/api/userRating/types.ts
Normal file
17
front/src/api/userRating/types.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { isObject } from '../../utils/types'
|
||||
|
||||
type UserRatingResponse = {
|
||||
rating: number
|
||||
}
|
||||
|
||||
const isUserRatingResponse = (obj: unknown): obj is UserRatingResponse => (
|
||||
isObject(obj, {
|
||||
'rating': 'number',
|
||||
})
|
||||
)
|
||||
|
||||
type UserRating = number
|
||||
|
||||
export type { UserRatingResponse, UserRating }
|
||||
|
||||
export { isUserRatingResponse }
|
Reference in New Issue
Block a user