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 IceServer = use('App/Models/IceServer');
|
||||||
|
|
||||||
const EmailUtils = use('App/Utils/EmailUtils');
|
const EmailUtils = use('App/Utils/EmailUtils');
|
||||||
|
const UserChildUtils = use('App/Utils/UserChildUtils');
|
||||||
class AdminApiController {
|
class AdminApiController {
|
||||||
async getUsers({ response }) {
|
async getUsers({ response }) {
|
||||||
const users = await User.all();
|
const users = await User.all();
|
||||||
|
@ -16,16 +17,25 @@ class AdminApiController {
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteUser({ request, response }) {
|
async deleteUser({ request, response }) {
|
||||||
console.log('in delete user')
|
|
||||||
const { id } = request.params
|
const { id } = request.params
|
||||||
|
|
||||||
const user = await User.find(id)
|
const user = await User.find(id)
|
||||||
let userLinks = await user.links().fetch();
|
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()];
|
const promises = [...links.map(l => (l.delete())), user.delete()];
|
||||||
return await Promise.all(promises);
|
return await Promise.all(promises);
|
||||||
}
|
}
|
||||||
|
|
||||||
async addStunServer({ request, response }) {}
|
async addStunServer({ request, response }) {}
|
||||||
async addTurnServer({ request, response }) {}
|
async addTurnServer({ request, response }) {}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
|
|
||||||
|
|
||||||
const Link = use('App/Models/Link');
|
const Link = use('App/Models/Link');
|
||||||
|
const Child = use('App/Models/Child');
|
||||||
class UserChildUtils {
|
class UserChildUtils {
|
||||||
static async isUserConnectedToChild(user_id, child_id) {
|
static async isUserConnectedToChild(user_id, child_id) {
|
||||||
const links = await Link.query().where({ user_id, child_id }).fetch();
|
const links = await Link.query().where({ user_id, child_id }).fetch();
|
||||||
|
@ -61,9 +60,19 @@ class UserChildUtils {
|
||||||
const user = await link.user().fetch();
|
const user = await link.user().fetch();
|
||||||
const child = await link.child().fetch();
|
const child = await link.child().fetch();
|
||||||
return {
|
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;
|
module.exports = UserChildUtils;
|
|
@ -4,7 +4,7 @@
|
||||||
test
|
test
|
||||||
</Modal>
|
</Modal>
|
||||||
<Modal title="DeleteUser" :isActive="showDeleteUser" @close="showDeleteUser=false; currentUser=null" acceptText="Delete" rejectText="Cancel" @accept="deleteUser(currentUser)">
|
<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>
|
</Modal>
|
||||||
<nav class="level">
|
<nav class="level">
|
||||||
<div class="level-left">
|
<div class="level-left">
|
||||||
|
@ -55,6 +55,7 @@
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<button v-if="!user.is_admin" class="button" @click="onDeleteClicked(user)">Delete</button>
|
<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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
@ -85,6 +86,10 @@ export default {
|
||||||
this.showDeleteUser = true;
|
this.showDeleteUser = true;
|
||||||
this.currentUser = user;
|
this.currentUser = user;
|
||||||
},
|
},
|
||||||
|
// onEditClicked(user){
|
||||||
|
// //this.showEditUser = true;
|
||||||
|
// //this.currentUser = user;
|
||||||
|
// },
|
||||||
...mapActions(["getUsers"])
|
...mapActions(["getUsers"])
|
||||||
},
|
},
|
||||||
async created() {
|
async created() {
|
||||||
|
|
Reference in a new issue