@lenne.tech/cli 0.0.82 → 0.0.85

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.
@@ -0,0 +1,100 @@
1
+ # <%= props.name %>
2
+
3
+ This is a [lerna](https://lerna.js.org/) [Monorepro](https://monorepo.tools) for App ([Angular](https://angular.io)) and API ([NestJS](https://nestjs.com)).
4
+ Build with [NgBaseStarter](https://github.com/lenneTech/ng-base-starter) and [Starter for Nest Server](https://github.com/lenneTech/nest-server-starter)
5
+ via [CLI](https://github.com/lenneTech/cli).
6
+
7
+ If you are not yet familiar with Angular or NestJS, we recommend you to have a look at the following sections of our
8
+ academy [lenne.Learning](https://lennelearning.de):
9
+ - [Angular](https://lennelearning.de/lernpfad/angular)
10
+ - [NestJS](https://lennelearning.de/lernpfad/nestjs)
11
+
12
+ ## Requirements
13
+
14
+ - [Node.js incl. npm](https://nodejs.org):
15
+ the runtime environment for your server
16
+
17
+ - [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git):
18
+ the version control system for your source code
19
+
20
+ - [MongoDB](https://docs.mongodb.com/manual/installation/#mongodb-community-edition-installation-tutorials)
21
+ (or any other database compatible with [MikroORM](https://mikro-orm.io)):
22
+ the database for your objects
23
+
24
+ Installation on MacOS:
25
+ ```
26
+ /bin/bash -c "$(curl - fsSL https: //raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
27
+ brew tap mongodb/brew
28
+ brew update
29
+ brew install mongodb-community@6.O
30
+ brew services start mongodb
31
+ brew install node
32
+ npm install -g n
33
+ ```
34
+
35
+ To check if all requirements are met, we can display the versions of the respective software
36
+ (the version may differ from your versions in the following example):
37
+ ```
38
+ mongod --version
39
+ db version v6.0.1
40
+ Build Info: {
41
+ "version": "6.0.1",
42
+ "gitVersion": "32f0f9c88dc44a2c8073a5bd47cf779d4bfdee6b",
43
+ "modules": [],
44
+ "allocator": "system",
45
+ "environment": {
46
+ "distarch": "aarch64",
47
+ "target_arch": "aarch64"
48
+ }
49
+ }
50
+
51
+ node -v
52
+ v16.17.0
53
+
54
+ npm -v
55
+ 8.15.0
56
+ ```
57
+
58
+ ## Initialization of a local instance
59
+
60
+ Clone this repository and install packages:
61
+ ```
62
+ git clone <%= props.repository %>
63
+ cd <%= props.nameKebab %>
64
+ npm i
65
+ ```
66
+
67
+ ## Testing
68
+
69
+ Check if the requirements are met by running the tests (in the root directory):
70
+ ```
71
+ npm test
72
+ ```
73
+
74
+ ## Start
75
+
76
+ Both the app and the API are started with the following command (in the root directory):
77
+ ```
78
+ npm start
79
+ ```
80
+
81
+ The following URLs are then accessible:
82
+
83
+ - App: http://localhost:4200
84
+ - Documentation of the API: http://localhost:3000
85
+ - Playground for using the API: http://localhost:3000/graphql
86
+
87
+ If a URL is not reachable, it may be due to an error in the source code or because another process is already
88
+ occupying the corresponding port (3000 / 4200). In this case you can either stop the other process or set another
89
+ port in the configuration of the app or server.
90
+
91
+ ## Architecture
92
+
93
+ The architecture of the projects is based on the following structures:
94
+ - Both the app and the API can be found with their respective dependencies in the `projects` directory
95
+ - Both technologies are still compatible with their own CLI ([Angular CLI](angular cli) / [NestJS CLI](https://docs.nestjs.com/cli/overview))
96
+ - The [lt CLI](https://github.com/lenneTech/cli) also offers a few benefits regarding the extensions [NgBaseStarter](https://github.com/lenneTech/ng-base-starter) and [Starter for Nest Server](https://github.com/lenneTech/nest-server-starter)
97
+ - To organize the monorepro [lerna](https://lerna.js.org/) is used
98
+
99
+ ## History
100
+ - Initialized via `lt create angular`
@@ -1,4 +1,4 @@
1
- import { Restricted, RoleEnum } from '@lenne.tech/nest-server';
1
+ import { CoreInput, Restricted, RoleEnum } from '@lenne.tech/nest-server';
2
2
  import { Field, InputType } from '@nestjs/graphql';
3
3
  import { IsOptional } from 'class-validator';<%- props.imports %>
4
4
 
@@ -7,7 +7,7 @@ import { IsOptional } from 'class-validator';<%- props.imports %>
7
7
  */
8
8
  @Restricted(RoleEnum.ADMIN)
9
9
  @InputType({ description: 'Input data to update an existing <%= props.namePascal %>' })
10
- export class <%= props.namePascal %>Input {
10
+ export class <%= props.namePascal %>Input extends CoreInput {
11
11
 
12
12
  // ===================================================================================================================
13
13
  // Properties
@@ -3,6 +3,7 @@ import { Field, ObjectType } from '@nestjs/graphql';
3
3
  import { Prop, Schema as MongooseSchema, SchemaFactory } from '@nestjs/mongoose';
4
4
  import { Document, Schema } from 'mongoose';
5
5
  import { PersistenceModel } from '../../common/models/persistence.model';
6
+ import { User } from '../user/user.model';
6
7
 
7
8
  export type <%= props.namePascal %>Document = <%= props.namePascal %> & Document;
8
9
 
@@ -26,7 +27,7 @@ export class <%= props.namePascal %> extends PersistenceModel {
26
27
  /**
27
28
  * Initialize instance with default values instead of undefined
28
29
  */
29
- init() {
30
+ override init() {
30
31
  super.init();
31
32
  // this.xxx = [];
32
33
  return this;
@@ -37,10 +38,21 @@ export class <%= props.namePascal %> extends PersistenceModel {
37
38
  *
38
39
  * Hint: Non-primitive variables should always be mapped (see mapClasses / mapClassesAsync in ModelHelper)
39
40
  */
40
- map(input) {
41
+ override map(input) {
41
42
  super.map(input);
42
43
  return <%- props.mappings %>
43
44
  }
45
+
46
+ /**
47
+ * Verification of the user's rights to access the properties of this object
48
+ */
49
+ override securityCheck(user: User, force?: boolean) {
50
+ if (force || user?.hasRole(RoleEnum.ADMIN)) {
51
+ return this;
52
+ }
53
+ // Check rights for properties of this object
54
+ return this;
55
+ }
44
56
  }
45
57
 
46
58
  export const <%= props.namePascal %>Schema = SchemaFactory.createForClass(<%= props.namePascal %>);
@@ -1,4 +1,5 @@
1
- import { Module } from '@nestjs/common';
1
+ import { ConfigService } from '@lenne.tech/nest-server';
2
+ import { forwardRef, Module } from '@nestjs/common';
2
3
  import { MongooseModule } from '@nestjs/mongoose';
3
4
  import { PubSub } from 'graphql-subscriptions';
4
5
  import { UserModule } from '../user/user.module';
@@ -10,9 +11,13 @@ import { <%= props.namePascal %>Service } from './<%= props.nameKebab %>.service
10
11
  * <%= props.namePascal %> module
11
12
  */
12
13
  @Module({
13
- imports: [MongooseModule.forFeature([{ name: <%= props.namePascal %>.name, schema: <%= props.namePascal %>Schema }]), UserModule],
14
+ imports: [
15
+ MongooseModule.forFeature([{ name: <%= props.namePascal %>.name, schema: <%= props.namePascal %>Schema }]),
16
+ forwardRef(() => UserModule),
17
+ ],
14
18
  controllers: [],
15
19
  providers: [
20
+ ConfigService,
16
21
  <%= props.namePascal %>Resolver,
17
22
  <%= props.namePascal %>Service,
18
23
  {
@@ -1,4 +1,4 @@
1
- import { assignPlain, CrudService, ServiceOptions } from '@lenne.tech/nest-server';
1
+ import { assignPlain, ConfigService, CrudService, ServiceOptions } from '@lenne.tech/nest-server';
2
2
  import { Inject, Injectable, NotFoundException } from '@nestjs/common';
3
3
  import { InjectModel } from '@nestjs/mongoose';
4
4
  import { PubSub } from 'graphql-subscriptions';
@@ -22,12 +22,17 @@ export class <%= props.namePascal %>Service extends CrudService<<%= props.namePa
22
22
 
23
23
  /**
24
24
  * Constructor for injecting services
25
+ *
26
+ * Hints:
27
+ * To resolve circular dependencies, integrate services as follows:
28
+ * @Inject(forwardRef(() => XxxService)) protected readonly xxxService: XxxService
25
29
  */
26
30
  constructor(
31
+ protected override readonly configService: ConfigService,
27
32
  @InjectModel('<%= props.namePascal %>') protected readonly <%= props.nameCamel %>Model: Model<<%= props.namePascal %>Document>,
28
33
  @Inject('PUB_SUB') protected readonly pubSub: PubSub
29
34
  ) {
30
- super({mainDbModel: <%= props.nameCamel %>Model, mainModelConstructor: <%= props.namePascal %>});
35
+ super({configService: configService, mainDbModel: <%= props.nameCamel %>Model, mainModelConstructor: <%= props.namePascal %>});
31
36
  }
32
37
 
33
38
  // ===================================================================================================================
@@ -38,7 +43,7 @@ export class <%= props.namePascal %>Service extends CrudService<<%= props.namePa
38
43
  * Create new <%= props.namePascal %>
39
44
  * Overwrites create method from CrudService
40
45
  */
41
- async create(input: <%= props.namePascal %>CreateInput, serviceOptions?: ServiceOptions): Promise<<%= props.namePascal %>> {
46
+ override async create(input: <%= props.namePascal %>CreateInput, serviceOptions?: ServiceOptions): Promise<<%= props.namePascal %>> {
42
47
  // Get new <%= props.namePascal %>
43
48
  const created<%= props.namePascal %> = await super.create(input, serviceOptions);
44
49
 
@@ -0,0 +1,18 @@
1
+ import { Restricted, RoleEnum } from '@lenne.tech/nest-server';
2
+ import { Field, InputType } from '@nestjs/graphql';
3
+ import { IsOptional } from 'class-validator';
4
+ import { <%= props.namePascal %>Input } from './<%= props.nameKebab %>.input';<%- props.imports %>
5
+
6
+
7
+ /**
8
+ * <%= props.namePascal %> create input
9
+ */
10
+ @Restricted(RoleEnum.ADMIN)
11
+ @InputType({ description: 'Input data to create a new <%= props.namePascal %>' })
12
+ export class <%= props.namePascal %>CreateInput extends <%= props.namePascal %>Input {
13
+
14
+ // ===================================================================================================================
15
+ // Properties
16
+ // ===================================================================================================================
17
+ <%- props.props %>
18
+ }
@@ -0,0 +1,16 @@
1
+ import { CoreInput, Restricted, RoleEnum } from '@lenne.tech/nest-server';
2
+ import { Field, InputType } from '@nestjs/graphql';
3
+ import { IsOptional } from 'class-validator';<%- props.imports %>
4
+
5
+ /**
6
+ * <%= props.namePascal %> input
7
+ */
8
+ @Restricted(RoleEnum.ADMIN)
9
+ @InputType({ description: 'Input data to update an existing <%= props.namePascal %>' })
10
+ export class <%= props.namePascal %>Input extends CoreInput {
11
+
12
+ // ===================================================================================================================
13
+ // Properties
14
+ // ===================================================================================================================
15
+ <%- props.props %>
16
+ }
@@ -0,0 +1,57 @@
1
+ import { CoreModel, mapClasses, Restricted, RoleEnum } from '@lenne.tech/nest-server';
2
+ import { Field, ObjectType } from '@nestjs/graphql';
3
+ import { Prop, Schema as MongooseSchema, SchemaFactory } from '@nestjs/mongoose';
4
+ import { Document, Schema } from 'mongoose';
5
+ import { User } from '../../../modules/user/user.model';
6
+
7
+ export type <%= props.namePascal %>Document = <%= props.namePascal %> & Document;
8
+
9
+ /**
10
+ * <%= props.namePascal %> model
11
+ */
12
+ @Restricted(RoleEnum.ADMIN)
13
+ @ObjectType({ description: '<%= props.namePascal %>' })
14
+ @MongooseSchema({ _id: false })
15
+ export class <%= props.namePascal %> extends CoreModel {
16
+
17
+ // ===================================================================================================================
18
+ // Properties
19
+ // ===================================================================================================================
20
+ <%- props.props %>
21
+
22
+ // ===================================================================================================================
23
+ // Methods
24
+ // ===================================================================================================================
25
+
26
+ /**
27
+ * Initialize instance with default values instead of undefined
28
+ */
29
+ override init() {
30
+ super.init();
31
+ // this.xxx = [];
32
+ return this;
33
+ }
34
+
35
+ /**
36
+ * Map input
37
+ *
38
+ * Hint: Non-primitive variables should always be mapped (see mapClasses / mapClassesAsync in ModelHelper)
39
+ */
40
+ override map(input) {
41
+ super.map(input);
42
+ return <%- props.mappings %>
43
+ }
44
+
45
+ /**
46
+ * Verification of the user's rights to access the properties of this object
47
+ */
48
+ override securityCheck(user: User, force?: boolean) {
49
+ if (force || user?.hasRole(RoleEnum.ADMIN)) {
50
+ return this;
51
+ }
52
+ // Check rights for properties of this object
53
+ return this;
54
+ }
55
+ }
56
+
57
+ export const <%= props.namePascal %>Schema = SchemaFactory.createForClass(<%= props.namePascal %>);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/cli",
3
- "version": "0.0.82",
3
+ "version": "0.0.85",
4
4
  "description": "lenne.Tech CLI: lt",
5
5
  "keywords": [
6
6
  "lenne.Tech",