Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Public profile organization: 40 #43

Merged
merged 3 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions apps/api-gateway/src/organization/organization.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,66 @@ export class OrganizationController {

}

/**
*
* @param user
* @param orgId
* @param res
* @returns Users list of organization
*/
@Get('/public')
@ApiResponse({ status: 200, description: 'Success', type: ApiResponseDto })
@ApiOperation({ summary: 'Get public organization list', description: 'Get users list.' })
@ApiQuery({
name: 'pageNumber',
type: Number,
required: false
})
@ApiQuery({
name: 'pageSize',
type: Number,
required: false
})
@ApiQuery({
name: 'search',
type: String,
required: false
})
async get(@Query() getAllUsersDto: GetAllOrganizationsDto, @Res() res: Response): Promise<Response> {

const users = await this.organizationService.getPublicOrganizations(getAllUsersDto);
const finalResponse: IResponseType = {
statusCode: HttpStatus.OK,
message: ResponseMessages.organisation.success.getOrganizations,
data: users.response
};

return res.status(HttpStatus.OK).json(finalResponse);
}

@Get('public-profile')
@ApiOperation({
summary: 'Fetch user details',
description: 'Fetch user details'
})
@ApiQuery({
name: 'id',
type: Number,
required: false
})
async getPublicProfile(@User() reqUser: user, @Query('id') id: number, @Res() res: Response): Promise<object> {
const userData = await this.organizationService.getPublicProfile(id);

const finalResponse: IResponseType = {
statusCode: HttpStatus.OK,
message: ResponseMessages.organisation.success.fetchProfile,
data: userData.response
};

return res.status(HttpStatus.OK).json(finalResponse);

}

@Get('/roles')
@ApiOperation({
summary: 'Fetch org-roles details',
Expand Down
219 changes: 116 additions & 103 deletions apps/api-gateway/src/organization/organization.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,123 +11,136 @@ import { UpdateOrganizationDto } from './dtos/update-organization-dto';

@Injectable()
export class OrganizationService extends BaseService {
constructor(@Inject('NATS_CLIENT') private readonly serviceProxy: ClientProxy) {
super('OrganizationService');
}

constructor(
@Inject('NATS_CLIENT') private readonly serviceProxy: ClientProxy
) {
super('OrganizationService');
/**
*
* @param createOrgDto
* @returns Organization creation Success
*/
async createOrganization(createOrgDto: CreateOrganizationDto, userId: number): Promise<object> {
try {
const payload = { createOrgDto, userId };
return this.sendNats(this.serviceProxy, 'create-organization', payload);
} catch (error) {
this.logger.error(`In service Error: ${error}`);
throw new RpcException(error.response);
}
}

/**
*
* @param createOrgDto
* @returns Organization creation Success
*/
async createOrganization(createOrgDto: CreateOrganizationDto, userId: number): Promise<object> {
try {
const payload = { createOrgDto, userId };
return this.sendNats(this.serviceProxy, 'create-organization', payload);
} catch (error) {
this.logger.error(`In service Error: ${error}`);
throw new RpcException(error.response);
}
/**
*
* @param updateOrgDto
* @returns Organization update Success
*/
async updateOrganization(updateOrgDto: UpdateOrganizationDto, userId: number): Promise<object> {
try {
const payload = { updateOrgDto, userId };
return this.sendNats(this.serviceProxy, 'update-organization', payload);
} catch (error) {
this.logger.error(`In service Error: ${error}`);
throw new RpcException(error.response);
}
}

/**
*
* @param updateOrgDto
* @returns Organization update Success
*/
async updateOrganization(updateOrgDto: UpdateOrganizationDto, userId: number): Promise<object> {
try {
const payload = { updateOrgDto, userId };
return this.sendNats(this.serviceProxy, 'update-organization', payload);
} catch (error) {
this.logger.error(`In service Error: ${error}`);
throw new RpcException(error.response);
}
}
/**
*
* @param
* @returns Organizations details
*/
async getOrganizations(getAllOrgsDto: GetAllOrganizationsDto, userId: number): Promise<{ response: object }> {
const payload = { userId, ...getAllOrgsDto };
return this.sendNats(this.serviceProxy, 'get-organizations', payload);
}

/**
*
* @param
* @returns Public organizations list
*/
async getPublicOrganizations(getAllOrgsDto: GetAllOrganizationsDto): Promise<{ response: object }> {
const payload = { ...getAllOrgsDto };
return this.sendNats(this.serviceProxy, 'get-public-organizations', payload);
}

/**
*
* @param
* @returns Organizations details
*/
async getOrganizations(getAllOrgsDto: GetAllOrganizationsDto, userId: number): Promise<{ response: object }> {
const payload = { userId, ...getAllOrgsDto };
return this.sendNats(this.serviceProxy, 'get-organizations', payload);
async getPublicProfile(id: number): Promise<{ response: object }> {
const payload = { id };
try {
return this.sendNats(this.serviceProxy, 'get-organization-public-profile', payload);
} catch (error) {
this.logger.error(`Error in get user:${JSON.stringify(error)}`);
}
}

/**
*
* @param orgId
* @returns Organization get Success
*/
async getOrganization(orgId: number, userId: number): Promise<{ response: object }> {
const payload = { orgId, userId };
return this.sendNats(this.serviceProxy, 'get-organization-by-id', payload);
}

/**
*
* @param orgId
* @returns Organization get Success
*/
async getOrganization(orgId: number, userId: number): Promise<{ response: object }> {
const payload = { orgId, userId };
return this.sendNats(this.serviceProxy, 'get-organization-by-id', payload);
}
/**
*
* @param orgId
* @returns Invitations details
*/
async getInvitationsByOrgId(
orgId: number,
getAllInvitationsDto: GetAllSentInvitationsDto
): Promise<{ response: object }> {
const { pageNumber, pageSize, search } = getAllInvitationsDto;
const payload = { orgId, pageNumber, pageSize, search };
return this.sendNats(this.serviceProxy, 'get-invitations-by-orgId', payload);
}

/**
*
* @param orgId
* @returns Invitations details
*/
async getInvitationsByOrgId(orgId: number, getAllInvitationsDto: GetAllSentInvitationsDto): Promise<{ response: object }> {
const { pageNumber, pageSize, search } = getAllInvitationsDto;
const payload = { orgId, pageNumber, pageSize, search };
return this.sendNats(this.serviceProxy, 'get-invitations-by-orgId', payload);
}
async getOrganizationDashboard(orgId: number, userId: number): Promise<{ response: object }> {
const payload = { orgId, userId };
return this.sendNats(this.serviceProxy, 'get-organization-dashboard', payload);
}

async getOrganizationDashboard(orgId: number, userId: number): Promise<{ response: object }> {
const payload = { orgId, userId };
return this.sendNats(this.serviceProxy, 'get-organization-dashboard', payload);
/**
*
* @param
* @returns get organization roles
*/
async getOrgRoles(): Promise<object> {
try {
const payload = {};
return this.sendNats(this.serviceProxy, 'get-org-roles', payload);
} catch (error) {
this.logger.error(`In service Error: ${error}`);
throw new RpcException(error.response);
}
}

/**
*
* @param
* @returns get organization roles
*/
async getOrgRoles(): Promise<object> {
try {
const payload = {};
return this.sendNats(this.serviceProxy, 'get-org-roles', payload);
} catch (error) {
this.logger.error(`In service Error: ${error}`);
throw new RpcException(error.response);
}
/**
*
* @param sendInvitationDto
* @returns Organization invitation creation Success
*/
async createInvitation(bulkInvitationDto: BulkSendInvitationDto, userId: number): Promise<object> {
try {
const payload = { bulkInvitationDto, userId };
return this.sendNats(this.serviceProxy, 'send-invitation', payload);
} catch (error) {
this.logger.error(`In service Error: ${error}`);
throw new RpcException(error.response);
}
}


/**
*
* @param sendInvitationDto
* @returns Organization invitation creation Success
*/
async createInvitation(bulkInvitationDto: BulkSendInvitationDto, userId: number): Promise<object> {
try {
const payload = { bulkInvitationDto, userId };
return this.sendNats(this.serviceProxy, 'send-invitation', payload);
} catch (error) {
this.logger.error(`In service Error: ${error}`);
throw new RpcException(error.response);
}
}

/**
*
* @param updateUserDto
* @param userId
* @returns User roles update response
*/
async updateUserRoles(
updateUserDto: UpdateUserRolesDto,
userId: number
): Promise<{ response: boolean }> {
const payload = { orgId: updateUserDto.orgId, roleIds: updateUserDto.orgRoleId, userId };
return this.sendNats(this.serviceProxy, 'update-user-roles', payload);
}
/**
*
* @param updateUserDto
* @param userId
* @returns User roles update response
*/
async updateUserRoles(updateUserDto: UpdateUserRolesDto, userId: number): Promise<{ response: boolean }> {
const payload = { orgId: updateUserDto.orgId, roleIds: updateUserDto.orgRoleId, userId };
return this.sendNats(this.serviceProxy, 'update-user-roles', payload);
}
}
7 changes: 1 addition & 6 deletions apps/api-gateway/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ async getOrganizationUsers(@User() user: IUserRequestInterface, @Query() getAllU
* @param res
* @returns Users list of organization
*/
@Get('/public-users')
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN, OrgRoles.HOLDER, OrgRoles.ISSUER, OrgRoles.SUPER_ADMIN, OrgRoles.SUPER_ADMIN, OrgRoles.MEMBER)
@ApiBearerAuth()
@UseGuards(AuthGuard('jwt'))
@Get('/public')
@ApiResponse({ status: 200, description: 'Success', type: ApiResponseDto })
@ApiOperation({ summary: 'Get users list', description: 'Get users list.' })
@ApiQuery({
Expand Down Expand Up @@ -228,8 +225,6 @@ async get(@User() user: IUserRequestInterface, @Query() getAllUsersDto: GetAllUs
summary: 'Fetch user details',
description: 'Fetch user details'
})
@UseGuards(AuthGuard('jwt'))
@ApiBearerAuth()
@ApiQuery({
name: 'id',
type: Number,
Expand Down
6 changes: 3 additions & 3 deletions apps/organization/repositories/organization.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ export class OrganizationRepository {
}
}

async getOrganization(orgId: number): Promise<object> {
async getOrganization(queryObject: object): Promise<object> {
try {
return this.prisma.organisation.findUnique({
return this.prisma.organisation.findFirst({
where: {
id: orgId
...queryObject
},
include: {
org_agents: {
Expand Down
Loading