n8n
Version:
n8n Workflow Automation Tool
55 lines • 2.31 kB
JavaScript
const typedi_1 = require("typedi");
const users_service_ee_1 = require("./users.service.ee");
const pagination_service_1 = require("../../shared/services/pagination.service");
const global_middleware_1 = require("../../shared/middlewares/global.middleware");
const InternalHooks_1 = require("../../../../InternalHooks");
module.exports = {
getUser: [
global_middleware_1.validLicenseWithUserQuota,
(0, global_middleware_1.globalScope)('user:read'),
async (req, res) => {
const { includeRole = false } = req.query;
const { id } = req.params;
const user = await (0, users_service_ee_1.getUser)({ withIdentifier: id, includeRole });
if (!user) {
return res.status(404).json({
message: `Could not find user with id: ${id}`,
});
}
const telemetryData = {
user_id: req.user.id,
public_api: true,
};
void typedi_1.Container.get(InternalHooks_1.InternalHooks).onUserRetrievedUser(telemetryData);
return res.json((0, users_service_ee_1.clean)(user, { includeRole }));
},
],
getUsers: [
global_middleware_1.validLicenseWithUserQuota,
global_middleware_1.validCursor,
(0, global_middleware_1.globalScope)(['user:list', 'user:read']),
async (req, res) => {
const { offset = 0, limit = 100, includeRole = false } = req.query;
const [users, count] = await (0, users_service_ee_1.getAllUsersAndCount)({
includeRole,
limit,
offset,
});
const telemetryData = {
user_id: req.user.id,
public_api: true,
};
void typedi_1.Container.get(InternalHooks_1.InternalHooks).onUserRetrievedAllUsers(telemetryData);
return res.json({
data: (0, users_service_ee_1.clean)(users, { includeRole }),
nextCursor: (0, pagination_service_1.encodeNextCursor)({
offset,
limit,
numberOfTotalRecords: count,
}),
});
},
],
};
//# sourceMappingURL=users.handler.ee.js.map
;