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

fix: roles response issues #702

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
3,240 changes: 3,088 additions & 152 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/helpers/SystemMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ export const NO_USER_TESTIMONIALS = 'User has no testimonials';
export const USER_TESTIMONIALS_FETCHED = 'User testimonials retrieved successfully';
export const REVENUE_FETCHED_SUCCESSFULLY = 'Revenue Fetched';
export const QUESTION_ALREADY_EXISTS = 'This question already exists.';
export const ROLE_ALREADY_EXISTS = 'A role with this name already exists in the organisation';
1 change: 1 addition & 0 deletions src/modules/invite/mocks/mockOrg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export const mockOrg: Organisation = {
preferences: [],
invites: [],
products: [],
members: [],
};
1 change: 1 addition & 0 deletions src/modules/invite/mocks/mockUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ export const mockUser: User = {
notifications: [],
blogs: [],
cart: [],
organisations: [],
};
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ export const mockUser: User = {
jobs: [],
blogs: [],
cart: [],
organisations: [],
};
8 changes: 4 additions & 4 deletions src/modules/organisations/entities/organisations.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Entity, Column, ManyToOne, OneToMany } from 'typeorm';
import { Entity, Column, ManyToOne, OneToMany, ManyToMany } from 'typeorm';
import { User } from '../../user/entities/user.entity';
import { OrganisationPreference } from './org-preferences.entity';
import { AbstractBaseEntity } from '../../../entities/base.entity';
Expand Down Expand Up @@ -31,6 +31,9 @@ export class Organisation extends AbstractBaseEntity {
@ManyToOne(() => User, user => user.owned_organisations, { nullable: false })
owner: User;

@ManyToMany(() => User, user => user.organisations, { nullable: false })
members: User[];

@Column({ nullable: false })
state: string;

Expand All @@ -45,7 +48,4 @@ export class Organisation extends AbstractBaseEntity {

@OneToMany(() => Invite, invite => invite.organisation.id)
invites: Invite[];

// @OneToMany(() => OrganisationMember, organisationMember => organisationMember.organisation_id)
// organisationMembers: OrganisationMember[];
}
178 changes: 36 additions & 142 deletions src/modules/organisations/organisations.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { pipeline } from 'stream/promises';
import { unlink } from 'fs/promises';

@ApiBearerAuth()
@ApiTags('organization')
@ApiTags('Organization')
@Controller('organizations')
export class OrganisationsController {
private readonly logger = new Logger(OrganisationsController.name);
Expand Down Expand Up @@ -113,145 +113,39 @@ export class OrganisationsController {
return this.organisationsService.getOrganisationMembers(org_id, page, page_size, sub);
}

// @ApiOperation({ summary: 'Assign roles to members of an organisation' })
// @ApiResponse({
// status: 200,
// description: 'Assign roles to members of an organisation',
// schema: {
// properties: {
// status: { type: 'string' },
// message: { type: 'string' },
// data: {
// type: 'object',
// properties: {
// user: { type: 'string' },
// org: { type: 'string' },
// role: { type: 'string' },
// },
// },
// },
// },
// })
// @ApiResponse({
// status: 404,
// description: 'Organisation not found',
// })
// @ApiResponse({
// status: 403,
// description: 'User not a member of the organisation',
// })

// @Put(':orgId/members/:memberId/role')
// async updateMemberRole(
// @Param('memberId') memberId: string,
// @Param('orgId') orgId: string,
// @Body() updateMemberRoleDto: UpdateMemberRoleDto
// ) {
// return await this.organisationsService.updateMemberRole(orgId, memberId, updateMemberRoleDto);
// }
// @UseGuards(OwnershipGuard)
// @ApiOperation({ summary: 'Add member to an organization' })
// @ApiResponse({
// status: 201,
// description: 'Member added successfully',
// })
// @ApiResponse({
// status: 409,
// description: 'User already added to organization.',
// })
// @ApiResponse({
// status: 404,
// description: 'Organisation not found',
// })
// @Post(':org_id/users')
// async addMember(@Param('org_id', ParseUUIDPipe) org_id: string, @Body() addMemberDto: AddMemberDto) {
// return this.organisationsService.addOrganisationMember(org_id, addMemberDto);
// }
// @ApiOperation({ summary: "Gets a user's organizations" })
// @ApiResponse({
// status: 200,
// description: 'Organisations retrieved successfully',
// type: UserOrganizationResponseDto,
// })
// @ApiResponse({
// status: 400,
// description: 'Bad request',
// type: UserOrganizationErrorResponseDto,
// })
// @Get('/')
// async getUserOrganisations(@Req() req) {
// const { sub } = req.user;
// return this.organisationsService.getUserOrganisations(sub);
// }
// @ApiOperation({ summary: 'Get Organization details by Id' })
// @ApiResponse({
// status: 200,
// description: 'Fetched Organization details',
// })
// @ApiResponse({
// status: 400,
// description: 'Must provide a valid organization Id',
// })
// @ApiResponse({
// status: 404,
// description: 'Organization not found',
// })
// @Get(':org_id')
// async getById(@Param('org_id') org_id: string) {
// return this.organisationsService.getOrganizationDetailsById(org_id);
// }
// @ApiOperation({ summary: 'Export members of an Organisation to a CSV file' })
// @ApiResponse({
// status: 200,
// })
// @ApiResponse({
// status: 200,
// description: 'The CSV file containing organisation members is returned.',
// headers: {
// 'Content-Type': {
// description: 'The content type of the response, which is text/csv.',
// schema: {
// type: 'string',
// example: 'text/csv',
// },
// },
// 'Content-Disposition': {
// description: 'Indicates that the content is an attachment with a filename.',
// schema: {
// type: 'string',
// example: 'attachment; filename="organisation-members-{orgId}.csv"',
// },
// },
// },
// })

// @UseGuards(OwnershipGuard)
// @Get(':org_id/members/export')
// async exportOrganisationMembers(
// @Param('org_id', ParseUUIDPipe) orgId: string,
// @Req() req: Request,
// @Res() res: Response
// ) {
// const userId = req['user'].id;
// const filePath = await this.organisationsService.exportOrganisationMembers(orgId, userId);

// res.set({
// 'Content-Type': 'text/csv',
// 'Content-Disposition': `attachment; filename="organisation-members-${orgId}.csv"`,
// });

// const fileStream = createReadStream(filePath);

// pipeline(fileStream, res)
// .then(() => unlink(filePath))
// .catch(error => {
// this.logger.error('Pipeline failed:', error.stack);
// if (!res.headersSent) {
// res.status(500).send('Internal Server Error');
// }
// return unlink(filePath).catch(unlinkError => {
// this.logger.error(`Failed to delete file: ${unlinkError.message}`, unlinkError.stack);
// });
// });
// }
@ApiOperation({ summary: 'Assign roles to members of an organisation' })
@ApiResponse({
status: 200,
description: 'Assign roles to members of an organisation',
schema: {
properties: {
status: { type: 'string' },
message: { type: 'string' },
data: {
type: 'object',
properties: {
user: { type: 'string' },
org: { type: 'string' },
role: { type: 'string' },
},
},
},
},
})
@ApiResponse({
status: 404,
description: 'Organisation not found',
})
@ApiResponse({
status: 403,
description: 'User not a member of the organisation',
})
@Put(':org_id/users/:user_id/role')
async updateMemberRole(
@Param('user_id') memberId: string,
@Param('org_id') orgId: string,
@Body() updateMemberRoleDto: UpdateMemberRoleDto
) {
return await this.organisationsService.updateMemberRole(orgId, memberId, updateMemberRoleDto);
}
}
Loading
Loading