del user-del also children & links of children
This commit is contained in:
parent
3bfa60db28
commit
a73ec272a8
3 changed files with 91 additions and 67 deletions
|
@ -5,6 +5,7 @@ const Link = use('App/Models/Link');
|
|||
const IceServer = use('App/Models/IceServer');
|
||||
|
||||
const EmailUtils = use('App/Utils/EmailUtils');
|
||||
const UserChildUtils = use('App/Utils/UserChildUtils');
|
||||
class AdminApiController {
|
||||
async getUsers({ response }) {
|
||||
const users = await User.all();
|
||||
|
@ -16,16 +17,25 @@ class AdminApiController {
|
|||
}
|
||||
|
||||
async deleteUser({ request, response }) {
|
||||
console.log('in delete user')
|
||||
const { id } = request.params
|
||||
|
||||
const user = await User.find(id)
|
||||
let userLinks = await user.links().fetch();
|
||||
const links = userLinks.rows
|
||||
|
||||
//my links
|
||||
const links = userLinks.rows;
|
||||
|
||||
//children and children links
|
||||
const childrenLinks = links.filter(l => l.is_parent)
|
||||
|
||||
for (const link of childrenLinks) {
|
||||
await UserChildUtils.deleteChild(link.child_id)
|
||||
}
|
||||
|
||||
const promises = [...links.map(l => (l.delete())), user.delete()];
|
||||
return await Promise.all(promises);
|
||||
}
|
||||
|
||||
async addStunServer({ request, response }) {}
|
||||
async addTurnServer({ request, response }) {}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
|
||||
|
||||
const Link = use('App/Models/Link');
|
||||
const Child = use('App/Models/Child');
|
||||
class UserChildUtils {
|
||||
static async isUserConnectedToChild(user_id, child_id) {
|
||||
const links = await Link.query().where({ user_id, child_id }).fetch();
|
||||
|
@ -61,9 +60,19 @@ class UserChildUtils {
|
|||
const user = await link.user().fetch();
|
||||
const child = await link.child().fetch();
|
||||
return {
|
||||
user, child, is_parent
|
||||
user,
|
||||
child,
|
||||
is_parent
|
||||
}
|
||||
}
|
||||
|
||||
static async deleteChild(child_id) {
|
||||
const child = await Child.find(child_id)
|
||||
const childLinks = await child.links().fetch();
|
||||
|
||||
const promises = [...childLinks.rows.map(l => (l.delete())), child.delete()];
|
||||
return await Promise.all(promises);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UserChildUtils;
|
|
@ -4,7 +4,7 @@
|
|||
test
|
||||
</Modal>
|
||||
<Modal title="DeleteUser" :isActive="showDeleteUser" @close="showDeleteUser=false; currentUser=null" acceptText="Delete" rejectText="Cancel" @accept="deleteUser(currentUser)">
|
||||
Are you sure you want to delete {{user.name}}?
|
||||
Are you sure you want to delete {{currentUser !== null ? currentUser.name: ''}}?
|
||||
</Modal>
|
||||
<nav class="level">
|
||||
<div class="level-left">
|
||||
|
@ -55,6 +55,7 @@
|
|||
</td>
|
||||
<td>
|
||||
<button v-if="!user.is_admin" class="button" @click="onDeleteClicked(user)">Delete</button>
|
||||
<!-- <button v-if="!user.is_admin" class="button" @click="onEditClicked(user)">Edit</button> -->
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -85,6 +86,10 @@ export default {
|
|||
this.showDeleteUser = true;
|
||||
this.currentUser = user;
|
||||
},
|
||||
// onEditClicked(user){
|
||||
// //this.showEditUser = true;
|
||||
// //this.currentUser = user;
|
||||
// },
|
||||
...mapActions(["getUsers"])
|
||||
},
|
||||
async created() {
|
||||
|
|
Reference in a new issue