This repository has been archived on 2024-12-15. You can view files and clone it, but cannot push or open issues or pull requests.
seepur/app/Utils/UserUtils.js

25 lines
679 B
JavaScript
Raw Permalink Normal View History

const User = use('App/Models/User');
const UserChildUtils = use('App/Utils/UserChildUtils');
class UserUtils {
static async deleteUser(user_id) {
const user = await User.find(user_id)
let userLinks = await user.links().fetch();
//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);
}
}
module.exports = UserUtils;