@lenne.tech/cli 0.0.61 → 0.0.64

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.
@@ -1,100 +0,0 @@
1
- import { FilterArgs, GraphQLUser, InputHelper, RoleEnum, Roles } from '@lenne.tech/nest-server';
2
- import { Args, Info, Mutation, Query, Resolver, Subscription } from '@nestjs/graphql';
3
- import { GraphQLResolveInfo } from 'graphql';
4
- import { PubSub } from 'graphql-subscriptions';
5
- import { User } from '../user/user.model';
6
- import { <%= props.namePascal %>CreateInput } from './inputs/<%= props.nameKebab %>-create.input';
7
- import { <%= props.namePascal %>Input } from './inputs/<%= props.nameKebab %>.input';
8
- import { <%= props.namePascal %> } from './<%= props.nameKebab %>.model';
9
- import { <%= props.namePascal %>Service } from './<%= props.nameKebab %>.service';
10
-
11
- // Subscription
12
- const pubSub = new PubSub();
13
-
14
- /**
15
- * Resolver to process with <%= props.namePascal %> data
16
- */
17
- @Resolver(of => <%= props.namePascal %>)
18
- export class <%= props.namePascal %>Resolver {
19
-
20
- /**
21
- * Import services
22
- */
23
- constructor(private readonly <%= props.nameCamel %>Service: <%= props.namePascal %>Service) {}
24
-
25
- // ===========================================================================
26
- // Queries
27
- // ===========================================================================
28
-
29
- /**
30
- * Get <%= props.namePascal %> via ID
31
- */
32
- @Query(returns => <%= props.namePascal %>, { description: 'Get <%= props.namePascal %> with specified ID' })
33
- async get<%= props.namePascal %>(@Args('id') id: string, @Info() info: GraphQLResolveInfo): Promise<<%= props.namePascal %>> {
34
- return await this.<%= props.nameCamel %>Service.get(id, info);
35
- }
36
-
37
- /**
38
- * Get <%= props.namePascal %>s (via filter)
39
- */
40
- @Roles(RoleEnum.USER)
41
- @Query(returns => [<%= props.namePascal %>], { description: 'Find <%= props.namePascal %> (via filter)' })
42
- async find<%= props.namePascal %>s(@Info() info: GraphQLResolveInfo, @Args() args?: FilterArgs) {
43
- return await this.<%= props.nameCamel %>Service.find(args, info);
44
- }
45
-
46
- // ===========================================================================
47
- // Mutations
48
- // ===========================================================================
49
-
50
- /**
51
- * Create new <%= props.namePascal %>
52
- */
53
- @Mutation(returns => <%= props.namePascal %>, { description: 'Create a new <%= props.namePascal %>' })
54
- async create<%= props.namePascal %>(@Args('input') input: <%= props.namePascal %>CreateInput, @GraphQLUser() user: User, @Info() info: GraphQLResolveInfo): Promise<<%= props.namePascal %>> {
55
- return await this.<%= props.nameCamel %>Service.create(input, user, info);
56
- }
57
-
58
- /**
59
- * Update existing <%= props.namePascal %>
60
- */
61
- @Roles(RoleEnum.ADMIN, RoleEnum.OWNER)
62
- @Mutation(returns => <%= props.namePascal %>, { description: 'Update existing <%= props.namePascal %>' })
63
- async update<%= props.namePascal %>(
64
- @Args('input') input: <%= props.namePascal %>Input,
65
- @Args('id') id: string,
66
- @GraphQLUser() user: User,
67
- @Info() info: GraphQLResolveInfo
68
- ): Promise<<%= props.namePascal %>> {
69
-
70
- // Check input
71
- // Hint: necessary as long as global CheckInputPipe can't access context for current user
72
- // (see https://github.com/nestjs/graphql/issues/325)
73
- input = await InputHelper.check(input, user);
74
-
75
- // Update <%= props.namePascal %>
76
- return await this.<%= props.nameCamel %>Service.update(id, input, user, info);
77
- }
78
-
79
- /**
80
- * Delete existing <%= props.namePascal %>
81
- */
82
- @Roles(RoleEnum.ADMIN, RoleEnum.OWNER)
83
- @Mutation(returns => <%= props.namePascal %>, { description: 'Delete existing <%= props.namePascal %>' })
84
- async delete<%= props.namePascal %>(@Args('id') id: string, @Info() info: GraphQLResolveInfo): Promise<<%= props.namePascal %>> {
85
- return await this.<%= props.nameCamel %>Service.delete(id, info);
86
- }
87
-
88
- // ===========================================================================
89
- // Subscriptions
90
- // ===========================================================================
91
-
92
- /**
93
- * Subscription for create <%= props.namePascal %>
94
- */
95
- @Roles(RoleEnum.ADMIN)
96
- @Subscription(returns => <%= props.namePascal %>)
97
- <%= props.nameCamel %>Created() {
98
- return pubSub.asyncIterator('<%= props.nameCamel %>Created');
99
- }
100
- }
@@ -1,169 +0,0 @@
1
- import {
2
- ConfigService,
3
- EmailService,
4
- Filter,
5
- FilterArgs,
6
- ServiceHelper,
7
- } from '@lenne.tech/nest-server';
8
- import { Injectable, InternalServerErrorException, NotFoundException } from '@nestjs/common';
9
- import { InjectRepository } from '@nestjs/typeorm';
10
- import { GraphQLResolveInfo } from 'graphql';
11
- import { PubSub } from 'graphql-subscriptions';
12
- import { MongoRepository } from 'typeorm';
13
- import { User } from '../user/user.model';
14
- import { UserService } from '../user/user.service';
15
- import { <%= props.namePascal %>CreateInput } from './inputs/<%= props.nameKebab %>-create.input';
16
- import { <%= props.namePascal %>Input } from './inputs/<%= props.nameKebab %>.input';
17
- import { <%= props.namePascal %> } from './<%= props.nameKebab %>.model';
18
-
19
- // Subscription
20
- const pubSub = new PubSub();
21
-
22
- /**
23
- * <%= props.namePascal %> service
24
- */
25
- @Injectable()
26
- export class <%= props.namePascal %>Service {
27
-
28
- // ===================================================================================================================
29
- // Properties
30
- // ===================================================================================================================
31
-
32
- // ===================================================================================================================
33
- // Injections
34
- // ===================================================================================================================
35
-
36
- /**
37
- * Constructor for injecting services
38
- */
39
- constructor(
40
- protected readonly configService: ConfigService,
41
- protected readonly emailService: EmailService,
42
- protected readonly userService: UserService,
43
- @InjectModel('<%= props.namePascal %>') protected readonly <%= props.namePascal %>Model: Model<<%= props.namePascal %>Document>,
44
- ) {}
45
-
46
- // ===================================================================================================================
47
- // Methods
48
- // ===================================================================================================================
49
-
50
- /**
51
- * Create new <%= props.namePascal %> and send welcome email
52
- */
53
- async create(input: <%= props.namePascal %>CreateInput, currentUser?: User, ...args: any[]): Promise<<%= props.namePascal %>> {
54
- // Prepare input
55
- await this.prepareInput(input, currentUser, { create: true });
56
-
57
- // Save new <%= props.namePascal %>
58
- const created<%= props.namePascal %> = new this.<%= props.namePascal %>Model(<%= props.namePascal %>.map(input));
59
-
60
- await created<%= props.namePascal %>.save();
61
-
62
- // Prepare output
63
- await this.prepareOutput(created<%= props.namePascal %>, args[0]);
64
-
65
- // Inform subscriber
66
- await pubSub.publish('<%= props.nameCamel %>Created', { <%= props.nameCamel %>Created: created<%= props.namePascal %> });
67
-
68
- // Return created <%= props.namePascal %>
69
- return created<%= props.namePascal %>;
70
- }
71
-
72
- /**
73
- * Delete <%= props.namePascal %> via ID
74
- */
75
- async delete(id: string, ...args: any[]): Promise<<%= props.namePascal %>> {
76
- // Search <%= props.namePascal %>
77
- const created<%= props.namePascal %> = await this.<%= props.namePascal %>Model.findOne({ _id: id }).exec();
78
-
79
- // Check <%= props.namePascal %>
80
- if (!created<%= props.namePascal %>) {
81
- throw new NotFoundException();
82
- }
83
-
84
- // Delete
85
- await this.<%= props.namePascal %>Model.deleteOne({ _id: id }).exec();
86
-
87
- const <%= props.namePascal %>Result = <%= props.namePascal %>.map(created<%= props.namePascal %>);
88
-
89
- // Return deleted user
90
- return await this.prepareOutput(<%= props.namePascal %>Result, args[0]);
91
- }
92
-
93
- /**
94
- * Get <%= props.namePascal %> via ID
95
- */
96
- async get(id: string, ...args: any[]): Promise<<%= props.namePascal %>> {
97
- const <%= props.nameCamel %> = await this.<%= props.namePascal %>Model.findOne({ _id: id }).exec();
98
- if (!<%= props.nameCamel %>) {
99
- throw new NotFoundException();
100
- }
101
- return await this.prepareOutput(<%= props.nameCamel %>, args[0]);
102
- }
103
-
104
- /**
105
- * Get <%= props.namePascal %> via filter
106
- */
107
- async find(filterArgs?: FilterArgs, ...args: any[]): Promise<<%= props.namePascal %>[]> {
108
- const filterQuery = Filter.convertFilterArgsToQuery(filterArgs)[0];
109
-
110
- // Return founded
111
- return await this.<%= props.namePascal %>Model.find(filterQuery);
112
- }
113
-
114
- /**
115
- * Update <%= props.namePascal %> via ID
116
- */
117
- async update(
118
- id: string,
119
- input: <%= props.namePascal %>Input,
120
- currentUser: User,
121
- ...args: any[]
122
- ): Promise<<%= props.namePascal %>> {
123
- // Check if <%= props.namePascal %> exists
124
- const <%= props.nameCamel %> = await this.<%= props.namePascal %>Model.findOne({_id: id});
125
- if (!<%= props.nameCamel %>) {
126
- throw new NotFoundException(`<%= props.namePascal %> not found with ID: ${id}`);
127
- }
128
-
129
- // Prepare input
130
- await this.prepareInput(input, currentUser);
131
-
132
- // Update
133
- <%= props.nameCamel %>.set(input);
134
-
135
- // Save
136
- await <%= props.nameCamel %>.save();
137
-
138
- // Return <%= props.namePascal %>
139
- return await this.prepareOutput(
140
- Object.assign(<%= props.nameCamel %>, input) as <%= props.namePascal %>,
141
- args[0],
142
- );
143
- }
144
-
145
- // ===================================================================================================================
146
- // Helper methods
147
- // ===================================================================================================================
148
-
149
- /**
150
- * Prepare input before save
151
- */
152
- protected async prepareInput(
153
- input: { [key: string]: any },
154
- currentUser: User,
155
- options: { create?: boolean } = {},
156
- ) {
157
- return await ServiceHelper.prepareInput(input, currentUser, options);
158
- }
159
-
160
- /**
161
- * Prepare output before return
162
- */
163
- protected async prepareOutput(
164
- <%= props.nameCamel %>: <%= props.namePascal %>,
165
- info?: GraphQLResolveInfo,
166
- ) {
167
- return await ServiceHelper.prepareOutput(<%= props.nameCamel %>, User, this.userService, info);
168
- }
169
- }
@@ -1,61 +0,0 @@
1
- # <%= props.name %>
2
-
3
- ## Requirements
4
-
5
- - [Node.js incl. npm](https://nodejs.org):
6
- the runtime environment for your server
7
-
8
- - [MongoDB](https://docs.mongodb.com/manual/installation/#mongodb-community-edition-installation-tutorials)
9
- (or any other database compatible with [TypeORM](https://typeorm.io)):
10
- the database for your objects
11
-
12
-
13
- ## Start the server
14
-
15
- `$ npm run start:dev`
16
-
17
-
18
- ## Extend the server
19
-
20
- This server is based on [lenne.Tech Nest Server](https://github.com/lenneTech/nest-server).
21
-
22
- Since the lenne.Tech Nest Server is based on [Nest](https://nestjs.com/), you can find all information about extending
23
- the **<%= props.name %>** in the [documentation of Nest](https://docs.nestjs.com/).
24
-
25
- The documentation of the extensions and auxiliary classes that the
26
- [lenne.Tech Nest Server](https://github.com/lenneTech/nest-server) contains is currently under construction.
27
- As long as this is not yet available,have a look at the
28
- [source code](https://github.com/lenneTech/nest-server/tree/master/src/core).
29
- There you will find a lot of things that will help you to extend your server, such as:
30
-
31
- - [GraphQL scalars](https://github.com/lenneTech/nest-server/tree/master/src/core/common/scalars)
32
- - [Filter and pagination](https://github.com/lenneTech/nest-server/tree/master/src/core/common/args)
33
- - [Decorators for restrictions and roles](https://github.com/lenneTech/nest-server/tree/master/src/core/common/decorators)
34
- - [Authorisation handling](https://github.com/lenneTech/nest-server/tree/master/src/core/modules/auth)
35
- - [Ready to use user module](https://github.com/lenneTech/nest-server/tree/master/src/core/modules/user)
36
- - [Common helpers](https://github.com/lenneTech/nest-server/tree/master/src/core/common/helpers) and
37
- [helpers for tests](https://github.com/lenneTech/nest-server/blob/master/src/test/test.helper.ts)
38
- - ...
39
-
40
-
41
- ## Further information
42
-
43
- ### Running the app
44
-
45
- ```bash
46
- # Development
47
- $ npm start
48
-
49
- # Watch mode
50
- $ npm run start:dev
51
-
52
- # Production mode
53
- $ npm run start:prod
54
- ```
55
-
56
- ### Test
57
-
58
- ```bash
59
- # e2e tests
60
- $ npm run test:e2e
61
- ```
@@ -1,30 +0,0 @@
1
- # <%= props.name %>
2
-
3
- [![License](https://img.shields.io/github/license/<%= props.nameKebab %>)](/LICENSE) [![CircleCI](https://circleci.com/gh/<%= props.nameKebab %>/tree/master.svg?style=shield)](https://circleci.com/gh/<%= props.nameKebab %>/tree/master)
4
- [![Dependency Status](https://david-dm.org/<%= props.nameKebab %>.svg)](https://david-dm.org/<%= props.nameKebab %>) [![devDependency Status](https://david-dm.org/<%= props.nameKebab %>/dev-status.svg)](https://david-dm.org/<%= props.nameKebab %>?type=dev)
5
-
6
- <!--
7
- [![GitHub forks](https://img.shields.io/github/forks/<%= props.nameKebab %>)](https://github.com/<%= props.nameKebab %>/fork) [![GitHub stars](https://img.shields.io/github/stars/<%= props.nameKebab %>)](https://github.com/<%= props.nameKebab %>)
8
- -->
9
-
10
-
11
- ## Requirements
12
-
13
- - [Node.js incl. npm](https://nodejs.org):
14
- the runtime environment for your project
15
-
16
-
17
- ## Scripts
18
-
19
- ```bash
20
- # Lint
21
- $ npm run lint
22
-
23
- # Test
24
- $ npm test
25
- $ npm run watch
26
- $ npm run coverage
27
-
28
- # Build
29
- $ npm build
30
- ```
package/tslint.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "extends": ["tslint-config-standard", "tslint-config-prettier"],
3
- "rules": {
4
- "strict-type-predicates": false,
5
- "trailing-comma": false
6
- },
7
- "env": {
8
- "jest": true
9
- }
10
- }