Added creation to useradmin model, adding call to apollo in backend.

This commit is contained in:
ogerly 2021-11-23 13:12:11 +01:00
parent 435489223f
commit 52aa7e437e
4 changed files with 41 additions and 37 deletions

View File

@ -0,0 +1,12 @@
import gql from 'graphql-tag'
export const searchUsers = gql`
query($searchText: String!) {
searchUsers(searchText: $searchText) {
firstName
lastName
email
creation
}
}
`

View File

@ -6,6 +6,7 @@
v-model="criteria"
class="shadow p-3 mb-5 bg-white rounded"
placeholder="User suche"
@input="getUsers"
></b-input>
<user-table
type="PageUserSearch"
@ -17,6 +18,7 @@
</template>
<script>
import UserTable from '../components/UserTable.vue'
import { searchUsers } from '../graphql/searchUsers'
export default {
name: 'overview',
@ -28,41 +30,12 @@ export default {
showArrays: false,
fields: [
{ key: 'email', label: 'Email' },
{ key: 'first_name', label: 'Firstname' },
{ key: 'last_name', label: 'Lastname' },
{ key: 'firstName', label: 'Firstname' },
{ key: 'lastName', label: 'Lastname' },
{ key: 'creation', label: 'Creation' },
{ key: 'show_details', label: 'Details' },
],
searchResult: [
{
id: 1,
email: 'dickerson@web.de',
first_name: 'Dickerson',
last_name: 'Macdonald',
creation: '450,200,700',
},
{
id: 2,
email: 'larsen@woob.de',
first_name: 'Larsen',
last_name: 'Shaw',
creation: '300,200,1000',
},
{
id: 3,
email: 'geneva@tete.de',
first_name: 'Geneva',
last_name: 'Wilson',
creation: '350,200,900',
},
{
id: 4,
email: 'viewrter@asdfvb.com',
first_name: 'Soledare',
last_name: 'Takker',
creation: '100,400,800',
},
{ key: 'showDetails', label: 'Details' },
],
searchResult: [],
massCreation: [],
criteria: '',
}
@ -70,20 +43,31 @@ export default {
methods: {
getUsers() {
console.log('getUsers function', this.criteria)
console.log(this.$apollo)
this.$apollo
.query({
query: gql`{ query{getUsers(searchText) {} } }`,
query: searchUsers,
variables: {
searchText: this.criteria,
},
})
.then((result) => {
console.log('getUsers result', result)
this.searchResult = result.data.searchUsers.map((user) => {
return {
...user,
showDetails: false,
}
})
})
.catch((error) => {
this.$toasted.error(error.message)
})
},
},
created() {
this.getUsers()
},
}
</script>

View File

@ -11,4 +11,7 @@ export class UserAdmin {
@Field(() => String)
lastName: string
@Field(() => [Number])
creation: number[]
}

View File

@ -6,7 +6,7 @@ import { LoginUserRepository } from '../../typeorm/repository/LoginUser'
@Resolver()
export class AdminResolver {
@Query(() => [UserAdmin])
async getUsers(@Arg('searchText') searchText: string): Promise<UserAdmin[]> {
async searchUsers(@Arg('searchText') searchText: string): Promise<UserAdmin[]> {
const loginUserRepository = getCustomRepository(LoginUserRepository)
const loginUsers = await loginUserRepository.findBySearchCriteria(searchText)
const users = loginUsers.map((loginUser) => {
@ -14,6 +14,11 @@ export class AdminResolver {
user.firstName = loginUser.firstName
user.lastName = loginUser.lastName
user.email = loginUser.email
user.creation = [
(Math.floor(Math.random() * 50) + 1) * 20,
(Math.floor(Math.random() * 50) + 1) * 20,
(Math.floor(Math.random() * 50) + 1) * 20,
]
return user
})
return users