@foal/cli 2.11.0 → 3.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/create-secret/create-secret.js +1 -1
- package/lib/generate/file-system.js +47 -47
- package/lib/generate/generators/angular/connect-angular.js +11 -12
- package/lib/generate/generators/app/create-app.js +11 -12
- package/lib/generate/generators/controller/create-controller.js +4 -4
- package/lib/generate/generators/entity/create-entity.js +2 -2
- package/lib/generate/generators/hook/create-hook.js +2 -2
- package/lib/generate/generators/index.d.ts +0 -1
- package/lib/generate/generators/index.js +5 -2
- package/lib/generate/generators/react/connect-react.js +3 -3
- package/lib/generate/generators/rest-api/create-rest-api.js +9 -5
- package/lib/generate/generators/script/create-script.js +1 -1
- package/lib/generate/generators/service/create-service.js +2 -2
- package/lib/generate/generators/vue/connect-vue.js +4 -4
- package/lib/generate/index.js +5 -1
- package/lib/generate/templates/app/.eslintrc.js +13 -14
- package/lib/generate/templates/app/package.json +17 -17
- package/lib/generate/templates/app/package.mongodb.json +13 -13
- package/lib/generate/templates/app/package.mongodb.yaml.json +13 -13
- package/lib/generate/templates/app/package.yaml.json +17 -17
- package/lib/generate/templates/app/src/app/app.controller.ts +0 -5
- package/lib/generate/templates/app/src/app/entities/user.entity.mongodb.ts +3 -14
- package/lib/generate/templates/app/src/app/entities/user.entity.ts +1 -12
- package/lib/generate/templates/app/src/db.ts +24 -0
- package/lib/generate/templates/app/src/e2e/index.ts +10 -2
- package/lib/generate/templates/app/src/index.ts +3 -0
- package/lib/generate/templates/app/src/scripts/create-user.ts +9 -13
- package/lib/generate/templates/app/tsconfig.json +3 -3
- package/lib/generate/templates/entity/entity.mongodb.ts +3 -3
- package/lib/generate/templates/rest-api/controllers/controller.auth.ts +15 -16
- package/lib/generate/templates/rest-api/controllers/controller.spec.auth.ts +27 -21
- package/lib/generate/templates/rest-api/controllers/controller.spec.ts +24 -16
- package/lib/generate/templates/rest-api/controllers/controller.ts +9 -10
- package/lib/generate/templates/script/script.ts +4 -14
- package/lib/generate/utils/init-git-repo.js +2 -2
- package/lib/generate/utils/mkdir-if-does-not-exist.js +2 -2
- package/lib/generate/utils/rm-dir-and-files-if-exist.js +6 -6
- package/lib/index.js +41 -41
- package/lib/rmdir/rmdir.util.js +5 -5
- package/lib/run-script/run-script.js +7 -7
- package/package.json +12 -12
- package/lib/generate/generators/vscode-config/create-vscode-config.d.ts +0 -1
- package/lib/generate/generators/vscode-config/create-vscode-config.js +0 -15
- package/lib/generate/generators/vscode-config/index.d.ts +0 -1
- package/lib/generate/generators/vscode-config/index.js +0 -5
- package/lib/generate/templates/app/ormconfig.js +0 -21
- package/lib/generate/templates/app/src/scripts/create-user.mongodb.ts +0 -38
- package/lib/generate/templates/vscode-config/launch.json +0 -54
- package/lib/generate/templates/vscode-config/tasks.json +0 -25
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
|
|
3
|
-
'browser': true,
|
|
4
|
-
'es6': true,
|
|
5
|
-
'node': true
|
|
6
|
-
},
|
|
7
|
-
extends: [
|
|
8
|
-
'eslint:recommended',
|
|
9
|
-
'plugin:@typescript-eslint/eslint-recommended',
|
|
10
|
-
'plugin:@typescript-eslint/recommended',
|
|
11
|
-
'plugin:@typescript-eslint/recommended-requiring-type-checking',
|
|
12
|
-
],
|
|
2
|
+
root: true,
|
|
13
3
|
parser: '@typescript-eslint/parser',
|
|
14
4
|
parserOptions: {
|
|
15
|
-
project: 'tsconfig.json',
|
|
16
5
|
tsconfigRootDir: __dirname,
|
|
17
|
-
|
|
6
|
+
project: ['./tsconfig.json'],
|
|
18
7
|
},
|
|
19
8
|
plugins: [
|
|
20
9
|
'@typescript-eslint'
|
|
21
10
|
],
|
|
11
|
+
extends: [
|
|
12
|
+
'eslint:recommended',
|
|
13
|
+
'plugin:@typescript-eslint/recommended',
|
|
14
|
+
'plugin:@typescript-eslint/recommended-requiring-type-checking',
|
|
15
|
+
],
|
|
22
16
|
rules: {
|
|
23
17
|
'@typescript-eslint/array-type': 'error',
|
|
24
18
|
'@typescript-eslint/explicit-member-accessibility': [
|
|
@@ -40,7 +34,12 @@ module.exports = {
|
|
|
40
34
|
'@typescript-eslint/no-unused-vars': ['error', { 'args': 'none' }],
|
|
41
35
|
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
42
36
|
'@typescript-eslint/require-await': 'off',
|
|
43
|
-
'@typescript-eslint/no-explicit-any': 'off'
|
|
37
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
38
|
+
'@typescript-eslint/no-unsafe-argument': 'off',
|
|
39
|
+
'@typescript-eslint/no-unsafe-assignment': 'off',
|
|
40
|
+
'@typescript-eslint/no-unsafe-call': 'off',
|
|
41
|
+
'@typescript-eslint/no-unsafe-member-access': 'off',
|
|
42
|
+
'@typescript-eslint/no-unsafe-return': 'off',
|
|
44
43
|
},
|
|
45
44
|
ignorePatterns: [
|
|
46
45
|
'src/migrations/*.ts'
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "foal rmdir build && tsc -p tsconfig.app.json",
|
|
9
9
|
"start": "node ./build/index.js",
|
|
10
|
-
"
|
|
10
|
+
"dev": "npm run build && concurrently -r \"tsc -p tsconfig.app.json -w\" \"supervisor -w ./build,./config -e js,json,yml --no-restart-on error ./build/index.js\"",
|
|
11
11
|
"build:test": "foal rmdir build && tsc -p tsconfig.test.json",
|
|
12
12
|
"start:test": "mocha --file ./build/test.js \"./build/**/*.spec.js\"",
|
|
13
13
|
"test": "npm run build:test && concurrently -r \"tsc -p tsconfig.test.json -w\" \"mocha --file ./build/test.js -w \\\"./build/**/*.spec.js\\\"\"",
|
|
@@ -16,31 +16,31 @@
|
|
|
16
16
|
"e2e": "npm run build:e2e && concurrently -r \"tsc -p tsconfig.e2e.json -w\" \"mocha --file ./build/e2e.js -w \\\"./build/e2e/**/*.js\\\"\"",
|
|
17
17
|
"lint": "eslint --ext ts src",
|
|
18
18
|
"lint:fix": "eslint --ext ts --fix src",
|
|
19
|
-
"makemigrations": "foal rmdir build && tsc -p tsconfig.app.json && npx typeorm migration:generate
|
|
20
|
-
"migrations": "npx typeorm migration:run",
|
|
21
|
-
"revertmigration": "npx typeorm migration:revert"
|
|
19
|
+
"makemigrations": "foal rmdir build && tsc -p tsconfig.app.json && npx typeorm migration:generate src/migrations/migration -d build/db -p && tsc -p tsconfig.app.json",
|
|
20
|
+
"migrations": "npx typeorm migration:run -d build/db",
|
|
21
|
+
"revertmigration": "npx typeorm migration:revert -d build/db"
|
|
22
22
|
},
|
|
23
23
|
"engines": {
|
|
24
|
-
"node": ">=
|
|
24
|
+
"node": ">=16.0.0"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@foal/core": "
|
|
28
|
-
"@foal/typeorm": "
|
|
29
|
-
"source-map-support": "~0.5.
|
|
30
|
-
"better-sqlite3": "~7.
|
|
31
|
-
"typeorm": "0.
|
|
27
|
+
"@foal/core": "3.0.0-alpha.1",
|
|
28
|
+
"@foal/typeorm": "3.0.0-alpha.1",
|
|
29
|
+
"source-map-support": "~0.5.21",
|
|
30
|
+
"better-sqlite3": "~7.6.2",
|
|
31
|
+
"typeorm": "0.3.10"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@foal/cli": "^2.9.0",
|
|
35
|
-
"@types/mocha": "
|
|
36
|
-
"@types/node": "
|
|
37
|
-
"concurrently": "~
|
|
35
|
+
"@types/mocha": "9.1.1",
|
|
36
|
+
"@types/node": "16.11.7",
|
|
37
|
+
"concurrently": "~7.2.2",
|
|
38
38
|
"mocha": "~8.2.0",
|
|
39
39
|
"supertest": "~6.2.3",
|
|
40
40
|
"supervisor": "~0.12.0",
|
|
41
|
-
"eslint": "
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "~
|
|
43
|
-
"@typescript-eslint/parser": "~
|
|
44
|
-
"typescript": "~4.
|
|
41
|
+
"eslint": "~8.17.0",
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "~5.27.1",
|
|
43
|
+
"@typescript-eslint/parser": "~5.27.1",
|
|
44
|
+
"typescript": "~4.7.4"
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "foal rmdir build && tsc -p tsconfig.app.json",
|
|
9
9
|
"start": "node ./build/index.js",
|
|
10
|
-
"
|
|
10
|
+
"dev": "npm run build && concurrently -r \"tsc -p tsconfig.app.json -w\" \"supervisor -w ./build,./config -e js,json,yml --no-restart-on error ./build/index.js\"",
|
|
11
11
|
"build:test": "foal rmdir build && tsc -p tsconfig.test.json",
|
|
12
12
|
"start:test": "mocha --file ./build/test.js \"./build/**/*.spec.js\"",
|
|
13
13
|
"test": "npm run build:test && concurrently -r \"tsc -p tsconfig.test.json -w\" \"mocha --file ./build/test.js -w \\\"./build/**/*.spec.js\\\"\"",
|
|
@@ -18,25 +18,25 @@
|
|
|
18
18
|
"lint:fix": "eslint --ext ts --fix src"
|
|
19
19
|
},
|
|
20
20
|
"engines": {
|
|
21
|
-
"node": ">=
|
|
21
|
+
"node": ">=16.0.0"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@foal/core": "
|
|
24
|
+
"@foal/core": "3.0.0-alpha.1",
|
|
25
25
|
"mongodb": "~3.7.3",
|
|
26
|
-
"source-map-support": "~0.5.
|
|
27
|
-
"typeorm": "0.
|
|
26
|
+
"source-map-support": "~0.5.21",
|
|
27
|
+
"typeorm": "0.3.10"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@foal/cli": "^2.9.0",
|
|
31
|
-
"@types/mocha": "
|
|
32
|
-
"@types/node": "
|
|
33
|
-
"concurrently": "~
|
|
31
|
+
"@types/mocha": "9.1.1",
|
|
32
|
+
"@types/node": "16.11.7",
|
|
33
|
+
"concurrently": "~7.2.2",
|
|
34
34
|
"mocha": "~8.2.0",
|
|
35
|
-
"supertest": "~6.
|
|
35
|
+
"supertest": "~6.2.3",
|
|
36
36
|
"supervisor": "~0.12.0",
|
|
37
|
-
"eslint": "
|
|
38
|
-
"@typescript-eslint/eslint-plugin": "~
|
|
39
|
-
"@typescript-eslint/parser": "~
|
|
40
|
-
"typescript": "~4.
|
|
37
|
+
"eslint": "~8.17.0",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "~5.27.1",
|
|
39
|
+
"@typescript-eslint/parser": "~5.27.1",
|
|
40
|
+
"typescript": "~4.7.4"
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "foal rmdir build && tsc -p tsconfig.app.json",
|
|
9
9
|
"start": "node ./build/index.js",
|
|
10
|
-
"
|
|
10
|
+
"dev": "npm run build && concurrently -r \"tsc -p tsconfig.app.json -w\" \"supervisor -w ./build,./config -e js,json,yml --no-restart-on error ./build/index.js\"",
|
|
11
11
|
"build:test": "foal rmdir build && tsc -p tsconfig.test.json",
|
|
12
12
|
"start:test": "mocha --file ./build/test.js \"./build/**/*.spec.js\"",
|
|
13
13
|
"test": "npm run build:test && concurrently -r \"tsc -p tsconfig.test.json -w\" \"mocha --file ./build/test.js -w \\\"./build/**/*.spec.js\\\"\"",
|
|
@@ -18,26 +18,26 @@
|
|
|
18
18
|
"lint:fix": "eslint --ext ts --fix src"
|
|
19
19
|
},
|
|
20
20
|
"engines": {
|
|
21
|
-
"node": ">=
|
|
21
|
+
"node": ">=16.0.0"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@foal/core": "
|
|
24
|
+
"@foal/core": "3.0.0-alpha.1",
|
|
25
25
|
"mongodb": "~3.7.3",
|
|
26
|
-
"source-map-support": "~0.5.
|
|
27
|
-
"typeorm": "0.
|
|
26
|
+
"source-map-support": "~0.5.21",
|
|
27
|
+
"typeorm": "0.3.10",
|
|
28
28
|
"yamljs": "~0.3.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@foal/cli": "^2.9.0",
|
|
32
|
-
"@types/mocha": "
|
|
33
|
-
"@types/node": "
|
|
34
|
-
"concurrently": "~
|
|
32
|
+
"@types/mocha": "9.1.1",
|
|
33
|
+
"@types/node": "16.11.7",
|
|
34
|
+
"concurrently": "~7.2.2",
|
|
35
35
|
"mocha": "~8.2.0",
|
|
36
|
-
"supertest": "~6.
|
|
36
|
+
"supertest": "~6.2.3",
|
|
37
37
|
"supervisor": "~0.12.0",
|
|
38
|
-
"eslint": "
|
|
39
|
-
"@typescript-eslint/eslint-plugin": "~
|
|
40
|
-
"@typescript-eslint/parser": "~
|
|
41
|
-
"typescript": "~4.
|
|
38
|
+
"eslint": "~8.17.0",
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "~5.27.1",
|
|
40
|
+
"@typescript-eslint/parser": "~5.27.1",
|
|
41
|
+
"typescript": "~4.7.4"
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "foal rmdir build && tsc -p tsconfig.app.json",
|
|
9
9
|
"start": "node ./build/index.js",
|
|
10
|
-
"
|
|
10
|
+
"dev": "npm run build && concurrently -r \"tsc -p tsconfig.app.json -w\" \"supervisor -w ./build,./config -e js,json,yml --no-restart-on error ./build/index.js\"",
|
|
11
11
|
"build:test": "foal rmdir build && tsc -p tsconfig.test.json",
|
|
12
12
|
"start:test": "mocha --file ./build/test.js \"./build/**/*.spec.js\"",
|
|
13
13
|
"test": "npm run build:test && concurrently -r \"tsc -p tsconfig.test.json -w\" \"mocha --file ./build/test.js -w \\\"./build/**/*.spec.js\\\"\"",
|
|
@@ -16,32 +16,32 @@
|
|
|
16
16
|
"e2e": "npm run build:e2e && concurrently -r \"tsc -p tsconfig.e2e.json -w\" \"mocha --file ./build/e2e.js -w \\\"./build/e2e/**/*.js\\\"\"",
|
|
17
17
|
"lint": "eslint --ext ts src",
|
|
18
18
|
"lint:fix": "eslint --ext ts --fix src",
|
|
19
|
-
"makemigrations": "foal rmdir build && tsc -p tsconfig.app.json && npx typeorm migration:generate
|
|
20
|
-
"migrations": "npx typeorm migration:run",
|
|
21
|
-
"revertmigration": "npx typeorm migration:revert"
|
|
19
|
+
"makemigrations": "foal rmdir build && tsc -p tsconfig.app.json && npx typeorm migration:generate src/migrations/migration -d build/db -p && tsc -p tsconfig.app.json",
|
|
20
|
+
"migrations": "npx typeorm migration:run -d build/db",
|
|
21
|
+
"revertmigration": "npx typeorm migration:revert -d build/db"
|
|
22
22
|
},
|
|
23
23
|
"engines": {
|
|
24
|
-
"node": ">=
|
|
24
|
+
"node": ">=16.0.0"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@foal/core": "
|
|
28
|
-
"@foal/typeorm": "
|
|
29
|
-
"source-map-support": "~0.5.
|
|
27
|
+
"@foal/core": "3.0.0-alpha.1",
|
|
28
|
+
"@foal/typeorm": "3.0.0-alpha.1",
|
|
29
|
+
"source-map-support": "~0.5.21",
|
|
30
30
|
"better-sqlite3": "~7.5.0",
|
|
31
|
-
"typeorm": "0.
|
|
31
|
+
"typeorm": "0.3.10",
|
|
32
32
|
"yamljs": "~0.3.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@foal/cli": "^2.9.0",
|
|
36
|
-
"@types/mocha": "
|
|
37
|
-
"@types/node": "
|
|
38
|
-
"concurrently": "~
|
|
36
|
+
"@types/mocha": "9.1.1",
|
|
37
|
+
"@types/node": "16.11.7",
|
|
38
|
+
"concurrently": "~7.2.2",
|
|
39
39
|
"mocha": "~8.2.0",
|
|
40
|
-
"supertest": "~6.
|
|
40
|
+
"supertest": "~6.2.3",
|
|
41
41
|
"supervisor": "~0.12.0",
|
|
42
|
-
"eslint": "
|
|
43
|
-
"@typescript-eslint/eslint-plugin": "~
|
|
44
|
-
"@typescript-eslint/parser": "~
|
|
45
|
-
"typescript": "~4.
|
|
42
|
+
"eslint": "~8.17.0",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "~5.27.1",
|
|
44
|
+
"@typescript-eslint/parser": "~5.27.1",
|
|
45
|
+
"typescript": "~4.7.4"
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { controller, IAppController } from '@foal/core';
|
|
2
|
-
import { createConnection } from 'typeorm';
|
|
3
2
|
|
|
4
3
|
import { ApiController } from './controllers';
|
|
5
4
|
|
|
@@ -7,8 +6,4 @@ export class AppController implements IAppController {
|
|
|
7
6
|
subControllers = [
|
|
8
7
|
controller('/api', ApiController),
|
|
9
8
|
];
|
|
10
|
-
|
|
11
|
-
async init() {
|
|
12
|
-
await createConnection();
|
|
13
|
-
}
|
|
14
9
|
}
|
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import { /*Column, */Entity, ObjectID, ObjectIdColumn } from 'typeorm';
|
|
1
|
+
import { BaseEntity, Entity, ObjectID, ObjectIdColumn } from 'typeorm';
|
|
3
2
|
|
|
4
3
|
@Entity()
|
|
5
|
-
export class User {
|
|
4
|
+
export class User extends BaseEntity {
|
|
6
5
|
|
|
7
6
|
@ObjectIdColumn()
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// @Column({ unique: true })
|
|
11
|
-
// email: string;
|
|
12
|
-
|
|
13
|
-
// @Column()
|
|
14
|
-
// password: string;
|
|
15
|
-
|
|
16
|
-
// async setPassword(password: string) {
|
|
17
|
-
// this.password = await hashPassword(password);
|
|
18
|
-
// }
|
|
7
|
+
_id: ObjectID;
|
|
19
8
|
|
|
20
9
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { BaseEntity, /*Column, */Entity, PrimaryGeneratedColumn } from 'typeorm';
|
|
1
|
+
import { BaseEntity, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
|
3
2
|
|
|
4
3
|
@Entity()
|
|
5
4
|
export class User extends BaseEntity {
|
|
@@ -7,14 +6,4 @@ export class User extends BaseEntity {
|
|
|
7
6
|
@PrimaryGeneratedColumn()
|
|
8
7
|
id: number;
|
|
9
8
|
|
|
10
|
-
// @Column({ unique: true })
|
|
11
|
-
// email: string;
|
|
12
|
-
|
|
13
|
-
// @Column()
|
|
14
|
-
// password: string;
|
|
15
|
-
|
|
16
|
-
// async setPassword(password: string) {
|
|
17
|
-
// this.password = await hashPassword(password);
|
|
18
|
-
// }
|
|
19
|
-
|
|
20
9
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
import { Config } from '@foal/core';
|
|
3
|
+
import { DataSource } from 'typeorm';
|
|
4
|
+
|
|
5
|
+
export function createDataSource(): DataSource {
|
|
6
|
+
return new DataSource({
|
|
7
|
+
type: Config.getOrThrow('database.type', 'string') as any,
|
|
8
|
+
|
|
9
|
+
url: Config.get('database.url', 'string'),
|
|
10
|
+
host: Config.get('database.host', 'string'),
|
|
11
|
+
port: Config.get('database.port', 'number'),
|
|
12
|
+
username: Config.get('database.username', 'string'),
|
|
13
|
+
password: Config.get('database.password', 'string'),
|
|
14
|
+
database: Config.get('database.database', 'string'),
|
|
15
|
+
|
|
16
|
+
dropSchema: Config.get('database.dropSchema', 'boolean', false),
|
|
17
|
+
synchronize: Config.get('database.synchronize', 'boolean', false),
|
|
18
|
+
|
|
19
|
+
entities: ['build/app/**/*.entity.js'],
|
|
20
|
+
migrations: ['build/migrations/*.js'],
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const dataSource = createDataSource();
|
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
// 3p
|
|
2
2
|
import { createApp } from '@foal/core';
|
|
3
3
|
import * as request from 'supertest';
|
|
4
|
-
import {
|
|
4
|
+
import { DataSource } from 'typeorm';
|
|
5
5
|
|
|
6
6
|
// App
|
|
7
7
|
import { AppController } from '../app/app.controller';
|
|
8
|
+
import { createDataSource } from '../db';
|
|
8
9
|
|
|
9
10
|
describe('The server', () => {
|
|
10
11
|
|
|
11
12
|
let app;
|
|
13
|
+
let dataSource: DataSource;
|
|
12
14
|
|
|
13
15
|
before(async () => {
|
|
14
16
|
app = await createApp(AppController);
|
|
17
|
+
dataSource = createDataSource();
|
|
18
|
+
await dataSource.initialize();
|
|
15
19
|
});
|
|
16
20
|
|
|
17
|
-
after(() =>
|
|
21
|
+
after(async () => {
|
|
22
|
+
if (dataSource) {
|
|
23
|
+
await dataSource.destroy();
|
|
24
|
+
}
|
|
25
|
+
});
|
|
18
26
|
|
|
19
27
|
it('should return a 200 status on GET / requests.', () => {
|
|
20
28
|
return request(app)
|
|
@@ -5,8 +5,11 @@ import { Config, createApp, displayServerURL } from '@foal/core';
|
|
|
5
5
|
|
|
6
6
|
// App
|
|
7
7
|
import { AppController } from './app/app.controller';
|
|
8
|
+
import { dataSource } from './db';
|
|
8
9
|
|
|
9
10
|
async function main() {
|
|
11
|
+
await dataSource.initialize();
|
|
12
|
+
|
|
10
13
|
const app = await createApp(AppController);
|
|
11
14
|
|
|
12
15
|
const port = Config.get('port', 'number', 3001);
|
|
@@ -1,32 +1,28 @@
|
|
|
1
|
-
// 3p
|
|
2
|
-
// import { hashPassword } from '@foal/core';
|
|
3
|
-
import { createConnection } from 'typeorm';
|
|
4
|
-
|
|
5
1
|
// App
|
|
6
2
|
import { User } from '../app/entities';
|
|
3
|
+
import { dataSource } from '../db';
|
|
7
4
|
|
|
8
5
|
export const schema = {
|
|
9
6
|
additionalProperties: false,
|
|
10
7
|
properties: {
|
|
11
|
-
|
|
12
|
-
// password: { type: 'string' },
|
|
8
|
+
|
|
13
9
|
},
|
|
14
|
-
required: [
|
|
10
|
+
required: [
|
|
11
|
+
|
|
12
|
+
],
|
|
15
13
|
type: 'object',
|
|
16
14
|
};
|
|
17
15
|
|
|
18
|
-
export async function main(
|
|
19
|
-
|
|
16
|
+
export async function main() {
|
|
17
|
+
await dataSource.initialize();
|
|
20
18
|
|
|
21
19
|
try {
|
|
22
20
|
const user = new User();
|
|
23
|
-
// user.email = args.email;
|
|
24
|
-
// user.password = await hashPassword(args.password);
|
|
25
21
|
|
|
26
22
|
console.log(await user.save());
|
|
27
23
|
} catch (error: any) {
|
|
28
|
-
console.
|
|
24
|
+
console.error(error.message);
|
|
29
25
|
} finally {
|
|
30
|
-
await
|
|
26
|
+
await dataSource.destroy();
|
|
31
27
|
}
|
|
32
28
|
}
|
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
"noImplicitAny": false,
|
|
9
9
|
"strictPropertyInitialization": false,
|
|
10
10
|
"module": "commonjs",
|
|
11
|
-
"target": "
|
|
11
|
+
"target": "es2021",
|
|
12
12
|
"rootDir": "src",
|
|
13
13
|
"lib": [
|
|
14
|
-
"
|
|
14
|
+
"es2021",
|
|
15
15
|
"dom"
|
|
16
16
|
]
|
|
17
17
|
},
|
|
18
18
|
"include": [
|
|
19
19
|
"src/**/*.ts"
|
|
20
20
|
]
|
|
21
|
-
}
|
|
21
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2
|
-
import { Column, Entity, ObjectID, ObjectIdColumn } from 'typeorm';
|
|
2
|
+
import { BaseEntity, Column, Entity, ObjectID, ObjectIdColumn } from 'typeorm';
|
|
3
3
|
|
|
4
4
|
@Entity()
|
|
5
|
-
export class /* upperFirstCamelName */ {
|
|
5
|
+
export class /* upperFirstCamelName */ extends BaseEntity {
|
|
6
6
|
|
|
7
7
|
@ObjectIdColumn()
|
|
8
|
-
|
|
8
|
+
_id: ObjectID;
|
|
9
9
|
|
|
10
10
|
}
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
HttpResponseNoContent, HttpResponseNotFound, HttpResponseOK, Patch, Post,
|
|
5
5
|
Put, ValidateBody, ValidatePathParam, ValidateQueryParam
|
|
6
6
|
} from '@foal/core';
|
|
7
|
-
import { getRepository } from 'typeorm';
|
|
8
7
|
|
|
9
8
|
import { /* upperFirstCamelName */, User } from '/* entitiesPath */';
|
|
10
9
|
|
|
@@ -32,11 +31,11 @@ export class /* upperFirstCamelName */Controller {
|
|
|
32
31
|
@ValidateQueryParam('skip', { type: 'number' }, { required: false })
|
|
33
32
|
@ValidateQueryParam('take', { type: 'number' }, { required: false })
|
|
34
33
|
async find/* upperFirstCamelName */s(ctx: Context<User>) {
|
|
35
|
-
const /* camelName */s = await
|
|
34
|
+
const /* camelName */s = await /* upperFirstCamelName */.find({
|
|
36
35
|
skip: ctx.request.query.skip,
|
|
37
36
|
take: ctx.request.query.take,
|
|
38
37
|
where: {
|
|
39
|
-
owner: ctx.user
|
|
38
|
+
owner: { id: ctx.user.id }
|
|
40
39
|
}
|
|
41
40
|
});
|
|
42
41
|
return new HttpResponseOK(/* camelName */s);
|
|
@@ -49,9 +48,9 @@ export class /* upperFirstCamelName */Controller {
|
|
|
49
48
|
@ApiResponse(200, { description: 'Returns the /* camelName */.' })
|
|
50
49
|
@ValidatePathParam('/* camelName */Id', { type: 'number' })
|
|
51
50
|
async find/* upperFirstCamelName */ById(ctx: Context<User>) {
|
|
52
|
-
const /* camelName */ = await
|
|
51
|
+
const /* camelName */ = await /* upperFirstCamelName */.findOneBy({
|
|
53
52
|
id: ctx.request.params./* camelName */Id,
|
|
54
|
-
owner: ctx.user
|
|
53
|
+
owner: { id: ctx.user.id }
|
|
55
54
|
});
|
|
56
55
|
|
|
57
56
|
if (!/* camelName */) {
|
|
@@ -68,9 +67,9 @@ export class /* upperFirstCamelName */Controller {
|
|
|
68
67
|
@ApiResponse(201, { description: '/* upperFirstCamelName */ successfully created. Returns the /* camelName */.' })
|
|
69
68
|
@ValidateBody(/* camelName */Schema)
|
|
70
69
|
async create/* upperFirstCamelName */(ctx: Context<User>) {
|
|
71
|
-
const /* camelName */ = await
|
|
70
|
+
const /* camelName */ = await /* upperFirstCamelName */.save({
|
|
72
71
|
...ctx.request.body,
|
|
73
|
-
owner: ctx.user
|
|
72
|
+
owner: { id: ctx.user.id }
|
|
74
73
|
});
|
|
75
74
|
return new HttpResponseCreated(/* camelName */);
|
|
76
75
|
}
|
|
@@ -84,9 +83,9 @@ export class /* upperFirstCamelName */Controller {
|
|
|
84
83
|
@ValidatePathParam('/* camelName */Id', { type: 'number' })
|
|
85
84
|
@ValidateBody({ .../* camelName */Schema, required: [] })
|
|
86
85
|
async modify/* upperFirstCamelName */(ctx: Context<User>) {
|
|
87
|
-
const /* camelName */ = await
|
|
86
|
+
const /* camelName */ = await /* upperFirstCamelName */.findOneBy({
|
|
88
87
|
id: ctx.request.params./* camelName */Id,
|
|
89
|
-
owner: ctx.user
|
|
88
|
+
owner: { id: ctx.user.id }
|
|
90
89
|
});
|
|
91
90
|
|
|
92
91
|
if (!/* camelName */) {
|
|
@@ -95,7 +94,7 @@ export class /* upperFirstCamelName */Controller {
|
|
|
95
94
|
|
|
96
95
|
Object.assign(/* camelName */, ctx.request.body);
|
|
97
96
|
|
|
98
|
-
await
|
|
97
|
+
await /* upperFirstCamelName */.save(/* camelName */);
|
|
99
98
|
|
|
100
99
|
return new HttpResponseOK(/* camelName */);
|
|
101
100
|
}
|
|
@@ -109,9 +108,9 @@ export class /* upperFirstCamelName */Controller {
|
|
|
109
108
|
@ValidatePathParam('/* camelName */Id', { type: 'number' })
|
|
110
109
|
@ValidateBody(/* camelName */Schema)
|
|
111
110
|
async replace/* upperFirstCamelName */(ctx: Context<User>) {
|
|
112
|
-
const /* camelName */ = await
|
|
111
|
+
const /* camelName */ = await /* upperFirstCamelName */.findOneBy({
|
|
113
112
|
id: ctx.request.params./* camelName */Id,
|
|
114
|
-
owner: ctx.user
|
|
113
|
+
owner: { id: ctx.user.id }
|
|
115
114
|
});
|
|
116
115
|
|
|
117
116
|
if (!/* camelName */) {
|
|
@@ -120,7 +119,7 @@ export class /* upperFirstCamelName */Controller {
|
|
|
120
119
|
|
|
121
120
|
Object.assign(/* camelName */, ctx.request.body);
|
|
122
121
|
|
|
123
|
-
await
|
|
122
|
+
await /* upperFirstCamelName */.save(/* camelName */);
|
|
124
123
|
|
|
125
124
|
return new HttpResponseOK(/* camelName */);
|
|
126
125
|
}
|
|
@@ -132,16 +131,16 @@ export class /* upperFirstCamelName */Controller {
|
|
|
132
131
|
@ApiResponse(204, { description: '/* upperFirstCamelName */ successfully deleted.' })
|
|
133
132
|
@ValidatePathParam('/* camelName */Id', { type: 'number' })
|
|
134
133
|
async delete/* upperFirstCamelName */(ctx: Context<User>) {
|
|
135
|
-
const /* camelName */ = await
|
|
134
|
+
const /* camelName */ = await /* upperFirstCamelName */.findOneBy({
|
|
136
135
|
id: ctx.request.params./* camelName */Id,
|
|
137
|
-
owner: ctx.user
|
|
136
|
+
owner: { id: ctx.user.id }
|
|
138
137
|
});
|
|
139
138
|
|
|
140
139
|
if (!/* camelName */) {
|
|
141
140
|
return new HttpResponseNotFound();
|
|
142
141
|
}
|
|
143
142
|
|
|
144
|
-
await
|
|
143
|
+
await /* upperFirstCamelName */.delete({ id: ctx.request.params./* camelName */Id });
|
|
145
144
|
|
|
146
145
|
return new HttpResponseNoContent();
|
|
147
146
|
}
|