Skip to content

Commit

Permalink
[chore] Fix up
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-kuznetsov-osome committed Apr 22, 2024
1 parent e9b4400 commit a7ac9c4
Showing 1 changed file with 34 additions and 32 deletions.
66 changes: 34 additions & 32 deletions src/backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ Table of contents can be generated in services like http://ecotrust-canada.githu

Project structure should follow next principles:

1. Not needed to move files without changing their purpose.

1. It's easy to identify a single place where a new file should be located.

1. It's easy to understand where to look files/functionality up.
Expand Down Expand Up @@ -116,36 +114,6 @@ Jobs directory structure example:
- user
- user.job.ts
- user.job.test.ts
- jobNames.ts
- jobHandlers.ts
```

`jobName.ts` - file which contains enum with all existing job names.

Example:

```ts
export enum JobName {
handleUserCreated = 'handleUserCreated',
handleUserUpdated = 'handleUserUpdated',
}
```

`jobHandlers.ts` - file which contains mapping between job names and their handler functions.

Example:

```ts
import { handleUserCreatedJob } from './user/handleUserCreated.job';
import { handleUserUpdatedJob } from './user/handleUserUpdated.job';
import { JobName } from './jobNames';

export function getJobFunctions() {
return {
[JobName.handleUserCreated]: handleUserCreatedJob,
[JobName.handleUserUpdated]: handleUserUpdatedJob,
};
}
```

#### lib directory
Expand Down Expand Up @@ -226,6 +194,40 @@ Services directory structure example:
- eventBus.service.ts
```

Also `src/services` directory can contain some specific files:

##### `src/services/jobNames.ts`

File which contains enum with all existing job names.

Example:

```ts
export enum JobName {
handleUserCreated = 'handleUserCreated',
handleUserUpdated = 'handleUserUpdated',
}
```

##### `src/services/jobHandlers.ts`

File which contains mapping between job names and their handler functions.

Example:

```ts
import { handleUserCreatedJob } from '../jobs/user/handleUserCreated.job';
import { handleUserUpdatedJob } from '../jobs/user/handleUserUpdated.job';
import { JobName } from './jobNames';

export function getJobFunctions() {
return {
[JobName.handleUserCreated]: handleUserCreatedJob,
[JobName.handleUserUpdated]: handleUserUpdatedJob,
};
}
```

#### tests directory

Contains nocks, seeds, fakes and other helpers for tests. Each type of test helpers should have it own file extension:
Expand Down

0 comments on commit a7ac9c4

Please sign in to comment.