Skip to content

Commit

Permalink
Merge pull request #35 from TineCrnugelj/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
TineCrnugelj authored Apr 13, 2023
2 parents 4a0824f + 3a498f6 commit fff118a
Show file tree
Hide file tree
Showing 63 changed files with 2,087 additions and 10,508 deletions.
9,862 changes: 0 additions & 9,862 deletions backend/package-lock.json

Large diffs are not rendered by default.

22 changes: 14 additions & 8 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ import { TypeOrmModule } from '@nestjs/typeorm';

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AuthModule } from './auth/auth.module';
import { CustomConfigModule } from './custom-config/custom-config.module';
import { DatabaseConfigService } from './custom-config/database-config.service';
import { HealthModule } from './health/health.module';
import { HealthController } from './health/health.controller';
import { HttpConfigService } from './custom-config/http-config.service';
import { HttpLoggingInterceptor } from './interceptor/http-logging/http-logging.interceptor';
import { ProjectModule } from './project/project.module';
import { ServeStaticConfigService } from './custom-config/serve-static-config.service';
import { AuthModule } from './auth/auth.module';
import { UserModule } from './user/user.module';
import { SprintModule } from './sprint/sprint.module';
import { StoryModule } from './story/story.module';
import { UserModule } from './user/user.module';
import { TestModule } from './test/test.module';
import { StoryController } from './story/story.controller';
import {ProjectModule} from './project/project.module';
import { TaskModule } from './task/task.module';

@Module({
imports: [
Expand All @@ -37,12 +38,17 @@ import {ProjectModule} from './project/project.module';
}),
HealthModule,
AuthModule,
UserModule,
TestModule,
ProjectModule,
SprintModule,
StoryModule,
ProjectModule
TaskModule,
TestModule,
UserModule,
],
controllers: [
AppController,
HealthController,
],
controllers: [AppController, HealthController],
providers: [
{
provide: APP_INTERCEPTOR,
Expand Down
4 changes: 3 additions & 1 deletion backend/src/auth/dto/token.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ export interface TokenDto {
exp?: number;
jti?: string;

sid: string;
sid: number;
sub: string;
sname: string;
isAdmin: boolean;
}

export const tokenSchema = Joi.object().keys({
Expand Down
2 changes: 2 additions & 0 deletions backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ async function bootstrap() {
.addTag('health', 'Healthcheck')
.addTag('user', 'User')
.addTag('project', 'Project')
.addTag('sprint', 'Sprint')
.addTag('story', 'Story')
.addTag('task', 'Task')
.addTag('user-login', 'User logins')
.build();
const document = SwaggerModule.createDocument(app, docConfig);
Expand Down
29 changes: 0 additions & 29 deletions backend/src/member/dto/create-member.dto.ts

This file was deleted.

24 changes: 0 additions & 24 deletions backend/src/member/member.entity.ts

This file was deleted.

19 changes: 0 additions & 19 deletions backend/src/member/member.module.ts

This file was deleted.

125 changes: 0 additions & 125 deletions backend/src/member/member.service.ts

This file was deleted.

75 changes: 75 additions & 0 deletions backend/src/project/dto/create-project-user-role.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { ApiProperty } from '@nestjs/swagger';
import * as Joi from 'joi';

import { UserRole } from '../project-user-role.entity';

export class CreateProjectUserRoleDto {
@ApiProperty({
example: 1,
description: 'This is a sample user id in the database.',
minimum: 1,
default: 1
})
userId: number;

@ApiProperty({
example: 0,
description: 'Developer (0), Scrum master (1), Product owner (2).',
minimum: 0,
maximum: 2,
default: 1
})
role: (UserRole | number)[];
}

export const CreateProjectUserRoleSchema = Joi.object().keys({
userId: Joi.number().min(1).required(),
role: Joi.array().items(Joi.number().min(0).max(2).required().default(0))
});

export function hasNewProjectUsersWithRole(userRoles: CreateProjectUserRoleDto[], role: UserRole | number, exactCount: number = 0): boolean {
let count = 0;
for (const userRole of userRoles) {
if (userRole.role.includes(role)) {
count++;
if (exactCount < 0 && count >= Math.abs(exactCount)) // Negative count = at least that many
return true;
}
}
return count === exactCount;
}

export function getFirstNewProjectUserWithRole(userRoles: CreateProjectUserRoleDto[], role: UserRole | number): number | null {
for (const userRole of userRoles)
if (userRole.role.includes(role))
return userRole.userId;
return null;
}

export function hasNewProjectUserRole(userRoles: CreateProjectUserRoleDto[], userId: number, role: UserRole | number, otherThan: boolean = false): boolean {
if (!userId)
return false;
if (!otherThan) {
return userRoles.filter(ur => ur.userId === userId && ur.role.includes(role)).length > 0;
} else {
return userRoles.filter(ur => ur.userId === userId && ur.role.filter(i => i != role).length > 0).length > 0;
}
}

export function hasNewProjectProjectOwner(userRoles: CreateProjectUserRoleDto[]): boolean {
const userId = getFirstNewProjectUserWithRole(userRoles, UserRole.ProjectOwner);
if (userId === null || hasNewProjectUserRole(userRoles, userId, UserRole.ProjectOwner, true))
return false;
return hasNewProjectUsersWithRole(userRoles, UserRole.ProjectOwner, 1);
}

export function hasNewProjectScrumMaster(userRoles: CreateProjectUserRoleDto[]): boolean {
const userId = getFirstNewProjectUserWithRole(userRoles, UserRole.ScrumMaster);
if (userId === null || hasNewProjectUserRole(userRoles, userId, UserRole.ProjectOwner))
return false;
return hasNewProjectUsersWithRole(userRoles, UserRole.ScrumMaster, 1);
}

export function hasNewProjectDevelopers(userRoles: CreateProjectUserRoleDto[]): boolean {
return hasNewProjectUsersWithRole(userRoles, UserRole.Developer, -1);
}
15 changes: 7 additions & 8 deletions backend/src/project/dto/create-project.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ApiProperty } from '@nestjs/swagger';
import * as Joi from 'joi';
import { CreateMemberDto } from 'src/member/dto/create-member.dto';


import { CreateProjectUserRoleDto, CreateProjectUserRoleSchema } from './create-project-user-role.dto';


export class CreateProjectDto {
Expand All @@ -23,19 +25,16 @@ export class CreateProjectDto {
projectDescription?: string | null;

@ApiProperty({
example: [{ userId: 3, role: [2, 3] }, { userId: 1, role: [1] }],
example: [{ userId: 3, role: [2] }, { userId: 1, role: [1] }],
required: true
})
members: CreateMemberDto[];
userRoles: CreateProjectUserRoleDto[];

}

export const CreateProjectSchema = Joi.object().keys({
id: Joi.any().strip(),
projectName: Joi.string().trim().min(1).max(128).required(),
projectDescription: Joi.string().trim().allow(null).allow(''),
members: Joi.array().items(Joi.object().keys({
userId: Joi.number().min(1).required(),
role: Joi.array().items(Joi.number().greater(-1).less(3).required())
}))
});
userRoles: Joi.array().items(CreateProjectUserRoleSchema),
});
Loading

0 comments on commit fff118a

Please sign in to comment.