2020-03-17 22:16:34 +00:00
|
|
|
'use strict'
|
|
|
|
const User = use('App/Models/User');
|
2020-04-12 14:25:42 +00:00
|
|
|
const Child = use('App/Models/Child');
|
|
|
|
const Link = use('App/Models/Link');
|
|
|
|
const IceServer = use('App/Models/IceServer');
|
2020-05-13 01:30:11 +00:00
|
|
|
|
|
|
|
const EmailUtils = use('App/Utils/EmailUtils');
|
2020-05-26 11:52:36 +00:00
|
|
|
const UserChildUtils = use('App/Utils/UserChildUtils');
|
2020-03-17 22:16:34 +00:00
|
|
|
class AdminApiController {
|
2020-05-23 19:02:04 +00:00
|
|
|
async getUsers({ response }) {
|
|
|
|
const users = await User.all();
|
|
|
|
// console.log(typeof users);
|
|
|
|
// return users.rows.map(u => {
|
|
|
|
// return u.publicJSON();
|
|
|
|
// });
|
|
|
|
return users;
|
|
|
|
}
|
2020-05-13 01:30:11 +00:00
|
|
|
|
2020-05-23 19:02:04 +00:00
|
|
|
async deleteUser({ request, response }) {
|
|
|
|
const { id } = request.params
|
2020-05-13 01:30:11 +00:00
|
|
|
|
2020-05-23 19:02:04 +00:00
|
|
|
const user = await User.find(id)
|
|
|
|
let userLinks = await user.links().fetch();
|
2020-05-26 11:52:36 +00:00
|
|
|
|
|
|
|
//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)
|
|
|
|
}
|
2020-05-23 19:02:04 +00:00
|
|
|
|
|
|
|
const promises = [...links.map(l => (l.delete())), user.delete()];
|
|
|
|
return await Promise.all(promises);
|
|
|
|
}
|
2020-05-26 11:52:36 +00:00
|
|
|
|
2020-05-23 19:02:04 +00:00
|
|
|
async addStunServer({ request, response }) {}
|
|
|
|
async addTurnServer({ request, response }) {}
|
|
|
|
|
|
|
|
async testEmailSettings({ auth, response }) {
|
|
|
|
try {
|
|
|
|
if (EmailUtils.sendTestEmail(auth.user)) {
|
|
|
|
return {
|
|
|
|
code: 0,
|
|
|
|
data: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
code: 500,
|
|
|
|
message: 'Something went wrong'
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
response.code(500);
|
|
|
|
return {
|
|
|
|
code: 500,
|
|
|
|
message: e.message
|
|
|
|
}
|
|
|
|
}
|
2020-05-13 01:30:11 +00:00
|
|
|
}
|
2020-03-17 22:16:34 +00:00
|
|
|
}
|
|
|
|
|
2020-05-23 19:02:04 +00:00
|
|
|
module.exports = AdminApiController
|