Skip to content

Commit

Permalink
chore: Updated TypeOrm + fixed some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kwiky committed Dec 22, 2023
1 parent 83becbd commit 8d50647
Show file tree
Hide file tree
Showing 21 changed files with 8,483 additions and 17,906 deletions.
25,921 changes: 8,193 additions & 17,728 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
},
"dependencies": {
"@hapi/joi": "^17.1.1",
"@nestjs/common": "^7.6.12",
"@nestjs/config": "^0.6.1",
"@nestjs/core": "^7.5.1",
"@nestjs/jwt": "^7.2.0",
"@nestjs/passport": "^7.1.5",
"@nestjs/platform-express": "^7.5.1",
"@nestjs/swagger": "^4.7.10",
"@nestjs/terminus": "^7.2.0",
"@nestjs/typeorm": "^7.1.5",
"@nestjs/common": "^10.3.0",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.3.0",
"@nestjs/jwt": "^10.2.0",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.3.0",
"@nestjs/swagger": "^7.1.17",
"@nestjs/terminus": "^10.2.0",
"@nestjs/typeorm": "^10.0.1",
"firebase-admin": "^9.5.0",
"nest-winston": "^1.4.0",
"nestjs-swagger-api-implicit-queries-decorator": "^1.0.0",
Expand All @@ -40,15 +40,15 @@
"pg": "^8.5.1",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^6.6.3",
"rxjs": "^7.8.1",
"swagger-ui-express": "^4.1.6",
"typeorm": "^0.2.30",
"typeorm": "^0.3.17",
"winston": "^3.3.3"
},
"devDependencies": {
"@nestjs/cli": "^7.5.1",
"@nestjs/schematics": "^7.1.3",
"@nestjs/testing": "^7.6.5",
"@nestjs/testing": "^10.3.0",
"@types/express": "^4.17.8",
"@types/hapi__joi": "^17.1.6",
"@types/jest": "^26.0.15",
Expand All @@ -63,7 +63,7 @@
"supertest": "^6.0.0",
"ts-jest": "^26.4.3",
"ts-loader": "^8.0.8",
"ts-node": "^9.0.0",
"ts-node": "^10.9.2",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.0.5"
},
Expand Down
31 changes: 18 additions & 13 deletions src/invitations/invitation.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ForbiddenException, Injectable, NotFoundException, UnauthorizedException, UnprocessableEntityException} from "@nestjs/common";
import {ForbiddenException, forwardRef, Inject, Injectable, Logger, NotFoundException, UnauthorizedException, UnprocessableEntityException} from "@nestjs/common";
import {InjectRepository} from "@nestjs/typeorm";
import ProjectsService from "../projects/projects.service";
import {getManager, Repository} from "typeorm";
Expand All @@ -21,6 +21,8 @@ export default class InvitationService {
) {
}

private readonly logger = new Logger("InvitationService");

public async createInvitation(userId: string, createInvitationDto: CreateInvitationDto): Promise<Invitation> {
const project: Project = await this.projectsService.getProject(userId, createInvitationDto.projectId);
const guest: User = await this.usersService.getUserByEmail(createInvitationDto.email);
Expand All @@ -40,19 +42,22 @@ export default class InvitationService {
}

public async getInvitationsForUser(userId: string): Promise<UserInvitation[]> {
return await getManager()
.createQueryBuilder()
.select(["invitations.role AS role", "invitations.id AS id", "owner.email AS owner_email", "owner.username AS owner_username", "project.name AS project_name"])
.from(InvitationTableName, "invitations")
.leftJoin(UsersTableName, "owner", "invitations.ownerId = owner.id")
.leftJoin(ProjectsTableName, "project", "invitations.projectId = project.id")
.where("invitations.guestId = :guestId")
.setParameters({guestId: userId})
.getRawMany();
return (await this.invitationRepository.find({
relations: ["owner", "project"],
where: {guestId: userId}
})).map((invitation) => {
return new UserInvitation(
invitation.role,
invitation.id,
invitation.owner.email,
invitation.owner.username,
invitation.project.name
)
});
}

public async acceptInvitation(userId: string, invitationId: number): Promise<void> {
const invitation = await this.invitationRepository.findOne(invitationId);
const invitation = await this.invitationRepository.findOneById(invitationId);
if (!invitation) {
throw new NotFoundException();
}
Expand All @@ -64,7 +69,7 @@ export default class InvitationService {
}

public async declineInvitation(userId: string, invitationId: number): Promise<void> {
const invitation = await this.invitationRepository.findOne(invitationId);
const invitation = await this.invitationRepository.findOneById(invitationId);
if (!invitation) {
throw new NotFoundException();
}
Expand All @@ -75,7 +80,7 @@ export default class InvitationService {
}

public async deleteInvitation(userId: string, invitationId: number): Promise<void> {
const invitation = await this.invitationRepository.findOne(invitationId);
const invitation = await this.invitationRepository.findOneById(invitationId);
if (!invitation) {
throw new NotFoundException();
}
Expand Down
12 changes: 9 additions & 3 deletions src/projects/project.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn} from "typeorm";
import {ApiProperty, ApiPropertyOptional} from "@nestjs/swagger";
import {Column, CreateDateColumn, Entity, JoinTable, ManyToMany, OneToMany, PrimaryGeneratedColumn, UpdateDateColumn} from "typeorm";
import {ApiHideProperty, ApiProperty, ApiPropertyOptional} from "@nestjs/swagger";
import User from "../users/user.entity";
import UserProject from "../users-projects/user_project.entity";

export const ProjectsTableName: string = "projects";

Expand Down Expand Up @@ -28,4 +30,8 @@ export default class Project {
@UpdateDateColumn()
@ApiProperty()
readonly updatedAt: Date;
}

@OneToMany(() => UserProject, (userProject) => userProject.project)
@ApiHideProperty()
userProjects: UserProject[]
}
12 changes: 9 additions & 3 deletions src/projects/projects.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,25 @@ import UserProject from "../users-projects/user_project.entity";
import Project from "./project.entity";
import ProjectsController from "./projects.controller";
import ProjectsService from "./projects.service";
import Invitation from "../invitations/invitation.entity";
import User from "../users/user.entity";
import UsersModule from "../users/users.module";

@Module({
imports: [
TypeOrmModule.forFeature([
Project,
Language,
UserProject,
Group,
Invitation,
Language,
Project,
TranslationKey,
TranslationValue,
User,
UserProject,
]),
TranslationModule,
GroupModule,
UsersModule
],
controllers: [ProjectsController],
providers: [ProjectsService],
Expand Down
Loading

0 comments on commit 8d50647

Please sign in to comment.