Skip to content

Commit

Permalink
feat: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
collettemathieu committed Aug 5, 2024
1 parent 032fcc4 commit 75e87ed
Show file tree
Hide file tree
Showing 25 changed files with 282 additions and 226 deletions.
25 changes: 0 additions & 25 deletions apps/pathway-design/server/src/app/app.controller.spec.ts

This file was deleted.

13 changes: 0 additions & 13 deletions apps/pathway-design/server/src/app/app.controller.ts

This file was deleted.

21 changes: 16 additions & 5 deletions apps/pathway-design/server/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import { Module } from '@nestjs/common';

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { PDSPIInitializePathwayPersistenceInfrastructureModule } from '@bewoak/pathway-design-server-pathway-infrastructure';
import { PDSPIAInitializePathwayInterfaceAdaptersModule } from '@bewoak/pathway-design-server-pathway-interface-adapters';
import { PDSPPPathwayPresentersModule } from '@bewoak/pathway-design-server-pathway-presenters';
import { CqrsModule } from '@nestjs/cqrs';

@Module({
imports: [],
controllers: [AppController],
providers: [AppService],
imports: [
PDSPIAInitializePathwayInterfaceAdaptersModule.withPersistence(
PDSPIInitializePathwayPersistenceInfrastructureModule.use(
'inMemory'
)
)
.withPresenter(PDSPPPathwayPresentersModule.use('toJson'))
.build(),
CqrsModule.forRoot(),
],
controllers: [],
providers: [],
})
export class AppModule {}
22 changes: 0 additions & 22 deletions apps/pathway-design/server/src/app/app.service.spec.ts

This file was deleted.

8 changes: 0 additions & 8 deletions apps/pathway-design/server/src/app/app.service.ts

This file was deleted.

27 changes: 26 additions & 1 deletion apps/pathway-design/server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,38 @@
import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';

import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { AppModule } from './app/app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
const app = await NestFactory.create(AppModule, { bufferLogs: true });
const globalPrefix = 'api';
app.setGlobalPrefix(globalPrefix);
const port = process.env.PORT ?? 3000;

// Setting up Swagger document
const options = new DocumentBuilder()
.setTitle('Pathway Design Application')
.setDescription(
'Application Programming Interface (API) of Pathway Design Application'
)
.setVersion('1.0')
.addBearerAuth(
{
description:
'Please enter token in following format: Bearer <JWT>',
name: 'Authorization',
bearerFormat: 'Bearer',
scheme: 'Bearer',
type: 'http',
in: 'Header',
},
'access-token'
)
.build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup('api', app, document);

await app.listen(port);
Logger.log(
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`
Expand Down
7 changes: 0 additions & 7 deletions apps/pathway-design/server/src/test/index.feature

This file was deleted.

42 changes: 0 additions & 42 deletions apps/pathway-design/server/src/test/index.step.ts

This file was deleted.

16 changes: 15 additions & 1 deletion apps/pathway-design/server/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,27 @@ module.exports = {
plugins: [
new NxAppWebpackPlugin({
target: 'node',
compiler: 'swc',
compiler: 'tsc',
main: './src/main.ts',
tsConfig: './tsconfig.app.json',
assets: ['./src/assets'],
optimization: process.env.BUN_ENV === 'production',
outputHashing:
process.env.BUN_ENV === 'production' ? 'all' : 'none',
transformers: [
{
name: '@nestjs/swagger/plugin',
options: {
classValidatorShim: true,
dtoFileNameSuffix: [
'.dto.ts',
'.entity.ts',
'.schema.ts',
],
introspectComments: true,
},
},
],
}),
],
};
Binary file modified bun.lockb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PDSPBPPathwayPresenter } from '@bewoak/pathway-design-server-pathway-business';
import type { PDSPBPPathwayPresenters } from '@bewoak/pathway-design-server-pathway-business';
import { Inject, Injectable } from '@nestjs/common';
import { CommandBus } from '@nestjs/cqrs';
import type { PDSPAInitializePathwayCommand } from '../command/initialize-pathway.command';
Expand All @@ -10,7 +10,7 @@ export class PDSPAInitializePathwayService {
init(pDSPAInitializePathwayCommand: PDSPAInitializePathwayCommand) {
return this.commandBus.execute<
PDSPAInitializePathwayCommand,
PDSPBPPathwayPresenter
PDSPBPPathwayPresenters
>(pDSPAInitializePathwayCommand);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { strict as assert } from 'node:assert';
import type {
PDSPBEPathwayEntity,
PDSPBPInitializePathwayPersistencePort,
PDSPBPPathwayPresenter,
PDSPBPPathwayPresenterPort,
PDSPBPPathwayPresenters,
} from '@bewoak/pathway-design-server-pathway-business';
import type { DataTable } from '@cucumber/cucumber';
import type { EventPublisher } from '@nestjs/cqrs';
Expand Down Expand Up @@ -45,7 +45,7 @@ class FakeEventPublisher {
@binding()
export default class ControllerSteps {
private pDSPBUInitPathwayUseCase = new PDSPAIUInitializePathwayUsecase();
private result: PDSPBPPathwayPresenter | undefined;
private result: PDSPBPPathwayPresenters | undefined;
private fakeInitializePathwayPersistence =
new FakeInitializePathwayPersistence();
private fakePathwayPresenter = new FakePathwayPresenter();
Expand Down
2 changes: 1 addition & 1 deletion libs/pathway-design/server/pathway/business/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export {
} from './lib/ports/persistences/initialize/initialize-pathway-persitence.port';
export {
PDSPBP_PATHWAY_PRESENTER_PORT,
type PDSPBPPathwayPresenter,
type PDSPBPPathwayPresenterPort,
type PDSPBPPathwayPresenters,
} from './lib/ports/presenters/pathway-presenter.port';
export { PDSPBVOTitleValueObjects } from './lib/value-objects/title.value-object';
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,27 @@ Feature: Manage Pathway Entity
| id | title | description | researchField |
| | | | |
Then I should see an error message "Pathway id must be a valid uuid"

Scenario: I want to initialize a pathway with missing id
When I initialize a pathway with these data
| title | description | researchField |
| My Pathway | A test pathway | biology |
Then I should see an error message "Pathway id must be a valid uuid"

Scenario: I want to initialize a pathway with missing title
When I initialize a pathway with these data
| id | description | researchField |
| f7703737-186c-4c7c-8d46-925111c7c7c1 | A test pathway | biology |
Then I should see an error message "Title is required"

Scenario: I want to initialize a pathway with missing description
When I initialize a pathway with these data
| id | title | researchField |
| f7703737-186c-4c7c-8d46-925111c7c7c1 | My Pathway | biology |
Then I should see an error message "Description is required"

Scenario: I want to initialize a pathway with missing research field
When I initialize a pathway with these data
| id | title | description |
| f7703737-186c-4c7c-8d46-925111c7c7c1 | My Pathway | A test pathway |
Then I should see an error message "Research field is required"
62 changes: 62 additions & 0 deletions libs/pathway-design/server/pathway/business/src/lib/exceptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
export class BadRequestException extends Error {
public readonly statusCode: number;

constructor(message: string) {
super(message);
this.name = 'BadRequestException';
this.statusCode = HttpStatus.BAD_REQUEST;
this.message = message;
Error.captureStackTrace(this, this.constructor);
}
}

export enum HttpStatus {
CONTINUE = 100,
SWITCHING_PROTOCOLS = 101,
PROCESSING = 102,
EARLYHINTS = 103,
OK = 200,
CREATED = 201,
ACCEPTED = 202,
NON_AUTHORITATIVE_INFORMATION = 203,
NO_CONTENT = 204,
RESET_CONTENT = 205,
PARTIAL_CONTENT = 206,
AMBIGUOUS = 300,
MOVED_PERMANENTLY = 301,
FOUND = 302,
SEE_OTHER = 303,
NOT_MODIFIED = 304,
TEMPORARY_REDIRECT = 307,
PERMANENT_REDIRECT = 308,
BAD_REQUEST = 400,
UNAUTHORIZED = 401,
PAYMENT_REQUIRED = 402,
FORBIDDEN = 403,
NOT_FOUND = 404,
METHOD_NOT_ALLOWED = 405,
NOT_ACCEPTABLE = 406,
PROXY_AUTHENTICATION_REQUIRED = 407,
REQUEST_TIMEOUT = 408,
CONFLICT = 409,
GONE = 410,
LENGTH_REQUIRED = 411,
PRECONDITION_FAILED = 412,
PAYLOAD_TOO_LARGE = 413,
URI_TOO_LONG = 414,
UNSUPPORTED_MEDIA_TYPE = 415,
REQUESTED_RANGE_NOT_SATISFIABLE = 416,
EXPECTATION_FAILED = 417,
I_AM_A_TEAPOT = 418,
MISDIRECTED = 421,
UNPROCESSABLE_ENTITY = 422,
FAILED_DEPENDENCY = 424,
PRECONDITION_REQUIRED = 428,
TOO_MANY_REQUESTS = 429,
INTERNAL_SERVER_ERROR = 500,
NOT_IMPLEMENTED = 501,
BAD_GATEWAY = 502,
SERVICE_UNAVAILABLE = 503,
GATEWAY_TIMEOUT = 504,
HTTP_VERSION_NOT_SUPPORTED = 505,
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ export interface PDSPBPJsonPathwayPresenter {
title: string;
}

export type PDSPBPPathwayPresenter = PDSPBPJsonPathwayPresenter;
export type PDSPBPPathwayPresenters = PDSPBPJsonPathwayPresenter;

export interface PDSPBPPathwayPresenterPort {
present: (
pDSPBEpathwayEntity: PDSPBEPathwayEntity
) => PDSPBPPathwayPresenter;
) => PDSPBPPathwayPresenters;
}

export const PDSPBP_PATHWAY_PRESENTER_PORT = Symbol(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { BadRequestException } from '../exceptions';

export class DescriptionValueObject {
constructor(private description: string) {
if (this.isEmpty(description)) {
throw new Error('Description is required');
throw new BadRequestException('Description is required');
}
}
get value() {
Expand All @@ -16,7 +18,7 @@ export class DescriptionValueObject {
return this.description;
}

private isEmpty(name: string) {
return name.length === 0;
private isEmpty(name: string | undefined) {
return name === undefined || name.length === 0;
}
}
Loading

0 comments on commit 75e87ed

Please sign in to comment.