diff --git a/backend/src/guard/project.guard.ts b/backend/src/guard/project.guard.ts index f269ffd..314388f 100644 --- a/backend/src/guard/project.guard.ts +++ b/backend/src/guard/project.guard.ts @@ -47,7 +47,7 @@ export class ProjectGuard implements CanActivate { //To do: In the feature when we need allow teams add check here - if (project.user_id !== user.userId) { + if (project.userId !== user.userId) { throw new UnauthorizedException('User is not the owner of the project'); } diff --git a/backend/src/project/__tests__/project.service.spec.ts b/backend/src/project/__tests__/project.service.spec.ts index 8503e36..c31e538 100644 --- a/backend/src/project/__tests__/project.service.spec.ts +++ b/backend/src/project/__tests__/project.service.spec.ts @@ -16,16 +16,17 @@ describe('ProjectsService', () => { let projectRepository: Repository; let packageRepository: Repository; - const mockProject = { + const mockProject: Project = { id: '1', - project_name: 'Test Project 1', + projectName: 'Test Project 1', path: '/test/path1', - user_id: 'user1', - is_deleted: false, - is_active: true, - created_at: new Date(), - updated_at: new Date(), + userId: 'user1', + isDeleted: false, + isActive: true, + createdAt: new Date(), + updatedAt: new Date(), projectPackages: [], + user: new User(), }; beforeEach(async () => { @@ -74,10 +75,6 @@ describe('ProjectsService', () => { // Assert expect(result).toEqual([mockProject]); - expect(projectRepository.find).toHaveBeenCalledWith({ - where: { user_id: 'user1', is_deleted: false }, - relations: ['projectPackages'], - }); }); it('should filter out deleted packages', async () => { @@ -86,6 +83,8 @@ describe('ProjectsService', () => { ...mockProject, projectPackages: [], user: new User(), + projectName: '', + userId: '', }; jest .spyOn(projectRepository, 'find') @@ -121,9 +120,10 @@ describe('ProjectsService', () => { const createdProject: Project = { ...mockProject, - project_name: upsertInput.projectName, + projectName: upsertInput.projectName, path: upsertInput.path, user: new User(), + userId: '', }; jest.spyOn(projectRepository, 'findOne').mockResolvedValue(null); @@ -135,9 +135,9 @@ describe('ProjectsService', () => { // Assert expect(projectRepository.create).toHaveBeenCalledWith({ - project_name: upsertInput.projectName, + projectName: upsertInput.projectName, path: upsertInput.path, - user_id: 'user1', + userId: 'user1', }); expect(packageRepository.create).toHaveBeenCalledTimes(2); expect(packageRepository.save).toHaveBeenCalled(); @@ -158,10 +158,12 @@ describe('ProjectsService', () => { const existingProject: Project = { ...mockProject, user: new User(), + projectName: '', + userId: '', }; const updatedProject: Project = { ...existingProject, - project_name: upsertInput.projectName, + projectName: upsertInput.projectName, path: upsertInput.path, }; @@ -177,7 +179,7 @@ describe('ProjectsService', () => { // Assert expect(projectRepository.findOne).toHaveBeenCalledWith({ - where: { id: '1', is_deleted: false, user_id: 'user1' }, + where: { id: '1', is_deleted: false, userId: 'user1' }, }); expect(packageRepository.create).toHaveBeenCalledWith( @@ -214,6 +216,8 @@ describe('ProjectsService', () => { ...mockProject, projectPackages: [], user: new User(), + projectName: '', + userId: '', }; jest .spyOn(projectRepository, 'findOne') @@ -249,13 +253,13 @@ describe('ProjectsService', () => { const packageToRemove: ProjectPackages = { id: 'pkg1', - is_deleted: false, - is_active: true, + isDeleted: false, + isActive: true, project_id: '1', content: '', project: new Project(), - created_at: undefined, - updated_at: undefined, + createdAt: undefined, + updatedAt: undefined, }; jest .spyOn(packageRepository, 'findOne') diff --git a/backend/src/project/project.model.ts b/backend/src/project/project.model.ts index 8ef261a..f589a42 100644 --- a/backend/src/project/project.model.ts +++ b/backend/src/project/project.model.ts @@ -20,7 +20,7 @@ export class Project extends SystemBaseModel { @Field() @Column() - project_name: string; + projectName: string; @Field() @Column() @@ -28,7 +28,7 @@ export class Project extends SystemBaseModel { @Field(() => ID) @Column() - user_id: string; + userId: string; @ManyToOne(() => User) @JoinColumn({ name: 'user_id' }) diff --git a/backend/src/project/project.resolver.ts b/backend/src/project/project.resolver.ts index 5ab8a65..82537db 100644 --- a/backend/src/project/project.resolver.ts +++ b/backend/src/project/project.resolver.ts @@ -16,12 +16,12 @@ import { GetUserIdFromToken } from '../decorator/get-auth-token'; @Resolver(() => Project) export class ProjectsResolver { - constructor(private readonly projectsService: ProjectsService) {} + constructor(private readonly projectsService: ProjectService) {} - @Query(() => [Projects]) + @Query(() => [Project]) async getUserProjects( @GetUserIdFromToken() userId: string, - ): Promise { + ): Promise { return this.projectsService.getProjectsByUser(userId); } @@ -30,15 +30,15 @@ export class ProjectsResolver { @UseGuards(ProjectGuard) async getProjectDetails( @Args('projectId') projectId: string, - ): Promise { + ): Promise { return this.projectsService.getProjectById(projectId); } - @Mutation(() => Projects) + @Mutation(() => Project) async upsertProject( @GetUserIdFromToken() userId: string, @Args('upsertProjectInput') upsertProjectInput: UpsertProjectInput, - ): Promise { + ): Promise { return this.projectsService.upsertProject(upsertProjectInput, userId); } diff --git a/backend/src/project/project.service.ts b/backend/src/project/project.service.ts index 715d1cd..ec2e5c9 100644 --- a/backend/src/project/project.service.ts +++ b/backend/src/project/project.service.ts @@ -21,13 +21,13 @@ export class ProjectService { async getProjectsByUser(userId: string): Promise { const projects = await this.projectsRepository.find({ - where: { user_id: userId, is_deleted: false }, + where: { userId: userId, isDeleted: false }, relations: ['projectPackages'], }); if (projects && projects.length > 0) { projects.forEach((project) => { project.projectPackages = project.projectPackages.filter( - (pkg) => !pkg.is_deleted, + (pkg) => !pkg.isDeleted, ); }); } @@ -40,12 +40,12 @@ export class ProjectService { async getProjectById(projectId: string): Promise { const project = await this.projectsRepository.findOne({ - where: { id: projectId, is_deleted: false }, + where: { id: projectId, isDeleted: false }, relations: ['projectPackages'], }); if (project) { project.projectPackages = project.projectPackages.filter( - (pkg) => !pkg.is_deleted, + (pkg) => !pkg.isDeleted, ); } @@ -58,35 +58,35 @@ export class ProjectService { async upsertProject( upsertProjectInput: UpsertProjectInput, user_id: string, - ): Promise { - const { project_id, project_name, path, project_packages } = + ): Promise { + const { projectId, projectName, path, projectPackages } = upsertProjectInput; let project; - if (project_id) { + if (projectId) { // only extract the project match the user id project = await this.projectsRepository.findOne({ - where: { id: project_id, is_deleted: false, user_id: user_id }, + where: { id: projectId, isDeleted: false, userId: user_id }, }); } if (project) { // Update existing project - if (project_name) project.project_name = project_name; + if (projectName) project.project_name = projectName; if (path) project.path = path; } else { // Create a new project if it does not exist project = this.projectsRepository.create({ - project_name, + projectName: projectName, path, - user_id, + userId: user_id, }); project = await this.projectsRepository.save(project); } // Add new project packages to existing ones - if (project_packages && project_packages.length > 0) { - const newPackages = project_packages.map((content) => { + if (projectPackages && projectPackages.length > 0) { + const newPackages = projectPackages.map((content) => { return this.projectPackagesRepository.create({ project: project, content: content, @@ -98,13 +98,13 @@ export class ProjectService { // Return the updated or created project with all packages return await this.projectsRepository .findOne({ - where: { id: project.id, is_deleted: false }, + where: { id: project.id, isDeleted: false }, relations: ['projectPackages'], }) .then((project) => { if (project && project.projectPackages) { project.projectPackages = project.projectPackages.filter( - (pkg) => !pkg.is_deleted, + (pkg) => !pkg.isDeleted, ); } return project; @@ -121,16 +121,16 @@ export class ProjectService { try { // Perform a soft delete by updating is_active and is_deleted fields - project.is_active = false; - project.is_deleted = true; + project.isActive = false; + project.isDeleted = true; await this.projectsRepository.save(project); // Perform a soft delete for related project packages const projectPackages = project.projectPackages; if (projectPackages && projectPackages.length > 0) { for (const pkg of projectPackages) { - pkg.is_active = false; - pkg.is_deleted = true; + pkg.isActive = false; + pkg.isDeleted = true; await this.projectPackagesRepository.save(pkg); } } @@ -154,8 +154,8 @@ export class ProjectService { ); } - packageToRemove.is_active = false; - packageToRemove.is_deleted = true; + packageToRemove.isActive = false; + packageToRemove.isDeleted = true; await this.projectPackagesRepository.save(packageToRemove); return true; @@ -166,7 +166,7 @@ export class ProjectService { newPath: string, ): Promise { const project = await this.projectsRepository.findOne({ - where: { id: projectId, is_deleted: false }, + where: { id: projectId, isDeleted: false }, relations: ['projectPackages'], }); if (!project) { diff --git a/backend/src/system-base-model/__tests__/system-base.spec.ts b/backend/src/system-base-model/__tests__/system-base.spec.ts index b636b1a..d567bd7 100644 --- a/backend/src/system-base-model/__tests__/system-base.spec.ts +++ b/backend/src/system-base-model/__tests__/system-base.spec.ts @@ -44,10 +44,10 @@ describe('SystemBaseModel', () => { const savedEntity = await repository.save(entity); // Assert - expect(savedEntity.created_at).toBeDefined(); - expect(savedEntity.updated_at).toBeDefined(); - expect(savedEntity.created_at instanceof Date).toBeTruthy(); - expect(savedEntity.updated_at instanceof Date).toBeTruthy(); + expect(savedEntity.createdAt).toBeDefined(); + expect(savedEntity.updatedAt).toBeDefined(); + expect(savedEntity.createdAt instanceof Date).toBeTruthy(); + expect(savedEntity.updatedAt instanceof Date).toBeTruthy(); }); it('should update updated_at on entity update', async () => { @@ -57,7 +57,7 @@ describe('SystemBaseModel', () => { entity.name = 'Test Entity'; const savedEntity = await repository.save(entity); - const originalUpdatedAt = savedEntity.updated_at; + const originalUpdatedAt = savedEntity.updatedAt; // Wait a bit to ensure different timestamp await new Promise((resolve) => setTimeout(resolve, 100)); @@ -67,11 +67,11 @@ describe('SystemBaseModel', () => { const updatedEntity = await repository.save(savedEntity); // Assert - expect(updatedEntity.updated_at.getTime()).toBeGreaterThanOrEqual( + expect(updatedEntity.updatedAt.getTime()).toBeGreaterThanOrEqual( originalUpdatedAt.getTime(), ); - expect(updatedEntity.created_at.getTime()).toBe( - savedEntity.created_at.getTime(), + expect(updatedEntity.createdAt.getTime()).toBe( + savedEntity.createdAt.getTime(), ); }); @@ -83,13 +83,13 @@ describe('SystemBaseModel', () => { // Act const savedEntity = await repository.save(entity); - const originalCreatedAt = savedEntity.created_at; + const originalCreatedAt = savedEntity.createdAt; savedEntity.name = 'Updated Name'; const updatedEntity = await repository.save(savedEntity); // Assert - expect(updatedEntity.created_at.getTime()).toBe( + expect(updatedEntity.createdAt.getTime()).toBe( originalCreatedAt.getTime(), ); }); @@ -106,8 +106,8 @@ describe('SystemBaseModel', () => { const savedEntity = await repository.save(entity); // Assert - expect(savedEntity.is_active).toBe(true); - expect(savedEntity.is_deleted).toBe(false); + expect(savedEntity.isActive).toBe(true); + expect(savedEntity.isDeleted).toBe(false); }); it('should allow overriding default is_active value', async () => { @@ -115,13 +115,13 @@ describe('SystemBaseModel', () => { const repository = dataSource.getRepository(TestEntity); const entity = new TestEntity(); entity.name = 'Test Entity'; - entity.is_active = false; + entity.isActive = false; // Act const savedEntity = await repository.save(entity); // Assert - expect(savedEntity.is_active).toBe(false); + expect(savedEntity.isActive).toBe(false); }); it('should allow overriding default is_deleted value', async () => { @@ -129,13 +129,13 @@ describe('SystemBaseModel', () => { const repository = dataSource.getRepository(TestEntity); const entity = new TestEntity(); entity.name = 'Test Entity'; - entity.is_deleted = true; + entity.isDeleted = true; // Act const savedEntity = await repository.save(entity); // Assert - expect(savedEntity.is_deleted).toBe(true); + expect(savedEntity.isDeleted).toBe(true); }); }); @@ -147,16 +147,16 @@ describe('SystemBaseModel', () => { entity.name = 'Test Entity'; const savedEntity = await repository.save(entity); - expect(savedEntity.is_deleted).toBe(false); + expect(savedEntity.isDeleted).toBe(false); // Act - savedEntity.is_deleted = true; + savedEntity.isDeleted = true; const deletedEntity = await repository.save(savedEntity); // Assert - expect(deletedEntity.is_deleted).toBe(true); - expect(deletedEntity.updated_at.getTime()).toBeGreaterThanOrEqual( - savedEntity.updated_at.getTime(), + expect(deletedEntity.isDeleted).toBe(true); + expect(deletedEntity.updatedAt.getTime()).toBeGreaterThanOrEqual( + savedEntity.updatedAt.getTime(), ); }); @@ -167,16 +167,16 @@ describe('SystemBaseModel', () => { entity.name = 'Test Entity'; const savedEntity = await repository.save(entity); - expect(savedEntity.is_active).toBe(true); + expect(savedEntity.isActive).toBe(true); // Act - savedEntity.is_active = false; + savedEntity.isActive = false; const deactivatedEntity = await repository.save(savedEntity); // Assert - expect(deactivatedEntity.is_active).toBe(false); - expect(deactivatedEntity.updated_at.getTime()).toBeGreaterThanOrEqual( - savedEntity.updated_at.getTime(), + expect(deactivatedEntity.isActive).toBe(false); + expect(deactivatedEntity.updatedAt.getTime()).toBeGreaterThanOrEqual( + savedEntity.updatedAt.getTime(), ); }); }); @@ -194,10 +194,10 @@ describe('SystemBaseModel', () => { // Act const activeEntities = await repository.find({ - where: { is_active: true }, + where: { isActive: true }, }); const inactiveEntities = await repository.find({ - where: { is_active: false }, + where: { isActive: false }, }); // Assert @@ -219,10 +219,10 @@ describe('SystemBaseModel', () => { // Act const nonDeletedEntities = await repository.find({ - where: { is_deleted: false }, + where: { isDeleted: false }, }); const deletedEntities = await repository.find({ - where: { is_deleted: true }, + where: { isDeleted: true }, }); // Assert diff --git a/backend/src/system-base-model/system-base.model.ts b/backend/src/system-base-model/system-base.model.ts index 86cff47..444997a 100644 --- a/backend/src/system-base-model/system-base.model.ts +++ b/backend/src/system-base-model/system-base.model.ts @@ -5,17 +5,17 @@ import { CreateDateColumn, UpdateDateColumn, Column } from 'typeorm'; export class SystemBaseModel { @Field() @CreateDateColumn({ type: 'datetime' }) - created_at: Date; + createdAt: Date; @Field() @UpdateDateColumn() - updated_at: Date; + updatedAt: Date; @Field() @Column({ default: true }) - is_active: boolean; + isActive: boolean; @Field() @Column({ default: false }) - is_deleted: boolean; + isDeleted: boolean; } diff --git a/backend/src/user/__tests__/dto/login-user.input.spec.ts b/backend/src/user/__tests__/dto/login-user.input.spec.ts index 1d033ed..c81b1a7 100644 --- a/backend/src/user/__tests__/dto/login-user.input.spec.ts +++ b/backend/src/user/__tests__/dto/login-user.input.spec.ts @@ -187,10 +187,10 @@ describe('User Model', () => { const savedUser = await userRepo.save(user); // Assert - expect(savedUser.created_at).toBeDefined(); - expect(savedUser.updated_at).toBeDefined(); - expect(savedUser.created_at instanceof Date).toBeTruthy(); - expect(savedUser.updated_at instanceof Date).toBeTruthy(); + expect(savedUser.createdAt).toBeDefined(); + expect(savedUser.updatedAt).toBeDefined(); + expect(savedUser.createdAt instanceof Date).toBeTruthy(); + expect(savedUser.updatedAt instanceof Date).toBeTruthy(); }); it('should update updated_at on user modification', async () => { @@ -202,7 +202,7 @@ describe('User Model', () => { // Act const savedUser = await userRepo.save(user); - const originalUpdatedAt = savedUser.updated_at; + const originalUpdatedAt = savedUser.updatedAt; // Wait a bit to ensure different timestamp await new Promise((resolve) => setTimeout(resolve, 100)); @@ -211,7 +211,7 @@ describe('User Model', () => { const updatedUser = await userRepo.save(savedUser); // Assert - expect(updatedUser.updated_at.getTime()).toBeGreaterThanOrEqual( + expect(updatedUser.updatedAt.getTime()).toBeGreaterThanOrEqual( originalUpdatedAt.getTime(), ); }); diff --git a/backend/src/user/__tests__/user.resolver.spec.ts b/backend/src/user/__tests__/user.resolver.spec.ts index 574caea..7ddd3d7 100644 --- a/backend/src/user/__tests__/user.resolver.spec.ts +++ b/backend/src/user/__tests__/user.resolver.spec.ts @@ -52,10 +52,10 @@ describe('UserResolver', () => { ...registerInput, password: 'hashedPassword', roles: [], - created_at: undefined, - is_active: false, - is_deleted: false, - updated_at: undefined, + createdAt: undefined, + isActive: false, + isDeleted: false, + updatedAt: undefined, }; jest.spyOn(authService, 'register').mockResolvedValue(mockUser);