2023-12-20 17:23:31 -05:00
|
|
|
import { messages } from "@server/constants";
|
|
|
|
import isAdmin from "@server/middlewareButNotReally/isAdmin";
|
|
|
|
import isLoggedIn from "@server/middlewareButNotReally/isLoggedIn";
|
|
|
|
import { User } from "@models/user";
|
2023-10-11 13:24:10 -04:00
|
|
|
|
|
|
|
export default eventHandler(async (ev) => {
|
|
|
|
isLoggedIn(ev);
|
|
|
|
isAdmin(ev);
|
|
|
|
let idee = parseInt(getRouterParam(ev, "id")!);
|
|
|
|
if (Number.isNaN(idee)) throw createError({ statusCode: 400 });
|
|
|
|
const user = await User.findById(idee);
|
|
|
|
if (!user) throw createError({ statusCode: 404, message: messages[404] });
|
|
|
|
let fin: any = {};
|
|
|
|
|
|
|
|
for (const entry of user?.ipLog) {
|
|
|
|
fin[entry.ip] = (
|
|
|
|
await User.find({
|
|
|
|
"ipLog.ip": {
|
|
|
|
$in: [entry.ip],
|
|
|
|
},
|
2023-10-11 14:17:15 -04:00
|
|
|
_id: {
|
|
|
|
$nin: [idee],
|
|
|
|
},
|
2023-10-11 13:24:10 -04:00
|
|
|
})
|
|
|
|
.select("username _id")
|
|
|
|
.exec()
|
|
|
|
).map((a) => a.toObject());
|
|
|
|
}
|
|
|
|
return fin;
|
|
|
|
});
|