Skip to content

Commit e7f37d8

Browse files
committed
refactor: create helper
project for test and utils and database
1 parent eadcc51 commit e7f37d8

File tree

98 files changed

+4331
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+4331
-0
lines changed

apps/json-api-front/.eslintrc.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"extends": ["../../.eslintrc.base.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts"],
7+
"extends": [
8+
"plugin:@nx/angular",
9+
"plugin:@angular-eslint/template/process-inline-templates"
10+
],
11+
"rules": {
12+
"@angular-eslint/directive-selector": [
13+
"error",
14+
{
15+
"type": "attribute",
16+
"prefix": "nestjsJsonApi",
17+
"style": "camelCase"
18+
}
19+
],
20+
"@angular-eslint/component-selector": [
21+
"error",
22+
{
23+
"type": "element",
24+
"prefix": "nestjs-json-api",
25+
"style": "kebab-case"
26+
}
27+
]
28+
}
29+
},
30+
{
31+
"files": ["*.html"],
32+
"extends": ["plugin:@nx/angular-template"],
33+
"rules": {}
34+
}
35+
]
36+
}

apps/json-api-front/jest.config.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-disable */
2+
export default {
3+
displayName: 'json-api-front',
4+
preset: '../../jest.preset.js',
5+
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
6+
coverageDirectory: '../../coverage/apps/json-api-front',
7+
transform: {
8+
'^.+\\.(ts|mjs|js|html)$': [
9+
'jest-preset-angular',
10+
{
11+
tsconfig: '<rootDir>/tsconfig.spec.json',
12+
stringifyContentPathRegex: '\\.(html|svg)$',
13+
},
14+
],
15+
},
16+
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
17+
snapshotSerializers: [
18+
'jest-preset-angular/build/serializers/no-ng-attributes',
19+
'jest-preset-angular/build/serializers/ng-snapshot',
20+
'jest-preset-angular/build/serializers/html-comment',
21+
],
22+
};

apps/json-api-front/project.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"name": "json-api-front",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"projectType": "application",
5+
"prefix": "nestjs-json-api",
6+
"sourceRoot": "apps/json-api-front/src",
7+
"tags": [],
8+
"targets": {
9+
"build": {
10+
"executor": "@angular-devkit/build-angular:application",
11+
"outputs": ["{options.outputPath}"],
12+
"options": {
13+
"outputPath": "dist/apps/json-api-front",
14+
"index": "apps/json-api-front/src/index.html",
15+
"browser": "apps/json-api-front/src/main.ts",
16+
"polyfills": ["zone.js"],
17+
"tsConfig": "apps/json-api-front/tsconfig.app.json",
18+
"assets": [
19+
"apps/json-api-front/src/favicon.ico",
20+
"apps/json-api-front/src/assets"
21+
],
22+
"styles": ["apps/json-api-front/src/styles.css"],
23+
"scripts": []
24+
},
25+
"configurations": {
26+
"production": {
27+
"budgets": [
28+
{
29+
"type": "initial",
30+
"maximumWarning": "500kb",
31+
"maximumError": "1mb"
32+
},
33+
{
34+
"type": "anyComponentStyle",
35+
"maximumWarning": "2kb",
36+
"maximumError": "4kb"
37+
}
38+
],
39+
"outputHashing": "all"
40+
},
41+
"development": {
42+
"optimization": false,
43+
"extractLicenses": false,
44+
"sourceMap": true
45+
}
46+
},
47+
"defaultConfiguration": "production"
48+
},
49+
"serve": {
50+
"executor": "@angular-devkit/build-angular:dev-server",
51+
"options": {
52+
"port": 4200,
53+
"proxyConfig": "apps/json-api-front/proxy.conf.json"
54+
},
55+
"configurations": {
56+
"production": {
57+
"buildTarget": "json-api-front:build:production"
58+
},
59+
"development": {
60+
"buildTarget": "json-api-front:build:development"
61+
}
62+
},
63+
"defaultConfiguration": "development"
64+
},
65+
"extract-i18n": {
66+
"executor": "@angular-devkit/build-angular:extract-i18n",
67+
"options": {
68+
"buildTarget": "json-api-front:build"
69+
}
70+
}
71+
}
72+
}

apps/json-api-front/proxy.conf.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"/api": {
3+
"target": "http://localhost:3000",
4+
"secure": false
5+
}
6+
}

apps/json-api-front/src/app/app.component.css

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<nestjs-json-api-nx-welcome></nestjs-json-api-nx-welcome>
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { Component, inject, OnInit } from '@angular/core';
2+
import { NxWelcomeComponent } from './nx-welcome.component';
3+
import { JsonApiSdkService } from 'json-api-nestjs-sdk';
4+
import { AtomicFactory } from 'json-api-nestjs-sdk/json-api-nestjs-sdk.module';
5+
import { switchMap } from 'rxjs';
6+
7+
@Component({
8+
standalone: true,
9+
imports: [NxWelcomeComponent],
10+
selector: 'nestjs-json-api-root',
11+
templateUrl: './app.component.html',
12+
styleUrl: './app.component.css',
13+
})
14+
export class AppComponent implements OnInit {
15+
private JsonApiSdkService = inject(JsonApiSdkService);
16+
private atomicFactory = inject(AtomicFactory);
17+
18+
ngOnInit(): void {
19+
// this.JsonApiSdkService.getAll(class Users {}, {
20+
// page: {
21+
// size: 2,
22+
// number: 1,
23+
// },
24+
// }).subscribe((r) => console.log(r));
25+
26+
class Addresses {
27+
id = 1;
28+
}
29+
30+
class Users {
31+
id!: number;
32+
addresses = new Addresses();
33+
login!: string;
34+
firstName!: string;
35+
lastName!: string;
36+
roles!: Roles[];
37+
}
38+
39+
class Roles {
40+
public id!: number;
41+
42+
public name!: string;
43+
44+
public key!: string;
45+
46+
public isDefault!: boolean;
47+
48+
public createdAt!: Date;
49+
50+
public updatedAt!: Date;
51+
52+
public users!: Users[];
53+
}
54+
55+
const tmpUsers = new Users();
56+
tmpUsers.id = 1;
57+
// this.JsonApiSdkService.getRelationships(tmpUsers, 'addresses').subscribe(
58+
// (r) => console.log(r)
59+
// );
60+
61+
const roles = new Roles();
62+
roles.id = 10000;
63+
roles.name = 'testRolesAgain';
64+
roles.key = 'testRolesAgain';
65+
const newUser = new Users();
66+
newUser.addresses = new Addresses();
67+
newUser.roles = [roles];
68+
newUser.login = 'newLogin';
69+
70+
this.atomicFactory()
71+
.postOne(roles)
72+
.postOne(newUser)
73+
.run()
74+
.pipe(
75+
switchMap((r) => {
76+
const [roles, user] = r;
77+
user.login = 'newUser';
78+
user.firstName = '';
79+
user.lastName = '';
80+
newUser.id = user.id;
81+
newUser.roles = [roles];
82+
return this.atomicFactory()
83+
.patchOne(user)
84+
.deleteRelationships(newUser, 'roles')
85+
.deleteOne(user)
86+
.deleteOne(roles)
87+
.run();
88+
})
89+
)
90+
.subscribe((r) => console.log(r));
91+
}
92+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ApplicationConfig, importProvidersFrom } from '@angular/core';
2+
import { JsonApiAngular } from 'json-api-nestjs-sdk/json-api-nestjs-sdk.module';
3+
4+
export const appConfig: ApplicationConfig = {
5+
providers: [
6+
importProvidersFrom(
7+
JsonApiAngular.forRoot({
8+
apiHost: 'http://localhost:4200',
9+
idKey: 'id',
10+
apiPrefix: 'api',
11+
operationUrl: 'operation',
12+
})
13+
),
14+
],
15+
};

0 commit comments

Comments
 (0)