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

Move backend docu #16

Merged
merged 8 commits into from
Nov 22, 2023
Merged

Move backend docu #16

merged 8 commits into from
Nov 22, 2023

Conversation

Metauriel
Copy link
Contributor

Description

Links to Tickets or other pull requests

Changes

Datasecurity

Deployment

New Repos, NPM pakages or vendor scripts

Screenshots of UI changes

Approval for review

  • All points were discussed with the ticket creator, support-team or product owner. The code upholds all quality guidelines from the PR-template.

Notice: Please remove the WIP label if the PR is ready to review, otherwise nobody will review it.

The main responsibilities of a controller is to define the REST API interface as openAPI specification and map DTO's to match the logic layers interfaces.

```TypeScript
@Post()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it sense to also put a example line for expected errors open API definition.
Empty line between 15-16


## openAPI specification

Defining the request/response DTOs in a controller will define the openAPI specification automatically. Additional [validation rules](https://docs.nestjs.com/techniques/validation) and [openAPI definitions](https://docs.nestjs.com/openapi/decorators) can be added using decorators. For simplification, openAPI decorators should define a type and if a property is required, while additional decorators can be used from class-validator to validate content.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By any change of the API the vue client must be updated too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should that be part of the server docu? That the vue client is using a generated client seems to be a detail of the client to me, especially since the command has to be executed in the client repository.

Its also already documented here
https://documentation.dbildungscloud.dev/docs/nuxt-client/HowTo


## Mapping

It is forbidden, to directly pass a DTO to a use-case or return an Entity (or other use-case result) via REST. In-between a mapper must transform the given data, to protect the logic layer from outside implications.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not wrong, but a picture with overall layer structure + name defintitions + dependency & mappings make more sense like a text.


A specification checks if a domain object fulfills the conditions of the specification.

A specification can simply specify that a domain object is valid. E.g. a `Task` has an owner and a description.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any hind how we use it?
Use methods that do more like simple getter/setter (to make class cohesion vsisible), props a private. Only methods that can handle by the domain object. It is allow that other domain object can pass by in props, but should not generate a new one.

try {
someMethod();
} catch(error) {
throw new ForbiddenException('some message', { cause: error });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not work anymore. We has a ErrorUtil to pass the cause.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please put in a correct example

super();
}

getLogMessage(): ErrorLogMessage {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SevenWaysDP if i remember correct you had one PR for implement loggables with cause error in test and add this examples also to confluence or?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is is not up to date anymore.

```TypeScript
// doSomethingCrazy : Promise<retValue>
it('bad async sample', async function (done) => {
this.timeout(10000);
Copy link
Contributor

@CeEv CeEv Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. The timeout for a isolated test should be pass as 3. parameter. It is a bad example but not in case of this timeout.

You can create a mock using `createMock<Class>()`. As result you will recieved a `DeepMocked<Class>`

```Typescript
let fut: FeatureUnderTest;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not let stay featherJS examples inside to documentation. It not needed, for this show case.
The imports from golevelup should also be part of the example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean by feathers example?

describe('[method]', () => {
describe('when [senario description that is prepared in setup]', () => {
const setup = () => {
// prepare the data and mocks for this scenario
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I miss the part of deep mocked services should be mocked. Do not use Jest (expect it is a other method of the tested service in this file), use Once, use for async Resolve / Reject for syncron mockImplementation.


### Domain Layer

The Domain Layer contains the business logic of the application. As mentioned above, it is not allowed to know about anything outside the domain layer itself.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting UC and service in two layer. Nothing from UC should be importat into service layer.

@CeEv CeEv self-requested a review November 20, 2023 08:46
Copy link
Contributor

@CeEv CeEv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expect the comments.

describe('createCourse', () => {
// a "when..." sentence
describe("When a student tries to create a course", (() => {
// a "should..." sentence
Copy link
Contributor

@CeEv CeEv Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thint the const setup = () => is missed but maybe it is enough with the double explaination from line 76?

@Metauriel Metauriel merged commit 93eddc8 into main Nov 22, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants