@simitgroup/simpleapp-generator 1.4.2-alpha → 1.5.1-alpha
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/README.md +3 -1
- package/dist/buildinschemas/autoincreament.d.ts.map +1 -1
- package/dist/buildinschemas/autoincreament.js +1 -0
- package/dist/buildinschemas/autoincreament.js.map +1 -1
- package/dist/buildinschemas/docnoformat.d.ts.map +1 -1
- package/dist/buildinschemas/docnoformat.js +1 -0
- package/dist/buildinschemas/docnoformat.js.map +1 -1
- package/dist/buildinschemas/permission.d.ts.map +1 -1
- package/dist/buildinschemas/permission.js +1 -8
- package/dist/buildinschemas/permission.js.map +1 -1
- package/dist/framework.d.ts.map +1 -1
- package/dist/framework.js +4 -2
- package/dist/framework.js.map +1 -1
- package/dist/generate.js +6 -4
- package/dist/generate.js.map +1 -1
- package/dist/processors/bpmnbuilder.d.ts.map +1 -1
- package/dist/processors/bpmnbuilder.js +10 -4
- package/dist/processors/bpmnbuilder.js.map +1 -1
- package/dist/processors/jsonschemabuilder.d.ts.map +1 -1
- package/dist/processors/jsonschemabuilder.js +9 -0
- package/dist/processors/jsonschemabuilder.js.map +1 -1
- package/package.json +1 -1
- package/src/buildinschemas/autoincreament.ts +1 -0
- package/src/buildinschemas/docnoformat.ts +1 -0
- package/src/buildinschemas/permission.ts +1 -8
- package/src/framework.ts +5 -4
- package/src/generate.ts +7 -6
- package/src/processors/bpmnbuilder.ts +10 -5
- package/src/processors/jsonschemabuilder.ts +10 -0
- package/templates/basic/nest/apischema.ts.eta +5 -0
- package/templates/basic/nest/controller.ts.eta +31 -12
- package/templates/basic/nest/resolver.ts.eta +124 -0
- package/templates/basic/nest/service.ts.eta +0 -6
- package/templates/nest/.env._eta +7 -7
- package/templates/nest/src/app.module.ts.eta +24 -21
- package/templates/nest/src/app.resolver.ts.eta +9 -0
- package/templates/nest/src/cloudapi/cloudapi.module.ts._eta +15 -0
- package/templates/nest/src/cloudapi/cloudapi.service.ts._eta +15 -0
- package/templates/nest/src/simpleapp/apischemas/index.ts._eta +15 -1
- package/templates/nest/src/simpleapp/generate/commons/decorators/appuser.decorator.ts.eta +11 -5
- package/templates/nest/src/simpleapp/generate/commons/interceptors/response.interceptor.ts.eta +44 -39
- package/templates/nest/src/simpleapp/generate/commons/middlewares/tenant.middleware.ts.eta +16 -4
- package/templates/nest/src/simpleapp/generate/commons/robotuser.service.ts.eta +112 -0
- package/templates/nest/src/simpleapp/generate/commons/roles/roles.guard.ts.eta +24 -12
- package/templates/nest/src/simpleapp/generate/commons/user.context.ts.eta +4 -1
- package/templates/nest/src/simpleapp/generate/processors/simpleapp.processor.ts.eta +12 -5
- package/templates/nest/src/simpleapp/generate/types/index.ts.eta +1 -1
- package/templates/nest/src/simpleapp/generate/types/schema.type.ts.eta +191 -0
- package/templates/nest/src/simpleapp/generate/types/simpleapp.type.ts.eta +200 -5
- package/templates/nest/src/simpleapp/generate/types/workflow.type.ts.eta +15 -0
- package/templates/nest/src/simpleapp/generate/workflow/workflow.config.ts.eta +3 -3
- package/templates/nest/src/simpleapp/generate/workflow/workflow.controller.ts.eta +8 -6
- package/templates/nest/src/simpleapp/generate/workflow/workflow.service.ts.eta +60 -23
- package/templates/nest/src/simpleapp/resolvers/readme.md.eta +1 -0
- package/templates/nest/src/simpleapp/simpleapp.module.ts.eta +13 -3
- package/templates/nest/src/simpleapp/types/index.ts._eta +6 -0
- package/templates/nest/src/simpleapp/workflows/listeners/simpleapp.listener.ts.eta +31 -0
- package/templates/nuxt/app.vue._eta +8 -2
- package/templates/nuxt/assets/primevue/passthrough.ts._eta +1 -1
- package/templates/nuxt/components/renderer/RendererMoney.vue.eta +21 -12
- package/templates/nuxt/composables/graphquery.generate.ts.eta +26 -0
- package/templates/nuxt/composables/refreshDocumentList.generate.ts.eta +7 -6
- package/templates/nuxt/layouts/mobile.vue._eta +2 -2
- package/templates/nuxt/nuxt.config.ts._eta +8 -0
- package/templates/nuxt/pages/[xorg]/index.vue._eta +9 -0
- package/templates/nuxt/pages/[xorg]/mobile/index.vue._eta +2 -15
- package/templates/nuxt/pages/picktenant.vue._eta +3 -1
- package/templates/nuxt/simpleapp/generate/clients/SimpleAppClient.ts.eta +2 -0
- package/templates/nuxt/types/events.ts.eta +4 -3
- package/templates/project/workflows/bpmn/{suspendcustomer.bpmn._eta → sayhello.bpmn._eta} +6 -36
- package/tsconfig.tsbuildinfo +1 -1
- package/templates/nest/src/simpleapp/workflows/listeners/simpleapp.listener.ts._eta +0 -26
|
@@ -5,21 +5,26 @@
|
|
|
5
5
|
* Author: Ks Tan
|
|
6
6
|
*/
|
|
7
7
|
import { ApiProperty } from '@nestjs/swagger';
|
|
8
|
+
import { Field, ObjectType,ID } from '@nestjs/graphql';
|
|
8
9
|
|
|
9
10
|
<%Object.keys(it.models).forEach(function(name) { %>
|
|
10
11
|
<% let schema = it.models[name].model %>
|
|
12
|
+
@ObjectType()
|
|
11
13
|
export class <%= name %>{
|
|
12
14
|
|
|
13
15
|
<% Object.keys(schema).forEach(function(key){%>
|
|
14
16
|
<% let obj = schema[key] %>
|
|
15
17
|
<% if(typeof obj == 'string') {%>
|
|
18
|
+
@Field()
|
|
16
19
|
@ApiProperty({type: ()=><%=obj%>})
|
|
17
20
|
<%= key %>: <%= obj %>;
|
|
18
21
|
<% }else if( Array.isArray( obj)){%>
|
|
22
|
+
@Field(type=>[<%=initType(obj[0]) %>])
|
|
19
23
|
@ApiProperty({type: ()=>[<%=initType(obj[0]) %>] })
|
|
20
24
|
<%= key %>: <%= obj[0] %>[];
|
|
21
25
|
|
|
22
26
|
<% }else{%>
|
|
27
|
+
@Field()
|
|
23
28
|
@ApiProperty(<%~ JSON.stringify(obj)%> )
|
|
24
29
|
<%= key %>: <%= obj.type %>;
|
|
25
30
|
<% } %>
|
|
@@ -34,6 +34,25 @@ import { Response } from 'express';
|
|
|
34
34
|
import {AppUser} from '../commons/decorators/appuser.decorator'
|
|
35
35
|
import {UserContext} from '../commons/user.context'
|
|
36
36
|
|
|
37
|
+
<% const getFieldType =(proptype, typename)=>{
|
|
38
|
+
const systemtypes = ['Boolean','boolean','string','String','number','Number','object','Object','integer','Integer']
|
|
39
|
+
let tmptypename = typename.replace('[','').replace(']','')
|
|
40
|
+
|
|
41
|
+
if(systemtypes.includes(tmptypename)){
|
|
42
|
+
|
|
43
|
+
}else if(proptype=='schema'){
|
|
44
|
+
tmptypename= 'schemas.'+tmptypename
|
|
45
|
+
}else{ //type
|
|
46
|
+
tmptypename= 'types.'+tmptypename
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if(typename.includes('[')){
|
|
50
|
+
return proptype=='schema' ? `[${tmptypename}]` : `${tmptypename}[]`
|
|
51
|
+
}else{
|
|
52
|
+
return tmptypename
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
%>
|
|
37
56
|
<% let superadmindoctype = ['tenant','globaluser'] %>
|
|
38
57
|
const doctype = '<%= it.doctype %>'.toUpperCase();
|
|
39
58
|
@ApiTags(doctype)
|
|
@@ -149,19 +168,21 @@ export class <%= it.typename %>Controller extends SimpleAppAbstractController<
|
|
|
149
168
|
<%}%>
|
|
150
169
|
<% if(['post','put','patch'].includes(api.method)){ %>
|
|
151
170
|
@ApiBody({ description: 'Request Body',
|
|
152
|
-
type:
|
|
171
|
+
type:
|
|
172
|
+
<%= api.schema
|
|
153
173
|
? (api.schema.includes('[') ? '[schemas.'+api.schema.replace('[','').replace(']','') + ']' : 'schemas.'+api.schema )
|
|
154
|
-
: 'Object'
|
|
174
|
+
: 'Object'
|
|
175
|
+
%>
|
|
176
|
+
})
|
|
155
177
|
<%}%>
|
|
156
178
|
@ApiResponse({status: 200,description: '<%=api.description%>'
|
|
157
|
-
,type: <%= api.responseType
|
|
158
|
-
|
|
159
|
-
: 'Object'%> })
|
|
179
|
+
,type: <%= getFieldType('schema',api.responseType)%>
|
|
180
|
+
})
|
|
160
181
|
@ApiOperation({ operationId: 'run<%=capitalizeFirstLetter(api.action)%>' })
|
|
161
182
|
<% if(api.queryPara && api.queryPara.length>0) {%>
|
|
162
183
|
<%for(let q=0;q<api.queryPara.length; q++){%>
|
|
163
184
|
@ApiQuery({name: "<%=api['queryPara'][q]%>",required: false,type: String})
|
|
164
|
-
<%}%>
|
|
185
|
+
<%}%>
|
|
165
186
|
<%}%>
|
|
166
187
|
async <%=capitalizeFirstLetter(api.action) %>(
|
|
167
188
|
@AppUser() appuser: UserContext,
|
|
@@ -189,7 +210,8 @@ export class <%= it.typename %>Controller extends SimpleAppAbstractController<
|
|
|
189
210
|
<%}%>
|
|
190
211
|
){
|
|
191
212
|
|
|
192
|
-
|
|
213
|
+
|
|
214
|
+
const res:<%= getFieldType('type',api.responseType)%> = await this.service.run<%=capitalizeFirstLetter(api.action)%>(appuser,<% if(api.entryPoint && api.entryPoint.includes(':')) {%>
|
|
193
215
|
<%let subpath = api.entryPoint.split('/')%>
|
|
194
216
|
<% for(let a=0;a<subpath.length;a++){%>
|
|
195
217
|
<%const partstr = subpath[a]%>
|
|
@@ -208,7 +230,7 @@ export class <%= it.typename %>Controller extends SimpleAppAbstractController<
|
|
|
208
230
|
data,
|
|
209
231
|
<%}%>
|
|
210
232
|
)
|
|
211
|
-
|
|
233
|
+
return res
|
|
212
234
|
|
|
213
235
|
}
|
|
214
236
|
<%}%>
|
|
@@ -303,8 +325,5 @@ export class <%= it.typename %>Controller extends SimpleAppAbstractController<
|
|
|
303
325
|
async delete(@AppUser() appuser: UserContext,@Param('id') id: string) {
|
|
304
326
|
return this._delete(appuser,id);
|
|
305
327
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
328
|
+
|
|
310
329
|
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. It is changable
|
|
3
|
+
* --remove-this-line-to-prevent-override--
|
|
4
|
+
* last change 2024-04-17
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
7
|
+
import { Resolver, Query, Mutation, Args, ID,Context } from '@nestjs/graphql';
|
|
8
|
+
import * as schemas from '../apischemas';
|
|
9
|
+
import { AppUser } from '../commons/decorators/appuser.decorator';
|
|
10
|
+
import { UserContext } from '../commons/user.context';
|
|
11
|
+
import { <%= it.typename %>, <%= it.typename %>Service } from '../../services/<%= it.doctype.toLowerCase() %>.service';
|
|
12
|
+
import { Roles } from '../commons/roles/roles.decorator';
|
|
13
|
+
import { Role } from '../commons/roles/roles.enum';
|
|
14
|
+
|
|
15
|
+
import { Request } from '@nestjs/common';
|
|
16
|
+
|
|
17
|
+
<% const getFieldType =(proptype, typename)=>{
|
|
18
|
+
const systemtypes = ['Boolean','boolean','string','String','number','Number','object','Object','integer','Integer']
|
|
19
|
+
let tmptypename = typename.replace('[','').replace(']','')
|
|
20
|
+
|
|
21
|
+
if(systemtypes.includes(tmptypename)){
|
|
22
|
+
|
|
23
|
+
}else if(proptype=='schema'){
|
|
24
|
+
tmptypename= 'schemas.'+tmptypename
|
|
25
|
+
}else{ //type
|
|
26
|
+
tmptypename= 'types.'+tmptypename
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if(typename.includes('[')){
|
|
30
|
+
return proptype=='schema' ? `[${tmptypename}]` : `${tmptypename}[]`
|
|
31
|
+
}else{
|
|
32
|
+
return tmptypename
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
%>
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
<% let superadmindoctype = ['tenant','globaluser'] %>
|
|
39
|
+
@Resolver(() => schemas.<%= it.typename %>)
|
|
40
|
+
export class <%= it.typename %>Resolver {
|
|
41
|
+
constructor(private readonly service: <%= it.typename %>Service) { }
|
|
42
|
+
|
|
43
|
+
<%if(superadmindoctype.includes(it.doctype)){%>
|
|
44
|
+
@Roles(Role.SuperAdmin,Role.<%= `${it.typename}_search`%>)
|
|
45
|
+
<%}else{%>
|
|
46
|
+
@Roles(Role.SuperAdmin,Role.SuperUser,Role.<%= `${it.typename}_search`%>)
|
|
47
|
+
<%}%>
|
|
48
|
+
@Query(() => [schemas.<%= it.typename %>])
|
|
49
|
+
async <%= it.name %>s(@AppUser() appuser: UserContext): Promise<<%= it.typename %>[]> {
|
|
50
|
+
|
|
51
|
+
return await this.service.search(appuser,undefined,undefined,undefined)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
<%if(superadmindoctype.includes(it.doctype)){%>
|
|
56
|
+
@Roles(Role.SuperAdmin,Role.<%= `${it.typename}_search`%>)
|
|
57
|
+
<%}else{%>
|
|
58
|
+
@Roles(Role.SuperAdmin,Role.SuperUser,Role.<%= `${it.typename}_search`%>)
|
|
59
|
+
<%}%>
|
|
60
|
+
@Query(() => schemas.<%= it.typename %>)
|
|
61
|
+
async <%= it.name %>(@AppUser() appuser: UserContext,@Args('id', { type: () => ID } ) id: string): Promise<<%= it.typename %>> {
|
|
62
|
+
|
|
63
|
+
return await this.service.findById(appuser,id)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
/***************************** begin additionalAPI definations *****************************************/
|
|
75
|
+
|
|
76
|
+
<% for(let i=0;i<it.apiSettings.length;i++){%>
|
|
77
|
+
<% let api = it.apiSettings[i] %>
|
|
78
|
+
<% if(api.method!='get') continue %>
|
|
79
|
+
<%if(superadmindoctype.includes(it.doctype)){%>
|
|
80
|
+
@Roles(Role.SuperAdmin,Role.<%= `${it.typename}_${api.action}`%>,
|
|
81
|
+
<%if(api.requiredRole && api.requiredRole.length>0) { %>
|
|
82
|
+
<% for(let r=0;r<api.requiredRole.length;r++){%>Role.<%=api.requiredRole[r]%>,<%}%>
|
|
83
|
+
<%}%>
|
|
84
|
+
)
|
|
85
|
+
<%}else{%>
|
|
86
|
+
@Roles(Role.SuperAdmin,Role.SuperUser,Role.<%= `${it.typename}_${api.action}`%>,
|
|
87
|
+
<%if(api.requiredRole && api.requiredRole.length>0) { %>
|
|
88
|
+
<% for(let r=0;r<api.requiredRole.length;r++){%>Role.<%=api.requiredRole[r]%>,<%}%>
|
|
89
|
+
<%}%>
|
|
90
|
+
)
|
|
91
|
+
<%}%>
|
|
92
|
+
@Query(()=> <%= getFieldType('schema',api.responseType)%>)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
async <%= it.name %><%=capitalizeFirstLetter(api.action) %>(
|
|
97
|
+
@AppUser() appuser: UserContext,
|
|
98
|
+
<% if(api.entryPoint && api.entryPoint.includes(':')) {%>
|
|
99
|
+
<%let subpath = api.entryPoint.split('/')%>
|
|
100
|
+
<% for(let a=0;a<subpath.length;a++){%>
|
|
101
|
+
<%const partstr = subpath[a]%>
|
|
102
|
+
<%if(partstr.includes(':')){%>
|
|
103
|
+
<% const paraname = partstr.replace(':','') %>
|
|
104
|
+
@Args('<%=paraname%>') <%=paraname%>: string,
|
|
105
|
+
<%}%>
|
|
106
|
+
<%}%>
|
|
107
|
+
<%}%>
|
|
108
|
+
){
|
|
109
|
+
|
|
110
|
+
return await this.service.run<%=capitalizeFirstLetter(api.action)%>(appuser,<% if(api.entryPoint && api.entryPoint.includes(':')) {%>
|
|
111
|
+
<%let subpath = api.entryPoint.split('/')%>
|
|
112
|
+
<% for(let a=0;a<subpath.length;a++){%>
|
|
113
|
+
<%const partstr = subpath[a]%>
|
|
114
|
+
<%if(partstr.includes(':')){%>
|
|
115
|
+
<% const paraname = partstr.replace(':','') %>
|
|
116
|
+
<%=paraname%>,
|
|
117
|
+
<%}%>
|
|
118
|
+
<%}%>
|
|
119
|
+
<%}%>
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
<%}%>
|
|
123
|
+
/***************************** end additionalAPI definitions *****************************************/
|
|
124
|
+
}
|
|
@@ -5,12 +5,6 @@
|
|
|
5
5
|
* Author: Ks Tan
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* This file was automatically generated by simpleapp generator.
|
|
10
|
-
|
|
11
|
-
* last change 2023-09-23
|
|
12
|
-
* Author: Ks Tan
|
|
13
|
-
*/
|
|
14
8
|
import { InjectModel } from '@nestjs/mongoose';
|
|
15
9
|
import { Model } from 'mongoose';
|
|
16
10
|
import { Injectable } from '@nestjs/common';
|
package/templates/nest/.env._eta
CHANGED
|
@@ -14,19 +14,19 @@ HTTP_PORT=<%=it.configs.backendPort%>
|
|
|
14
14
|
BPMN_PATH=./src/simpleapp/workflows/bpmn/
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
OAUTH2_BASEURL=<%=it.configs.oauthSetting.oauthBaseUrl%>
|
|
17
|
+
OAUTH2_BASEURL=<%=it.configs.oauthSetting ? it.configs.oauthSetting.oauthBaseUrl : ''%>
|
|
18
18
|
|
|
19
|
-
OAUTH2_REALM=<%=it.configs.oauthSetting.oauthRealm%>
|
|
19
|
+
OAUTH2_REALM=<%=it.configs.oauthSetting ? it.configs.oauthSetting.oauthRealm : ''%>
|
|
20
20
|
|
|
21
|
-
OAUTH2_CONFIGURL=<%=it.configs.oauthSetting.oauthRealmUrl%>
|
|
21
|
+
OAUTH2_CONFIGURL=<%=it.configs.oauthSetting ? it.configs.oauthSetting.oauthRealmUrl : ''%>
|
|
22
22
|
|
|
23
|
-
OAUTH2_CLIENTID=<%=it.configs.oauthSetting.oauthClient%>
|
|
23
|
+
OAUTH2_CLIENTID=<%=it.configs.oauthSetting ? it.configs.oauthSetting.oauthClient : ''%>
|
|
24
24
|
|
|
25
|
-
OAUTH2_CLIENTSECRET=<%=it.configs.oauthSetting.oauthClientSecret%>
|
|
25
|
+
OAUTH2_CLIENTSECRET=<%=it.configs.oauthSetting ? it.configs.oauthSetting.oauthClientSecret : ''%>
|
|
26
26
|
|
|
27
|
-
OAUTH2_ADMINROLE = <%=it.configs.oauthSetting.adminRole%>
|
|
27
|
+
OAUTH2_ADMINROLE = <%=it.configs.oauthSetting ? it.configs.oauthSetting.adminRole : ''%>
|
|
28
28
|
|
|
29
|
-
AUTH_SECRET_KEY=<%=it.configs.oauthSetting.oauthAuthSecretKey%>
|
|
29
|
+
AUTH_SECRET_KEY=<%=it.configs.oauthSetting ? it.configs.oauthSetting.oauthAuthSecretKey : 'any'%>
|
|
30
30
|
|
|
31
31
|
BACKEND_URL=http://localhost:<%=it.configs.backendPort%>
|
|
32
32
|
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This file was automatically generated by simpleapp generator. Every
|
|
3
3
|
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
-
* last change
|
|
4
|
+
* last change 2024-03-17
|
|
5
5
|
* Author: Ks Tan
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { Module, MiddlewareConsumer, NestModule } from '@nestjs/common';
|
|
8
|
+
import { Module, MiddlewareConsumer, NestModule, Provider } from '@nestjs/common';
|
|
9
9
|
import { MongooseModule,MongooseModuleOptions } from '@nestjs/mongoose';
|
|
10
|
+
import { GraphQLModule } from '@nestjs/graphql';
|
|
11
|
+
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';
|
|
12
|
+
|
|
10
13
|
import { APP_GUARD,APP_INTERCEPTOR,APP_FILTER } from '@nestjs/core';
|
|
11
14
|
import { ResponseInterceptor } from './simpleapp/generate/commons/interceptors/response.interceptor'
|
|
12
15
|
import {
|
|
@@ -21,18 +24,27 @@ import {RolesGuard} from './simpleapp/generate/commons/roles/roles.guard'
|
|
|
21
24
|
import { ConfigModule } from '@nestjs/config';
|
|
22
25
|
import { ServeStaticModule } from '@nestjs/serve-static';
|
|
23
26
|
import { join } from 'path';
|
|
27
|
+
import { AppResolver } from './app.resolver';
|
|
24
28
|
import { TenantMiddleware } from './simpleapp/generate/commons/middlewares/tenant.middleware';
|
|
25
29
|
import { AppController } from './app.controller';
|
|
26
30
|
import { AppService } from './app.service';
|
|
27
31
|
import {GenerateModule} from './simpleapp/simpleapp.module'
|
|
32
|
+
import { CloudApiModule } from './cloudapi/cloudapi.module';
|
|
28
33
|
import { UserMongoSchema } from './simpleapp/generate/models/user.model';
|
|
29
34
|
import { PermissionMongoSchema } from './simpleapp/generate/models/perm.model';
|
|
30
35
|
import { ApiEventMongoSchema } from './simpleapp/generate/models/apievent.model';
|
|
31
36
|
import { EventEmitterModule } from '@nestjs/event-emitter';
|
|
32
37
|
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
33
41
|
@Module({
|
|
34
42
|
|
|
35
43
|
imports: [
|
|
44
|
+
GraphQLModule.forRoot<ApolloDriverConfig>({
|
|
45
|
+
driver: ApolloDriver,
|
|
46
|
+
autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
|
|
47
|
+
}),
|
|
36
48
|
ConfigModule.forRoot(),
|
|
37
49
|
EventEmitterModule.forRoot({
|
|
38
50
|
// set this to `true` to use wildcards
|
|
@@ -64,6 +76,7 @@ import { EventEmitterModule } from '@nestjs/event-emitter';
|
|
|
64
76
|
tokenValidation: TokenValidation.ONLINE,
|
|
65
77
|
}),
|
|
66
78
|
GenerateModule,
|
|
79
|
+
CloudApiModule,
|
|
67
80
|
MongooseModule.forFeature([
|
|
68
81
|
{ name: 'User', schema: UserMongoSchema },
|
|
69
82
|
{ name: 'Permission', schema: PermissionMongoSchema },
|
|
@@ -71,30 +84,20 @@ import { EventEmitterModule } from '@nestjs/event-emitter';
|
|
|
71
84
|
]),
|
|
72
85
|
],
|
|
73
86
|
controllers: [AppController],
|
|
74
|
-
providers: [
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
|
|
82
|
-
useClass: ResourceGuard,
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
provide: APP_GUARD,
|
|
86
|
-
useClass: RolesGuard, //use simpleapp own roleguard
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
provide: APP_INTERCEPTOR,
|
|
90
|
-
useClass: ResponseInterceptor,
|
|
91
|
-
},
|
|
92
|
-
],
|
|
87
|
+
providers: [AppService,AppResolver, {
|
|
88
|
+
provide: APP_INTERCEPTOR,
|
|
89
|
+
useClass: ResponseInterceptor,
|
|
90
|
+
},
|
|
91
|
+
{provide: APP_GUARD,useClass: AuthGuard,},
|
|
92
|
+
{provide: APP_GUARD,useClass: ResourceGuard,},
|
|
93
|
+
{provide: APP_GUARD,useClass: RolesGuard,}
|
|
94
|
+
],
|
|
93
95
|
})
|
|
94
96
|
export class AppModule implements NestModule {
|
|
95
97
|
configure(consumer: MiddlewareConsumer) {
|
|
96
98
|
consumer
|
|
97
99
|
.apply(TenantMiddleware)
|
|
100
|
+
// .exclude('/graphql')
|
|
98
101
|
.exclude('/api-yaml')
|
|
99
102
|
.exclude('/api-json')
|
|
100
103
|
.exclude('/api')
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. It is changable
|
|
3
|
+
* --remove-this-line-to-prevent-override--
|
|
4
|
+
* last change 2024-04-19
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
7
|
+
import { Module } from '@nestjs/common';
|
|
8
|
+
import { CloudApiService } from './cloudapi.service';
|
|
9
|
+
@Module({
|
|
10
|
+
imports: [],
|
|
11
|
+
controllers: [],
|
|
12
|
+
providers: [CloudApiService],
|
|
13
|
+
exports: [CloudApiService],
|
|
14
|
+
})
|
|
15
|
+
export class CloudApiModule {}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. It is changable
|
|
3
|
+
* --remove-this-line-to-prevent-override--
|
|
4
|
+
* last change 2024-04-19
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
7
|
+
import { Injectable, InternalServerErrorException } from '@nestjs/common';
|
|
8
|
+
import { UserContext } from 'src/simpleapp/generate/commons/user.context';
|
|
9
|
+
|
|
10
|
+
@Injectable()
|
|
11
|
+
export class CloudApiService {
|
|
12
|
+
constructor() {}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
}
|
|
@@ -14,7 +14,21 @@ export class ForeignKey {
|
|
|
14
14
|
label: string;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
@ObjectType()
|
|
18
|
+
export class CodeLabelValue {
|
|
19
|
+
@ApiProperty({ type: 'string'})
|
|
20
|
+
@Field()
|
|
21
|
+
_id: string;
|
|
22
|
+
@ApiProperty({ type: 'string' })
|
|
23
|
+
@Field()
|
|
24
|
+
code: string
|
|
25
|
+
@ApiProperty({ type: 'string' })
|
|
26
|
+
@Field()
|
|
27
|
+
label: string
|
|
28
|
+
@ApiProperty({ type: Number, required: false, default: 0 })
|
|
29
|
+
@Field()
|
|
30
|
+
value: number
|
|
31
|
+
}
|
|
18
32
|
export class UserAllPermissionsBranches {
|
|
19
33
|
@ApiProperty({ type: 'string', required: true, default: '',})
|
|
20
34
|
permId: string;
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This file was automatically generated by simpleapp generator. Every
|
|
3
3
|
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
-
* last change
|
|
4
|
+
* last change 2024-04-17
|
|
5
5
|
* Author: Ks Tan
|
|
6
6
|
*/
|
|
7
7
|
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
|
|
8
8
|
|
|
9
9
|
export const AppUser = createParamDecorator(
|
|
10
|
-
(data: unknown, ctx: ExecutionContext) => {
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
(data: unknown, ctx: ExecutionContext) => {
|
|
11
|
+
if (ctx.getType() == 'http') {
|
|
12
|
+
const request = ctx.switchToHttp().getRequest();
|
|
13
|
+
return request['sessionuser'];
|
|
14
|
+
} else if (ctx.getArgs()[2]) {
|
|
15
|
+
const req = ctx.getArgs()[2].req;
|
|
16
|
+
return req['sessionuser'];
|
|
17
|
+
}
|
|
18
|
+
return undefined;
|
|
13
19
|
},
|
|
14
|
-
);
|
|
20
|
+
);
|
package/templates/nest/src/simpleapp/generate/commons/interceptors/response.interceptor.ts.eta
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This file was automatically generated by simpleapp generator. Every
|
|
3
3
|
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
-
* last change 2023-
|
|
4
|
+
* last change 2023-03-17
|
|
5
5
|
* Author: Ks Tan
|
|
6
6
|
*/
|
|
7
7
|
import {
|
|
@@ -25,31 +25,41 @@ export class ResponseInterceptor implements NestInterceptor {
|
|
|
25
25
|
@InjectModel('ApiEvent') private apieventmodel: Model<ApiEvent>,
|
|
26
26
|
) {}
|
|
27
27
|
|
|
28
|
-
|
|
29
28
|
async intercept(
|
|
30
29
|
context: ExecutionContext,
|
|
31
30
|
next: CallHandler,
|
|
32
31
|
): Promise<Observable<any>> {
|
|
32
|
+
|
|
33
|
+
//not http request then exclude such as graphql
|
|
34
|
+
if(context.getType()!='http'){
|
|
35
|
+
// obtain usersession here
|
|
36
|
+
return next.handle().pipe(tap(async () => {
|
|
37
|
+
//console.log("none http, do nothing at interceptor")
|
|
38
|
+
}))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
33
42
|
const req = context.switchToHttp().getRequest();
|
|
34
43
|
const resp = context.switchToHttp().getResponse();
|
|
44
|
+
//console.log("want to get user session:", Object.keys(req))
|
|
35
45
|
const usersession: UserContext = req['sessionuser'];
|
|
36
|
-
|
|
46
|
+
//console.log("after read user session:",usersession)
|
|
37
47
|
const method = req['method'];
|
|
38
48
|
const headers = { ...req['headers'] };
|
|
39
49
|
const ip = req['ip'];
|
|
40
50
|
const url = req['url'];
|
|
41
51
|
// let { url, method, headers, body }
|
|
42
52
|
const session = await this.connection.startSession();
|
|
43
|
-
if(!session['runCount']){
|
|
44
|
-
session['runCount']=0
|
|
45
|
-
}else{
|
|
46
|
-
session['runCount']=session['runCount']+1
|
|
47
|
-
}
|
|
48
|
-
usersession.setDBSession(session)
|
|
53
|
+
if (!session['runCount']) {
|
|
54
|
+
session['runCount'] = 0;
|
|
55
|
+
} else {
|
|
56
|
+
session['runCount'] = session['runCount'] + 1;
|
|
57
|
+
}
|
|
58
|
+
usersession.setDBSession(session);
|
|
49
59
|
// const session: ClientSession = usersession.getDBSession();
|
|
50
60
|
const logid: string = crypto.randomUUID();
|
|
51
61
|
const starttime = new Date();
|
|
52
|
-
let canCommit = true
|
|
62
|
+
let canCommit = true;
|
|
53
63
|
//authorization no need
|
|
54
64
|
delete headers['authorization']; //='--removed--'
|
|
55
65
|
const eventdata: ApiEvent = {
|
|
@@ -71,37 +81,33 @@ export class ResponseInterceptor implements NestInterceptor {
|
|
|
71
81
|
|
|
72
82
|
// req['eventObj'] = eventObj;
|
|
73
83
|
return next.handle().pipe(
|
|
74
|
-
|
|
75
|
-
catchError( async(err,caught)=>{
|
|
76
|
-
|
|
84
|
+
catchError(async (err, caught) => {
|
|
77
85
|
// console.log('**************catchError at interceptor ',method,url)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const responseBody = {
|
|
86
|
+
if (session.inTransaction()) {
|
|
87
|
+
await session.abortTransaction();
|
|
88
|
+
canCommit = false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const responseBody = {
|
|
85
92
|
message: err.message,
|
|
86
93
|
timestamp: new Date().toISOString(),
|
|
87
94
|
path: url,
|
|
88
95
|
error: err.options,
|
|
89
96
|
};
|
|
90
|
-
|
|
91
|
-
// eventObj.statusCode = err.status;
|
|
92
|
-
// eventObj.errMsg = responseBody.message;
|
|
93
|
-
// const endtime = new Date();
|
|
94
|
-
// eventObj.updated = endtime.toISOString();
|
|
95
|
-
// eventObj.data = req.body;
|
|
96
|
-
// eventObj.errData = responseBody.error;
|
|
97
|
-
// eventObj.status = 'NG';
|
|
98
|
-
// eventObj.duration =
|
|
99
|
-
// endtime.getTime() - new Date(eventObj.created).getTime();
|
|
100
|
-
// eventObj.save();
|
|
101
97
|
|
|
102
|
-
|
|
103
|
-
|
|
98
|
+
// eventObj.statusCode = err.status;
|
|
99
|
+
// eventObj.errMsg = responseBody.message;
|
|
100
|
+
// const endtime = new Date();
|
|
101
|
+
// eventObj.updated = endtime.toISOString();
|
|
102
|
+
// eventObj.data = req.body;
|
|
103
|
+
// eventObj.errData = responseBody.error;
|
|
104
|
+
// eventObj.status = 'NG';
|
|
105
|
+
// eventObj.duration =
|
|
106
|
+
// endtime.getTime() - new Date(eventObj.created).getTime();
|
|
107
|
+
// eventObj.save();
|
|
104
108
|
|
|
109
|
+
resp.status(err.status);
|
|
110
|
+
return responseBody;
|
|
105
111
|
}),
|
|
106
112
|
tap(async () => {
|
|
107
113
|
// console.log("============interceptor tap",method,url)
|
|
@@ -111,17 +117,16 @@ export class ResponseInterceptor implements NestInterceptor {
|
|
|
111
117
|
eventObj.updated = endtime.toISOString();
|
|
112
118
|
eventObj.status = 'OK';
|
|
113
119
|
eventObj.duration = endtime.getTime() - starttime.getTime();
|
|
114
|
-
await eventObj.save();
|
|
115
|
-
|
|
120
|
+
await eventObj.save();
|
|
116
121
|
|
|
117
122
|
if (process.env.DRYRUN == 'true') {
|
|
118
123
|
console.warn('--------dryrun! roll back everything-----------');
|
|
119
|
-
if (session.inTransaction() && canCommit
|
|
120
|
-
await session.abortTransaction()
|
|
124
|
+
if (session.inTransaction() && canCommit) {
|
|
125
|
+
await session.abortTransaction();
|
|
121
126
|
}
|
|
122
127
|
} else {
|
|
123
|
-
if (session.inTransaction() && canCommit
|
|
124
|
-
await session.commitTransaction()//.then(()=>session.endSession());
|
|
128
|
+
if (session.inTransaction() && canCommit) {
|
|
129
|
+
await session.commitTransaction(); //.then(()=>session.endSession());
|
|
125
130
|
}
|
|
126
131
|
}
|
|
127
132
|
// session.endSession()
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This file was automatically generated by simpleapp generator. Every
|
|
3
3
|
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
-
* last change
|
|
4
|
+
* last change 2024-03-17
|
|
5
5
|
* Author: Ks Tan
|
|
6
6
|
*/
|
|
7
7
|
import {
|
|
@@ -52,6 +52,19 @@ export class TenantMiddleware implements NestMiddleware {
|
|
|
52
52
|
next();
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
|
+
const u = new UserContext(this.usermodel, this.permmodel);
|
|
56
|
+
|
|
57
|
+
if (req.baseUrl == '/graphql') {
|
|
58
|
+
let tokenstr: string = req.headers['authorization'] ?? '';
|
|
59
|
+
tokenstr = tokenstr.replace('Bearer ', '');
|
|
60
|
+
const xorg = req.headers['x-org'] ?? this.defaultxorg;
|
|
61
|
+
if (tokenstr) {
|
|
62
|
+
await u.setCurrentUserInfo(tokenstr, xorg);
|
|
63
|
+
}
|
|
64
|
+
req['sessionuser'] = u;
|
|
65
|
+
next();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
55
68
|
this.logger.debug(`running TenantMiddleware for ${req.baseUrl}`);
|
|
56
69
|
if (!req.headers['authorization']) {
|
|
57
70
|
this.logger.log('undefine bearer token');
|
|
@@ -62,11 +75,10 @@ export class TenantMiddleware implements NestMiddleware {
|
|
|
62
75
|
'undefine x-org and require that at ' + req.baseUrl,
|
|
63
76
|
'TenantMiddleware',
|
|
64
77
|
);
|
|
65
|
-
throw new BadRequestException('undefine header string x-org')
|
|
78
|
+
throw new BadRequestException('undefine header string x-org');
|
|
66
79
|
// return res.status(401).send('undefine header string x-org');
|
|
67
80
|
}
|
|
68
81
|
// const session = await this.connection.startSession();
|
|
69
|
-
const u = new UserContext(this.usermodel, this.permmodel);
|
|
70
82
|
// console.log("line 43")
|
|
71
83
|
try {
|
|
72
84
|
let tokenstr: string = req.headers['authorization'];
|
|
@@ -95,7 +107,7 @@ export class TenantMiddleware implements NestMiddleware {
|
|
|
95
107
|
}
|
|
96
108
|
} catch (err) {
|
|
97
109
|
this.logger.error(err);
|
|
98
|
-
throw new BadRequestException(err
|
|
110
|
+
throw new BadRequestException(err);
|
|
99
111
|
}
|
|
100
112
|
}
|
|
101
113
|
}
|