Remove functions that mock filtering users
This commit is contained in:
parent
df0abd99c7
commit
3ff2c3ae38
1 changed files with 11 additions and 36 deletions
|
@ -1,12 +1,12 @@
|
|||
import userChats from './chat'
|
||||
|
||||
export let users = [
|
||||
{ active: true, is_confirmed: true, is_approved: true, is_active: true, id: '2', nickname: 'allis', local: true, external: false, roles: { admin: true, moderator: false }, tags: [], actor_type: 'Person' },
|
||||
{ active: true, is_confirmed: true, is_approved: true, is_active: true, id: '10', nickname: 'bob', local: true, external: false, roles: { admin: false, moderator: false }, tags: ['mrf_tag:sandbox'], actor_type: 'Person' },
|
||||
{ active: true, is_confirmed: true, is_approved: false, is_active: true, id: '567', nickname: 'ded', local: false, external: true, roles: { admin: false, moderator: false }, tags: [], actor_type: 'Person' },
|
||||
{ active: false, is_confirmed: true, is_approved: true, is_active: false, id: 'abc', nickname: 'john', local: true, external: false, roles: { admin: false, moderator: false }, tags: ['mrf_tag:media-strip'], actor_type: 'Person' },
|
||||
{ active: true, is_confirmed: true, is_approved: false, is_active: true, id: '100', nickname: 'sally', local: true, external: false, roles: { admin: false, moderator: false }, tags: [], actor_type: 'Service' },
|
||||
{ active: true, is_confirmed: true, is_approved: false, is_active: true, id: '123', nickname: 'bot', local: true, external: false, roles: { admin: false, moderator: false }, tags: [], actor_type: 'Application' }
|
||||
{ is_confirmed: true, is_approved: true, is_active: true, id: '2', nickname: 'allis', local: true, external: false, roles: { admin: true, moderator: false }, tags: [], actor_type: 'Person' },
|
||||
{ is_confirmed: true, is_approved: true, is_active: true, id: '10', nickname: 'bob', local: true, external: false, roles: { admin: false, moderator: false }, tags: ['mrf_tag:sandbox'], actor_type: 'Person' },
|
||||
{ is_confirmed: true, is_approved: false, is_active: true, id: '567', nickname: 'ded', local: false, external: true, roles: { admin: false, moderator: false }, tags: [], actor_type: 'Person' },
|
||||
{ is_confirmed: true, is_approved: true, is_active: false, id: 'abc', nickname: 'john', local: true, external: false, roles: { admin: false, moderator: false }, tags: ['mrf_tag:media-strip'], actor_type: 'Person' },
|
||||
{ is_confirmed: true, is_approved: false, is_active: true, id: '100', nickname: 'sally', local: true, external: false, roles: { admin: false, moderator: false }, tags: [], actor_type: 'Service' },
|
||||
{ is_confirmed: true, is_approved: false, is_active: true, id: '123', nickname: 'bot', local: true, external: false, roles: { admin: false, moderator: false }, tags: [], actor_type: 'Application' }
|
||||
]
|
||||
|
||||
const userProfile = { avatar: 'avatar.jpg', nickname: 'allis', id: '2', tags: [], roles: { admin: true, moderator: false }, local: true, external: false }
|
||||
|
@ -17,26 +17,6 @@ const userStatuses = [
|
|||
{ account: { id: '9n1bySks25olxWrku0', nickname: 'dolin' }, content: 'what is yout favorite pizza?', id: '9jop82OBXeFPYulVjM', created_at: '2020-05-22T17:34:34.000Z', visibility: 'public' }
|
||||
]
|
||||
|
||||
const filterUsers = (str) => {
|
||||
const filters = str.split(',').filter(item => item.length > 0)
|
||||
if (filters.length === 0) {
|
||||
return users
|
||||
}
|
||||
const applyFilters = (acc, filters, users) => {
|
||||
if (filters.length === 0) {
|
||||
return acc
|
||||
}
|
||||
const filteredUsers = users.filter(user => user[filters[0]])
|
||||
const newAcc = [...filteredUsers]
|
||||
return applyFilters(newAcc, filters.slice(1), filteredUsers)
|
||||
}
|
||||
return applyFilters([], filters, users)
|
||||
}
|
||||
|
||||
const filterUsersByActorType = filters => {
|
||||
return users.filter(user => filters.includes(user.actor_type))
|
||||
}
|
||||
|
||||
export async function fetchUser(id, authHost, token) {
|
||||
return Promise.resolve({ data: userProfile })
|
||||
}
|
||||
|
@ -46,12 +26,9 @@ export async function fetchUserCredentials(nickname, authHost, token) {
|
|||
}
|
||||
|
||||
export async function fetchUsers(filters, actorTypeFilters, authHost, token, page = 1) {
|
||||
const filteredUsers = filterUsers(filters)
|
||||
const filteredByActorTypeUsers = filterUsersByActorType(actorTypeFilters)
|
||||
const response = actorTypeFilters.length === 0 ? filteredUsers : filteredByActorTypeUsers
|
||||
return Promise.resolve({ data: {
|
||||
users: response,
|
||||
count: response.length,
|
||||
users,
|
||||
count: users.length,
|
||||
page_size: 50
|
||||
}})
|
||||
}
|
||||
|
@ -69,12 +46,10 @@ export async function getPasswordResetToken(nickname, authHost, token) {
|
|||
}
|
||||
|
||||
export async function searchUsers(query, filters, actorTypeFilters, authHost, token, page = 1) {
|
||||
const filteredUsers = filterUsers(filters)
|
||||
const filteredByActorTypeUsers = filterUsersByActorType(actorTypeFilters)
|
||||
const response = actorTypeFilters.length === 0 ? filteredUsers : filteredByActorTypeUsers
|
||||
const response = users.filter(user => user.nickname === query)
|
||||
return Promise.resolve({ data: {
|
||||
users: response.filter(user => user.nickname === query),
|
||||
count: response.filter(user => user.nickname === query).length,
|
||||
users: response,
|
||||
count: response.length,
|
||||
page_size: 50
|
||||
}})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue