Skip to content

Commit b59243d

Browse files
author
hirsch88
committed
Merge branch 'feature/v3' of github.com:w3tecch/express-typescript-boilerplate into feature/v3
2 parents 6b3d6c9 + 872203d commit b59243d

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

README.md

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ How does it work? Just, create a factory for your entities and a seeds script.
247247
248248
### 1. Create a factory for your entity
249249
250-
For all the entities we want to seed we need to define a factory. To do so we give you awesome the [faker](https://github.com/marak/Faker.js/) library. The create a new "fake" entity and return it. Those file should be in the `src/database/factories` folder and suffixed with `Factory`. Example `src/database/factories/UserFactory.ts`.
250+
For all the entities we want to seed, we need to define a factory. To do so we give you the awesome [faker](https://github.com/marak/Faker.js/) library as a parameter into your factory. Then create your "fake" entity as you would normally do and return it. Those factory files should be in the `src/database/factories` folder and suffixed with `Factory`. Example `src/database/factories/UserFactory.ts`.
251251
252252
```typescript
253253
factory.define(User, (faker: typeof Faker) => {
@@ -293,25 +293,18 @@ export class CreateUsers implements SeedsInterface {
293293
}
294294
```
295295
296-
Another example for nested entities. For that we use the each function to so.
296+
Here an example with nested factories.
297297
298298
```typescript
299299
...
300-
await factory.get(Tournament, 2)
301-
.each(async (tournament: Tournament) => {
300+
await factory.get(User)
301+
.each(async (user: User) => {
302302

303-
const teams: Team[] = await factory.get(Team)
304-
.each(async (team: Team) => {
303+
const pets: Pet[] = await factory.get(Pet)
304+
.create(2);
305305

306-
const users: User[] = await factory.get(User).create(2);
307-
const userIds = users.map((u: User) => u.Id);
308-
await team.users().attach(userIds);
309-
310-
})
311-
.create(getRandomNumber(tournament.MaxSize));
312-
313-
const teamIds = teams.map((t: Team) => t.Id);
314-
await tournament.teams().attach(teamIds);
306+
const petIds = pets.map((pet: Pet) => pet.Id);
307+
await user.pets().attach(petIds);
315308

316309
})
317310
.create(5);

src/lib/seeds/connection.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ const logging = args.indexOf('--logging') >= 0 || args.indexOf('-L') >= 0 || fal
1010
const configParam = '--config';
1111
const hasConfigPath = args.indexOf(configParam) >= 0 || false;
1212
const indexOfConfigPath = args.indexOf(configParam) + 1;
13-
const ormconfig = (hasConfigPath)
14-
? require(`${args[indexOfConfigPath]}`)
15-
: require(`${runDir}/ormconfig.json`);
1613

1714
/**
1815
* Returns a TypeORM database connection for our entity-manager
1916
*/
2017
export const getConnection = async (): Promise<Connection | undefined> => {
18+
19+
const ormconfig = (hasConfigPath)
20+
? require(`${args[indexOfConfigPath]}`)
21+
: require(`${runDir}/ormconfig.json`);
22+
2123
try {
2224
const connection = await createConnection({
2325
type: (ormconfig as any).type as any,

tslint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
160
77
],
88
"no-unnecessary-initializer": false,
9-
"no-var-requires": false,
9+
"no-var-requires": true,
1010
"no-null-keyword": true,
1111
"no-consecutive-blank-lines": false,
1212
"quotemark": [

0 commit comments

Comments
 (0)