@simitgroup/simpleapp-generator 1.0.47 → 1.0.48
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 +35 -1
- package/buildinschemas copy/docnoformat.docno.jsonschema.json +2 -20
- package/dist/buildinschemas/autoincreament.js +1 -1
- package/dist/buildinschemas/autoincreament.js.map +1 -1
- package/dist/buildinschemas/branch.js +1 -1
- package/dist/buildinschemas/branch.js.map +1 -1
- package/dist/buildinschemas/docnoformat.d.ts.map +1 -1
- package/dist/buildinschemas/docnoformat.js +12 -25
- package/dist/buildinschemas/docnoformat.js.map +1 -1
- package/dist/buildinschemas/user.d.ts.map +1 -1
- package/dist/buildinschemas/user.js +1 -0
- package/dist/buildinschemas/user.js.map +1 -1
- package/dist/framework.d.ts.map +1 -1
- package/dist/framework.js +10 -2
- package/dist/framework.js.map +1 -1
- package/dist/generate.js +24 -13
- package/dist/generate.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/type.d.ts +1 -0
- package/dist/type.d.ts.map +1 -1
- package/dist/type.js.map +1 -1
- package/package.json +1 -1
- package/src/buildinschemas/autoincreament.ts +1 -1
- package/src/buildinschemas/branch.ts +1 -1
- package/src/buildinschemas/docnoformat.ts +13 -27
- package/src/buildinschemas/user.ts +1 -0
- package/src/framework.ts +10 -2
- package/src/generate.ts +26 -13
- package/src/index.ts +1 -1
- package/src/type.ts +1 -0
- package/templates/basic/nest/processor.ts.eta +2 -2
- package/templates/basic/nest/service.ts.eta +2 -4
- package/templates/basic/nuxt/pages.crud.vue.eta +1 -1
- package/templates/nest/src/app.controller.ts.eta +6 -0
- package/templates/nest/src/app.module.ts.eta +9 -1
- package/templates/nest/src/app.service.ts.eta +6 -0
- package/templates/nest/src/main.ts.eta +7 -0
- package/templates/nest/src/simpleapp/generate/apischemas/index.ts.eta +6 -2
- package/templates/nest/src/simpleapp/generate/commons/audittrail.service.ts.eta +17 -0
- package/templates/nest/src/simpleapp/generate/commons/decorators/appuser.decorator.ts.eta +6 -0
- package/templates/nest/src/simpleapp/generate/commons/dicts/documents.ts.eta +14 -0
- package/templates/nest/src/simpleapp/generate/commons/dicts/foreignkeys.ts.eta +6 -0
- package/templates/nest/src/simpleapp/generate/commons/docnogenerator.service.ts.eta +9 -3
- package/templates/nest/src/simpleapp/generate/commons/exceptions/SimpleAppExceptionFilter.ts.eta +23 -3
- package/templates/nest/src/simpleapp/generate/commons/interceptors/response.interceptor.ts.eta +52 -10
- package/templates/nest/src/simpleapp/generate/commons/middlewares/tenant.middleware.ts.eta +6 -0
- package/templates/nest/src/simpleapp/generate/commons/providers/workflow.provider.ts.etax +6 -0
- package/templates/nest/src/simpleapp/generate/commons/roles/roles.decorator.ts.eta +6 -1
- package/templates/nest/src/simpleapp/generate/commons/roles/roles.enum.ts.eta +6 -0
- package/templates/nest/src/simpleapp/generate/commons/roles/roles.group.ts.eta +6 -0
- package/templates/nest/src/simpleapp/generate/commons/roles/roles.guard.ts.eta +6 -1
- package/templates/nest/src/simpleapp/generate/commons/user.context.ts.eta +15 -7
- package/templates/nest/src/simpleapp/generate/controllers/simpleapp.controller.ts.eta +6 -0
- package/templates/nest/src/simpleapp/generate/models/apievent.model.ts.eta +27 -0
- package/templates/nest/src/simpleapp/generate/models/perm.model.ts.eta +3 -4
- package/templates/nest/src/simpleapp/generate/models/tenant.model.ts.eta +3 -5
- package/templates/nest/src/simpleapp/generate/models/user.model.ts.eta +3 -4
- package/templates/nest/src/simpleapp/generate/processors/simpleapp.processor.ts.eta +42 -11
- package/templates/nest/src/simpleapp/generate/types/apievent.type.ts.eta +22 -0
- package/templates/nest/src/simpleapp/generate/types/index.ts.eta +6 -0
- package/templates/nest/src/simpleapp/profile/profile.apischema.ts.eta +6 -0
- package/templates/nest/src/simpleapp/profile/profile.controller.ts.eta +6 -0
- package/templates/nest/src/simpleapp/profile/profile.service.ts.eta +6 -0
- package/templates/nest/src/simpleapp/profile/profile.types.ts.eta +6 -0
- package/templates/nest/src/simpleapp/services/autoinc.service.ts.eta +5 -6
- package/templates/nest/src/simpleapp/services/branch.service.ts.eta +50 -10
- package/templates/nest/src/simpleapp/services/docno.service.ts.eta +5 -7
- package/templates/nest/src/simpleapp/services/org.service.ts.eta +4 -6
- package/templates/nest/src/simpleapp/services/perm.service.ts.eta +6 -7
- package/templates/nest/src/simpleapp/services/tenant.service.ts.eta +5 -6
- package/templates/nest/src/simpleapp/services/user.service.ts.eta +5 -6
- package/templates/nest/src/simpleapp/simpleapp.module.ts.eta +6 -8
- package/templates/nuxt/app.vue.eta +6 -1
- package/templates/nuxt/assets/css/style.css._eta +12 -0
- package/templates/nuxt/assets/css/tailwind.css._eta +10 -0
- package/templates/nuxt/assets/primevue/passthrough.ts._eta +37 -0
- package/templates/nuxt/components/ButtonCreateTenant.vue.eta +68 -0
- package/templates/nuxt/components/ButtonHome.vue.eta +10 -0
- package/templates/nuxt/components/ButtonLogout.vue.eta +9 -0
- package/templates/nuxt/components/ButtonMenuPicker.vue.eta +55 -0
- package/templates/nuxt/components/ButtonPermissionInfo.vue.eta +113 -0
- package/templates/nuxt/components/ButtonProfile.vue.eta +52 -0
- package/templates/nuxt/components/CrudNestedDoc.vue.eta +11 -7
- package/templates/nuxt/components/CrudSimple.vue.eta +13 -11
- package/templates/nuxt/components/DebugDocumentData.vue.eta +1 -1
- package/templates/nuxt/components/HeaderBar.vue.eta +39 -0
- package/templates/nuxt/components/Invitation.vue.eta +2 -2
- package/templates/nuxt/components/Menus.vue.eta +6 -6
- package/templates/nuxt/components/SelectBranch.vue.eta +35 -0
- package/templates/nuxt/components/SimpleAppDatatable.vue.eta +0 -1
- package/templates/nuxt/components/SimpleAppDocumentNo.vue.eta +1 -1
- package/templates/nuxt/components/SimpleAppInputTable.vue.eta +2 -2
- package/templates/nuxt/components/SimpleFieldContainer.vue.eta +18 -12
- package/templates/nuxt/components/Spinner.vue.eta +9 -0
- package/templates/nuxt/composables/getMenus.generate.ts.eta +5 -4
- package/templates/nuxt/layouts/default.vue.eta +3 -12
- package/templates/nuxt/middleware/{10.acl.global.ts.eta → 30.acl.global.ts.eta} +6 -0
- package/templates/nuxt/nuxt.config.ts.eta +55 -12
- package/templates/nuxt/pages/[xorg]/docnoformat/index.vue.eta +83 -113
- package/templates/nuxt/pages/[xorg]/index.vue._eta +13 -0
- package/templates/nuxt/pages/[xorg]/organization/index.vue.eta +89 -65
- package/templates/nuxt/pages/[xorg]/permission/index.vue.eta +7 -7
- package/templates/nuxt/pages/[xorg]/user/index.vue.eta +33 -33
- package/templates/nuxt/pages/index.vue.eta +10 -85
- package/templates/nuxt/pages/login.vue.eta +9 -3
- package/templates/nuxt/plugins/10.simpleapp-event.ts.eta +16 -19
- package/templates/nuxt/plugins/20.simpleapp-userstore.ts.eta +19 -3
- package/templates/nuxt/plugins/50.simpleapp-client.ts.eta +4 -4
- package/templates/nuxt/server/api/[xorg]/[...].ts.eta +4 -4
- package/templates/nuxt/server/api/auth/[...].ts.eta +6 -0
- package/templates/nuxt/server/api/auth/logout.ts.eta +6 -1
- package/templates/nuxt/server/api/profile/[...].ts.eta +4 -5
- package/templates/nuxt/server/api/profile/index.ts.eta +4 -6
- package/templates/nuxt/simpleapp/generate/clients/SimpleAppClient.ts.eta +9 -2
- package/templates/nuxt/simpleapp/generate/commons/documents.ts.eta +12 -3
- package/templates/nuxt/simpleapp/generate/commons/events.ts.eta +6 -0
- package/templates/nuxt/simpleapp/generate/commons/groups.ts.eta +6 -0
- package/templates/nuxt/simpleapp/generate/commons/roles.ts.eta +6 -0
- package/templates/nuxt/tailwind.config.ts._eta +66 -0
- package/templates/nuxt/types/index.ts.eta +22 -1
- package/templates/project/build.sh.eta +4 -4
- package/templates/project/schemas/invoice.ts.eta +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/templates/nuxt/assets/css/tailwind.css.eta +0 -35
- package/templates/nuxt/components/PermissionInfo.vue.eta +0 -92
- package/templates/nuxt/pages/[xorg]/index.vue.eta +0 -36
- package/templates/nuxt/tailwind.config.ts.eta +0 -9
- /package/templates/nest/{.env.eta → .env._eta} +0 -0
- /package/templates/nuxt/{.env.eta → .env._eta} +0 -0
- /package/templates/nuxt/pages/[xorg]/branch/{index.vue.eta → index.vue.etax} +0 -0
- /package/templates/project/{config.json.eta → config.json._eta} +0 -0
package/src/framework.ts
CHANGED
|
@@ -126,6 +126,14 @@ export const prepareProject = async (callback)=>{
|
|
|
126
126
|
// log.info(fullfilename+"====>>"+tofilename)
|
|
127
127
|
// console.log(txt)
|
|
128
128
|
writeFileSync(tofilename,txt)
|
|
129
|
+
}else if(filename.includes('._eta')){
|
|
130
|
+
const tofilename =targetfolder + filename.replace('._eta','')
|
|
131
|
+
log.info(tofilename,"Render file")
|
|
132
|
+
const txt = eta.render(fullfilename,vars)
|
|
133
|
+
if(!existsSync(tofilename)){
|
|
134
|
+
writeFileSync(tofilename,txt)
|
|
135
|
+
}
|
|
136
|
+
|
|
129
137
|
}else if(filename.includes('.md')){
|
|
130
138
|
const tofilename =dir + filename.replace('.eta','')
|
|
131
139
|
log.info(tofilename,"Copy")
|
|
@@ -149,10 +157,10 @@ export const prepareNuxt = (callback:Function)=>{
|
|
|
149
157
|
const targetfolder = config.frontendFolder
|
|
150
158
|
if(!fs.existsSync(`${targetfolder}/.env`)){
|
|
151
159
|
//asume no environment. prepare now
|
|
152
|
-
exec(`cd ${targetfolder};pnpm install;pnpm install -D @nuxtjs/tailwindcss @sidebase/nuxt-auth @nuxt/ui @types/node @vueuse/nuxt @sidebase/nuxt-auth @vueuse/core
|
|
160
|
+
exec(`cd ${targetfolder};pnpm install;pnpm install -D nuxt-primevue @nuxtjs/tailwindcss @sidebase/nuxt-auth @nuxt/ui @types/node @vueuse/nuxt @sidebase/nuxt-auth @vueuse/core prettier `, (error, stdout, stderr)=>{
|
|
153
161
|
//;pnpm install
|
|
154
162
|
console.log(error, stdout, stderr)
|
|
155
|
-
exec(`cd ${targetfolder};pnpm install --save jsonpath pinia @pinia/nuxt @nuxt/kit lodash @types/lodash @darkwolf/base64url next-auth@4.21.1 @darkwolf/base64url @nuxt/ui ajv ajv-formats ajv-errors dotenv @fullcalendar/core @fullcalendar/vue3 quill
|
|
163
|
+
exec(`cd ${targetfolder};pnpm install --save primeicons moment memory-cache jsonpath pinia @pinia/nuxt @nuxt/kit lodash @types/lodash @darkwolf/base64url next-auth@4.21.1 @darkwolf/base64url @nuxt/ui ajv ajv-formats ajv-errors dotenv @fullcalendar/core @fullcalendar/vue3 quill prettier axios json-schema mitt `, (error, stdout, stderr)=>{
|
|
156
164
|
console.log(error, stdout, stderr)
|
|
157
165
|
|
|
158
166
|
// fs.mkdirSync(`${targetfolder}/assets/css/`,{recursive:true})
|
package/src/generate.ts
CHANGED
|
@@ -92,15 +92,15 @@ export const run = async (paraconfigs:any,genFor:string[],callback:Function) =>
|
|
|
92
92
|
await processSchema(file.replace('.json',''),jsonschema)
|
|
93
93
|
}
|
|
94
94
|
// //generate groups
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
95
|
+
const systemgroups = readdirSync(`${groupFolder}`)
|
|
96
|
+
for(let g = 0; g< systemgroups.length;g++){
|
|
97
|
+
const groupfile = systemgroups[g]
|
|
98
|
+
const groupjsonstr = readFileSync(`${groupFolder}/${groupfile}`, 'utf-8');
|
|
99
|
+
const groupdata = JSON.parse(groupjsonstr);
|
|
100
|
+
const documentname = groupfile.split('.')[0]
|
|
101
|
+
const roles = prepareRoles(groupdata)
|
|
102
|
+
allroles[documentname]=roles
|
|
103
|
+
}
|
|
104
104
|
finalize(activatemodules)
|
|
105
105
|
callback()
|
|
106
106
|
}
|
|
@@ -128,6 +128,7 @@ const processSchema= async (schemaname:string,jsondata:JSONSchema7)=>{
|
|
|
128
128
|
// const jsondata = JSON.parse(jsonstring);
|
|
129
129
|
const rendertype = 'basic';
|
|
130
130
|
jsonschemas[docname] = jsondata;
|
|
131
|
+
const copyofjsonschema = {...jsondata}
|
|
131
132
|
const allmodels:ChildModels = await readJsonSchemaBuilder(docname, jsondata);
|
|
132
133
|
// log.error("allmodels",docname,schemaname)
|
|
133
134
|
generateSchema(docname, doctype, rendertype, allmodels);
|
|
@@ -135,7 +136,8 @@ const processSchema= async (schemaname:string,jsondata:JSONSchema7)=>{
|
|
|
135
136
|
doctype:doctype,
|
|
136
137
|
docname:capitalizeFirstLetter(docname),
|
|
137
138
|
pagetype: config.pageType??'',
|
|
138
|
-
api:config.additionalApis
|
|
139
|
+
api:config.additionalApis,
|
|
140
|
+
schema : copyofjsonschema
|
|
139
141
|
})
|
|
140
142
|
// } else {
|
|
141
143
|
// log.warn(`Load `+clc.yellow(file) + ` but it is not supported`)
|
|
@@ -339,15 +341,26 @@ const finalize=(modules:ModuleObject[])=>{
|
|
|
339
341
|
const arrfilename:string[] = filename.split('.')
|
|
340
342
|
// log.info("check longfilename:::",longfilename,"become====",arrfilename)
|
|
341
343
|
//only process .eta
|
|
342
|
-
if(_.last(arrfilename)=='eta'){
|
|
344
|
+
if(_.last(arrfilename)=='eta'|| _.last(arrfilename)=='_eta'){
|
|
343
345
|
const relativepath = longfilename.includes('/') ? longfilename.replace(`/${filename}`,'') : ''
|
|
344
346
|
const foldername = `${frameworkpath}/${relativepath}`
|
|
345
|
-
const shortfilename = filename.replace('.eta','')
|
|
347
|
+
const shortfilename = filename.replace('.eta','').replace('._eta','')
|
|
346
348
|
const targetfilename = `${foldername}/${shortfilename}`
|
|
349
|
+
let forceoverride=true
|
|
350
|
+
if(filename.includes('._eta')){
|
|
351
|
+
forceoverride=false
|
|
352
|
+
}
|
|
353
|
+
// log.warn("Process=== ",targetfilename)
|
|
354
|
+
if(existsSync(targetfilename) && forceoverride == false){
|
|
355
|
+
log.info("file exists, skip: ",targetfilename)
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
|
|
347
360
|
if(!existsSync(foldername)){
|
|
348
361
|
mkdirSync(foldername,{recursive:true})
|
|
349
362
|
}
|
|
350
|
-
const templatename = `${frameworkfolder}/${longfilename}`.replace(".eta","")
|
|
363
|
+
// const templatename = `${frameworkfolder}/${longfilename}`.replace(".eta","").replace('._eta','')
|
|
351
364
|
log.info("Write template:",targetfilename)
|
|
352
365
|
const txt = eta.render(longfilename, renderProperties)
|
|
353
366
|
writeFileSync(targetfilename,txt)
|
package/src/index.ts
CHANGED
package/src/type.ts
CHANGED
|
@@ -33,8 +33,8 @@ export class <%= it.typename %>Processor extends SimpleAppService<<%= it.typenam
|
|
|
33
33
|
|
|
34
34
|
protected foreignkeys = <%~ JSON.stringify(it.foreignkeys)%>
|
|
35
35
|
|
|
36
|
-
constructor(mydoc: Model<<%= it.typename
|
|
37
|
-
super('<%= it.doctype.toUpperCase() %>','<%= it.name %>',mydoc,IsolationType.<%=it.isolationtype
|
|
36
|
+
constructor(mydoc: Model<<%= it.typename %>>) {
|
|
37
|
+
super('<%= it.doctype.toUpperCase() %>','<%= it.name %>',mydoc,IsolationType.<%=it.isolationtype%>);
|
|
38
38
|
this.setSchema(<%= it.typename%>JsonSchema)
|
|
39
39
|
this.setData(Default<%=it.typename%>(crypto.randomUUID()))
|
|
40
40
|
<%if(it.moreAutoComplete.length>0){%>
|
|
@@ -8,7 +8,6 @@ import { InjectModel } from '@nestjs/mongoose';
|
|
|
8
8
|
import { Model } from 'mongoose';
|
|
9
9
|
import { Injectable } from '@nestjs/common';
|
|
10
10
|
import { UserContext } from '../generate/commons/user.context';
|
|
11
|
-
import {DocNumberFormatGenerator} from '../generate/commons/docnogenerator.service'
|
|
12
11
|
import { <%= it.typename %>Processor } from '../generate/processors/<%= it.doctype %>.processor';
|
|
13
12
|
import { <%= it.typename %>} from '../generate/types/<%= it.doctype %>.type';
|
|
14
13
|
export { <%= it.typename %>} from '../generate/types/<%= it.doctype %>.type';
|
|
@@ -18,10 +17,9 @@ export { <%= it.typename %>} from '../generate/types/<%= it.doctype %>.type';
|
|
|
18
17
|
export class <%= it.typename %>Service extends <%= it.typename %>Processor {
|
|
19
18
|
|
|
20
19
|
constructor(
|
|
21
|
-
@InjectModel('<%= it.typename %>') mydoc: Model<<%= it.typename
|
|
22
|
-
docnogenerator:DocNumberFormatGenerator
|
|
20
|
+
@InjectModel('<%= it.typename %>') mydoc: Model<<%= it.typename %>>
|
|
23
21
|
){
|
|
24
|
-
super(mydoc
|
|
22
|
+
super(mydoc)
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
// hook = async (appuser:UserContext,type: string, data?: any) => {
|
|
@@ -170,7 +170,7 @@
|
|
|
170
170
|
</column>
|
|
171
171
|
<%}%>
|
|
172
172
|
<column #body="{index}" header="Delete">
|
|
173
|
-
<
|
|
173
|
+
<Button class="btn-danger" type="button" @click="data.<%=key%>.splice(index,1)">X</Button>
|
|
174
174
|
</column>
|
|
175
175
|
</SimpleAppInputTable>
|
|
176
176
|
<% } else{%>
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2023-10-28
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
1
7
|
import { Controller, Get,Logger } from '@nestjs/common';
|
|
2
8
|
import { AppService } from './app.service';
|
|
3
9
|
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2023-10-28
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
import { Module, MiddlewareConsumer, NestModule } from '@nestjs/common';
|
|
2
9
|
import { MongooseModule,MongooseModuleOptions } from '@nestjs/mongoose';
|
|
3
10
|
import { APP_GUARD,APP_INTERCEPTOR,APP_FILTER } from '@nestjs/core';
|
|
@@ -20,7 +27,7 @@ import { AppService } from './app.service';
|
|
|
20
27
|
import {GenerateModule} from './simpleapp/simpleapp.module'
|
|
21
28
|
import { UserMongoSchema } from './simpleapp/generate/models/user.model';
|
|
22
29
|
import { PermissionMongoSchema } from './simpleapp/generate/models/perm.model';
|
|
23
|
-
|
|
30
|
+
import { ApiEventMongoSchema } from './simpleapp/generate/models/apievent.model';
|
|
24
31
|
@Module({
|
|
25
32
|
//define environment variables: MONGODB_URL='mongodb://<user>:<pass>@<host>:<port>/<db>?authMechanism=DEFAULT'
|
|
26
33
|
imports: [
|
|
@@ -42,6 +49,7 @@ import { PermissionMongoSchema } from './simpleapp/generate/models/perm.model';
|
|
|
42
49
|
MongooseModule.forFeature([
|
|
43
50
|
{ name: 'User', schema: UserMongoSchema },
|
|
44
51
|
{ name: 'Permission', schema: PermissionMongoSchema },
|
|
52
|
+
{ name: 'ApiEvent', schema: ApiEventMongoSchema },
|
|
45
53
|
])
|
|
46
54
|
],
|
|
47
55
|
controllers: [AppController],
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2023-10-28
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
1
7
|
import { Injectable } from '@nestjs/common';
|
|
2
8
|
// import { Workflow } from './simpleapp/generate/commons/providers/Workflow';
|
|
3
9
|
@Injectable()
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2023-10-28
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
import { NestFactory } from '@nestjs/core';
|
|
2
9
|
import { AppModule } from './app.module';
|
|
3
10
|
import { SimpleAppExceptionFilter } from './simpleapp/generate/commons/exceptions/SimpleAppExceptionFilter';
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2023-10-28
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
1
7
|
|
|
2
8
|
import { ApiProperty } from '@nestjs/swagger';
|
|
3
|
-
|
|
4
|
-
|
|
5
9
|
export class ApiKeyValuePair {
|
|
6
10
|
@ApiProperty({"type":Object,"required":false,"examples":['{"field1":"1"}'],"default":""} )
|
|
7
11
|
field1: any
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2023-10-28
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
7
|
+
import { Injectable } from "@nestjs/common";
|
|
8
|
+
|
|
9
|
+
@Injectable()
|
|
10
|
+
export class AuditTrail {
|
|
11
|
+
constructor(){
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
addEvent(data:any){
|
|
15
|
+
console.log("Add event into db:",data)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2023-10-28
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
1
7
|
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
|
|
2
8
|
|
|
3
9
|
export const AppUser = createParamDecorator(
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2023-10-28
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
7
|
+
export const alldocuments:any[] = [
|
|
8
|
+
<%for(let i=0; i<it.modules.length;i++){ %>
|
|
9
|
+
<% const d = it.modules[i] %>
|
|
10
|
+
<% const conf = d.schema["x-simpleapp-config"] %>
|
|
11
|
+
{docName:'<%= d['docname'] %>',docType:'<%= d['doctype'].toUpperCase()%>',page: '<%=d['pagetype']%>', isolationType:'<%=conf['isolationType']%>',
|
|
12
|
+
documentDate:'<%=conf['documentDate']??""%>', docNumber:<%=conf['generateDocumentNumber']??false%>},
|
|
13
|
+
<%}%>
|
|
14
|
+
]
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2023-10-28
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
1
7
|
import { UserContext } from './user.context';
|
|
2
8
|
import { InjectModel } from '@nestjs/mongoose';
|
|
3
9
|
import { Model } from 'mongoose';
|
|
@@ -61,7 +67,7 @@ export class DocNumberFormatGenerator{
|
|
|
61
67
|
static previewDocNo = (s: Docnoformat) => {
|
|
62
68
|
try {
|
|
63
69
|
const pattern = s.docNoPattern;
|
|
64
|
-
const numberReg: RegExp =
|
|
70
|
+
const numberReg: RegExp = /\[(.*?)\]/g;
|
|
65
71
|
const dateReg: RegExp = /\{(.*?)\}/g;
|
|
66
72
|
let newvalue = pattern;
|
|
67
73
|
const numberpattern: string[] = pattern.match(numberReg);
|
|
@@ -69,8 +75,8 @@ export class DocNumberFormatGenerator{
|
|
|
69
75
|
|
|
70
76
|
if (numberpattern && numberpattern.length > 0) {
|
|
71
77
|
const numberlength = numberpattern[0]
|
|
72
|
-
.replace('
|
|
73
|
-
.replace('
|
|
78
|
+
.replace('[', '')
|
|
79
|
+
.replace(']', '').length;
|
|
74
80
|
|
|
75
81
|
let nextnumber = s.nextNumber.toString();
|
|
76
82
|
|
package/templates/nest/src/simpleapp/generate/commons/exceptions/SimpleAppExceptionFilter.ts.eta
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2023-10-28
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
1
7
|
import {
|
|
2
8
|
ExceptionFilter,
|
|
3
9
|
Catch,
|
|
@@ -9,7 +15,8 @@ import { HttpAdapterHost } from '@nestjs/core';
|
|
|
9
15
|
import { ClientSession } from 'mongoose';
|
|
10
16
|
@Catch()
|
|
11
17
|
export class SimpleAppExceptionFilter implements ExceptionFilter {
|
|
12
|
-
constructor(
|
|
18
|
+
constructor(
|
|
19
|
+
private readonly httpAdapterHost: HttpAdapterHost) {}
|
|
13
20
|
|
|
14
21
|
catch(exception, host: ArgumentsHost): void {
|
|
15
22
|
// In certain situations `httpAdapter` might not be available in the
|
|
@@ -17,6 +24,7 @@ export class SimpleAppExceptionFilter implements ExceptionFilter {
|
|
|
17
24
|
const { httpAdapter } = this.httpAdapterHost;
|
|
18
25
|
const ctx = host.switchToHttp();
|
|
19
26
|
const request = ctx.getRequest<Request>();
|
|
27
|
+
|
|
20
28
|
if(request['sessionuser']){
|
|
21
29
|
const session:ClientSession = request['sessionuser'].getDBSession()
|
|
22
30
|
if(session.inTransaction())session.abortTransaction()
|
|
@@ -32,8 +40,20 @@ export class SimpleAppExceptionFilter implements ExceptionFilter {
|
|
|
32
40
|
// console.log("exception properties", Object.getOwnPropertyNames(exception),exception.options)
|
|
33
41
|
|
|
34
42
|
// console.log("exception.responseexception.response",exception)
|
|
35
|
-
|
|
43
|
+
const finalstatus = exception.response.status??exception.status
|
|
44
|
+
const eventObj = request['eventObj']
|
|
45
|
+
if(eventObj){
|
|
46
|
+
eventObj.statusCode=finalstatus
|
|
47
|
+
eventObj.errMsg=responseBody.message
|
|
48
|
+
const endtime =new Date()
|
|
49
|
+
eventObj.updated = endtime.toISOString()
|
|
50
|
+
eventObj.data = request.body
|
|
51
|
+
eventObj.errData = responseBody.error
|
|
52
|
+
eventObj.status="NG"
|
|
53
|
+
eventObj.duration = endtime.getTime() - new Date(eventObj.created).getTime()
|
|
54
|
+
eventObj.save()
|
|
55
|
+
}
|
|
36
56
|
|
|
37
|
-
httpAdapter.reply(ctx.getResponse(), responseBody,
|
|
57
|
+
httpAdapter.reply(ctx.getResponse(), responseBody,finalstatus);
|
|
38
58
|
}
|
|
39
59
|
}
|
package/templates/nest/src/simpleapp/generate/commons/interceptors/response.interceptor.ts.eta
CHANGED
|
@@ -1,30 +1,72 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2023-10-28
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
2
7
|
import { Injectable, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
3
8
|
import { Observable } from 'rxjs';
|
|
4
9
|
import { tap } from 'rxjs/operators';
|
|
5
10
|
import { Model,Connection, ClientSession } from 'mongoose';
|
|
6
|
-
import { InjectConnection } from '@nestjs/mongoose';
|
|
11
|
+
import { InjectConnection,InjectModel } from '@nestjs/mongoose';
|
|
7
12
|
import { UserContext } from '../user.context';
|
|
13
|
+
import { ApiEvent } from '../../types/apievent.type';
|
|
8
14
|
@Injectable()
|
|
9
15
|
export class ResponseInterceptor implements NestInterceptor {
|
|
10
16
|
|
|
11
|
-
constructor(
|
|
17
|
+
constructor(
|
|
18
|
+
@InjectConnection() private readonly connection: Connection,
|
|
19
|
+
@InjectModel('ApiEvent') private apieventmodel: Model<ApiEvent>,
|
|
20
|
+
){
|
|
12
21
|
|
|
13
22
|
|
|
14
23
|
}
|
|
15
|
-
intercept(context: ExecutionContext, next: CallHandler): Observable<any
|
|
16
|
-
const req = context.switchToHttp().getRequest()
|
|
17
|
-
|
|
24
|
+
async intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<any>> {
|
|
25
|
+
const req = context.switchToHttp().getRequest()
|
|
26
|
+
const resp = context.switchToHttp().getResponse()
|
|
18
27
|
const usersession:UserContext = req['sessionuser']
|
|
28
|
+
const method = req['method']
|
|
29
|
+
const headers = {...req['headers']}
|
|
30
|
+
const ip = req['ip']
|
|
31
|
+
const url = req['url']
|
|
32
|
+
// let { url, method, headers, body }
|
|
19
33
|
const session:ClientSession = usersession.getDBSession()
|
|
20
|
-
|
|
21
|
-
|
|
34
|
+
const logid:string = crypto.randomUUID()
|
|
35
|
+
const starttime =new Date()
|
|
36
|
+
|
|
37
|
+
//authorization no need
|
|
38
|
+
delete headers['authorization']//='--removed--'
|
|
39
|
+
const data:ApiEvent = {
|
|
40
|
+
_id: logid,
|
|
41
|
+
created: starttime.toISOString(),
|
|
42
|
+
duration : 0,
|
|
43
|
+
createdby: usersession.getUid(),
|
|
44
|
+
path: url,
|
|
45
|
+
method: method,
|
|
46
|
+
headers: headers,
|
|
47
|
+
ip:ip,
|
|
48
|
+
// data: req.body,
|
|
49
|
+
statusCode:0,
|
|
50
|
+
status:'D'
|
|
51
|
+
}
|
|
52
|
+
const eventmodel = new this.apieventmodel(data)
|
|
53
|
+
|
|
54
|
+
const eventObj = await eventmodel.save()
|
|
22
55
|
|
|
23
|
-
|
|
56
|
+
req['eventObj']=eventObj
|
|
24
57
|
return next
|
|
25
58
|
.handle()
|
|
26
59
|
.pipe(
|
|
27
|
-
tap(() => {
|
|
60
|
+
tap(async () => {
|
|
61
|
+
|
|
62
|
+
const endtime =new Date()
|
|
63
|
+
eventObj.isNew=false
|
|
64
|
+
eventObj.statusCode=resp['statusCode']
|
|
65
|
+
eventObj.updated = endtime.toISOString()
|
|
66
|
+
eventObj.status="OK"
|
|
67
|
+
eventObj.duration = endtime.getTime() - starttime.getTime()
|
|
68
|
+
const result = await eventObj.save()//({_id:logid},{statusCode:resp['statusCode']})
|
|
69
|
+
// console.log("result===",logid,result)
|
|
28
70
|
|
|
29
71
|
if(process.env.DRYRUN=='true'){
|
|
30
72
|
console.warn("--------dryrun! roll back everything-----------")
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2023-10-28
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
1
7
|
import { Injectable, NestMiddleware, Logger,Scope,Inject } from '@nestjs/common';
|
|
2
8
|
import { Request, Response, NextFunction } from 'express';
|
|
3
9
|
import { InjectModel } from '@nestjs/mongoose';
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2023-10-28
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
1
7
|
import { BPMNClient } from "bpmn-client";
|
|
2
8
|
import { UserContext } from './user.context';
|
|
3
9
|
import { Injectable,Scope } from '@nestjs/common';
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2023-10-28
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
1
7
|
import {Role} from './roles.enum'
|
|
2
8
|
|
|
3
9
|
<% Object.getOwnPropertyNames(it.allroles).forEach((key)=>{ %>
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2023-10-28
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
2
7
|
import { Injectable, Inject, CanActivate, ExecutionContext, Scope } from '@nestjs/common';
|
|
3
8
|
import { Reflector } from '@nestjs/core';
|
|
4
9
|
import { Role } from './roles.enum'
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2023-10-28
|
|
5
|
+
* Author: Ks Tan
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
7
|
import { Injectable, Scope,Inject,Logger, BadRequestException } from '@nestjs/common';
|
|
9
8
|
import { Model, model, connect, PipelineStage } from 'mongoose';
|
|
10
9
|
import _ from 'lodash'
|
|
@@ -39,6 +38,8 @@ export class UserContext {
|
|
|
39
38
|
protected group: string = '';
|
|
40
39
|
protected branchCode: string = '';
|
|
41
40
|
protected branchName: string = '';
|
|
41
|
+
protected orgCode: string = '';
|
|
42
|
+
protected orgName: string = '';
|
|
42
43
|
protected branches: any[] = []
|
|
43
44
|
protected invites: any[] = [] //User + field tenant:Tenant[]
|
|
44
45
|
protected roles: string[] = [];
|
|
@@ -133,7 +134,8 @@ export class UserContext {
|
|
|
133
134
|
orgId:this.orgId,
|
|
134
135
|
branchId:this.branchId,
|
|
135
136
|
}},
|
|
136
|
-
{$lookup:{from: 'branch',localField: 'branchId',foreignField:'branchId',as: 'currentbranch'}}
|
|
137
|
+
{$lookup:{from: 'branch',localField: 'branchId',foreignField:'branchId',as: 'currentbranch'}},
|
|
138
|
+
{$lookup:{from: 'organization',localField: 'orgId',foreignField:'orgId',as: 'currentorg'}}
|
|
137
139
|
]
|
|
138
140
|
}}
|
|
139
141
|
|
|
@@ -160,6 +162,8 @@ export class UserContext {
|
|
|
160
162
|
userinfo.roles = rolegroups[userinfo.group]
|
|
161
163
|
userinfo.branchCode = myperm.currentbranch[0].branchCode
|
|
162
164
|
userinfo.branchName = myperm.currentbranch[0].branchName
|
|
165
|
+
userinfo.orgCode = myperm.currentorg[0].orgCode
|
|
166
|
+
userinfo.orgName = myperm.currentorg[0].orgName
|
|
163
167
|
}
|
|
164
168
|
}else{
|
|
165
169
|
userinfo.group = ''
|
|
@@ -192,6 +196,8 @@ export class UserContext {
|
|
|
192
196
|
this._id = userinfo._id.toString()
|
|
193
197
|
this.branchCode = userinfo['branchCode'] ?? ''
|
|
194
198
|
this.branchName = userinfo['branchName'] ?? ''
|
|
199
|
+
this.orgCode = userinfo['orgCode'] ?? ''
|
|
200
|
+
this.orgName = userinfo['orgName'] ?? ''
|
|
195
201
|
this.group = userinfo['group'] ?? ''
|
|
196
202
|
this.roles = userinfo['roles'] ?? [Role.Everyone,Role.User]
|
|
197
203
|
}else{
|
|
@@ -199,7 +205,7 @@ export class UserContext {
|
|
|
199
205
|
// this.group = ''
|
|
200
206
|
// this.tenantId=0
|
|
201
207
|
// this.orgId=0
|
|
202
|
-
// this.
|
|
208
|
+
// this.orgCode=0
|
|
203
209
|
this.roles = [Role.Everyone,Role.Unknown]
|
|
204
210
|
}
|
|
205
211
|
this.logger.debug(`${this.uid} have _id (${this.getId()}), group (${this.group}) and role (${this.getRoles()})` )
|
|
@@ -289,6 +295,8 @@ export class UserContext {
|
|
|
289
295
|
branchId: this.getBranchId(),
|
|
290
296
|
branchCode: this.branchCode,
|
|
291
297
|
branchName: this.branchName,
|
|
298
|
+
orgCode:this.orgCode,
|
|
299
|
+
orgName:this.orgName,
|
|
292
300
|
email: this.getEmail(),
|
|
293
301
|
uid: this.getUid(),
|
|
294
302
|
fullName: this.getFullname(),
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2023-10-28
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Schema } from 'mongoose';
|
|
9
|
+
import { BranchOrganization, Branch, } from '../types/branch.type';
|
|
10
|
+
const schemasetting = {
|
|
11
|
+
_id: {type:String},
|
|
12
|
+
created: {type: String},
|
|
13
|
+
updated: {type: String},
|
|
14
|
+
duration:{type: Number},
|
|
15
|
+
createdby: {type: String},
|
|
16
|
+
path:{type:String},
|
|
17
|
+
ip:{type:String},
|
|
18
|
+
method:{type:String},
|
|
19
|
+
headers:{type: Object},
|
|
20
|
+
data: {type: Object},
|
|
21
|
+
statusCode: {type: Number},
|
|
22
|
+
status:{type:String},
|
|
23
|
+
errMsg:{type:String},
|
|
24
|
+
errData: {type: Object},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const ApiEventMongoSchema = new Schema(schemasetting,{collection: 'apievent'})
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* This file was automatically generated by simpleapp generator.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* last change 2023-09-09
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2023-10-28
|
|
6
5
|
* Author: Ks Tan
|
|
7
6
|
*/
|
|
8
7
|
|