🕹 Manage root users
🕹 Manage root users
This commit is contained in:
@@ -261,6 +261,7 @@ export class CompanyServiceImpl {
|
||||
companyId: uuid,
|
||||
userId: uuid,
|
||||
role: CompanyUserRole = "member",
|
||||
level?: any,
|
||||
applications: string[] = [],
|
||||
context?: ExecutionContext,
|
||||
): Promise<SaveResult<CompanyUser>> {
|
||||
@@ -275,6 +276,9 @@ export class CompanyServiceImpl {
|
||||
}
|
||||
|
||||
entity.role = role;
|
||||
if (level) {
|
||||
entity.level = level;
|
||||
}
|
||||
entity.applications = applications;
|
||||
await this.companyUserRepository.save(entity, context);
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
UserListQueryParameters,
|
||||
UserObject,
|
||||
UserParameters,
|
||||
CompanyUsersParameters,
|
||||
} from "./types";
|
||||
import Company from "../entities/company";
|
||||
import CompanyUser from "../entities/company_user";
|
||||
@@ -144,6 +145,36 @@ export class UsersCrudController
|
||||
};
|
||||
}
|
||||
|
||||
async all(
|
||||
request: FastifyRequest<{
|
||||
Querystring: UserListQueryParameters;
|
||||
Params: CompanyUsersParameters;
|
||||
}>,
|
||||
): Promise<ResourceListResponse<UserObject>> {
|
||||
const companyId = request.params.companyId;
|
||||
|
||||
const users = await gr.services.users.search(
|
||||
new Pagination(request.query.page_token, request.query.limit),
|
||||
{
|
||||
search: "",
|
||||
companyId,
|
||||
},
|
||||
);
|
||||
|
||||
const resUsers = await Promise.all(
|
||||
users.getEntities().map(user =>
|
||||
formatUser(user, {
|
||||
includeCompanies: true,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
// return users;
|
||||
return {
|
||||
resources: resUsers,
|
||||
};
|
||||
}
|
||||
|
||||
async getUserCompanies(
|
||||
request: FastifyRequest<{ Params: UserParameters }>,
|
||||
_reply: FastifyReply,
|
||||
|
||||
@@ -60,6 +60,15 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
|
||||
handler: usersController.list.bind(usersController),
|
||||
});
|
||||
|
||||
fastify.route({
|
||||
method: "POST",
|
||||
url: `${usersUrl}/:companyId/all`,
|
||||
preHandler: accessControl,
|
||||
preValidation: [fastify.authenticate],
|
||||
schema: getUsersSchema,
|
||||
handler: usersController.all.bind(usersController),
|
||||
});
|
||||
|
||||
// Get a list of companies for a user, only common companies with current user are returned.
|
||||
fastify.route({
|
||||
method: "GET",
|
||||
|
||||
@@ -13,6 +13,11 @@ export interface UserParameters {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface CompanyUsersParameters {
|
||||
/* user id */
|
||||
companyId: string;
|
||||
}
|
||||
|
||||
export interface CompanyParameters {
|
||||
/* company id */
|
||||
id: string;
|
||||
|
||||
Reference in New Issue
Block a user