mirror of
https://github.com/kaythomas0/noisedash.git
synced 2025-11-13 03:46:22 +00:00
Add delete user function, fix profile loading
This commit is contained in:
@@ -10,6 +10,9 @@
|
||||
<v-simple-table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-left">
|
||||
ID
|
||||
</th>
|
||||
<th class="text-left">
|
||||
Username
|
||||
</th>
|
||||
@@ -26,17 +29,18 @@
|
||||
v-for="user in users"
|
||||
:key="user.username"
|
||||
>
|
||||
<td>{{ user.id }}</td>
|
||||
<td>{{ user.username }}</td>
|
||||
<td>
|
||||
<v-switch
|
||||
v-model="user.isAdmin"
|
||||
:label="`${user.isAdmin ? 'True' : 'False'}`"
|
||||
@change="updateUser(user.username, user.isAdmin); snackbar = true"
|
||||
@change="updateUser(user.id, user.isAdmin); snackbar = true"
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<v-btn
|
||||
@click="updateUser(user.username)"
|
||||
@click="deleteUser(user.id)"
|
||||
>
|
||||
Delete
|
||||
</v-btn>
|
||||
@@ -88,14 +92,12 @@ export default {
|
||||
console.error(error.response)
|
||||
})
|
||||
},
|
||||
updateUser (username, isAdmin) {
|
||||
this.$http.put('https://localhost:3000/users', {
|
||||
username: username,
|
||||
updateUser (id, isAdmin) {
|
||||
this.$http.patch('https://localhost:3000/users/'.concat(id), {
|
||||
isAdmin: isAdmin ? 1 : 0
|
||||
})
|
||||
.then(response => {
|
||||
if (response.status === 200) {
|
||||
console.log('User updated')
|
||||
this.updateText = 'User updated'
|
||||
}
|
||||
})
|
||||
@@ -103,6 +105,17 @@ export default {
|
||||
console.error(error.response)
|
||||
this.updateText = 'Error updating user'
|
||||
})
|
||||
},
|
||||
deleteUser (id) {
|
||||
this.$http.delete('https://localhost:3000/users/'.concat(id))
|
||||
.then(response => {
|
||||
if (response.status === 200) {
|
||||
this.getUsers()
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.error(error.response)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user