@simitgroup/simpleapp-generator 1.0.23 → 1.0.25
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 +48 -0
- package/dist/createproject.js +1 -1
- package/dist/createproject.js.map +1 -1
- package/dist/framework.js +37 -25
- package/dist/framework.js.map +1 -1
- package/dist/generate.js +38 -16
- package/dist/generate.js.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/processors/jsonschemabuilder.js +9 -9
- package/dist/processors/jsonschemabuilder.js.map +1 -1
- package/package.json +1 -1
- package/src/framework.ts +50 -36
- package/src/generate.ts +37 -21
- package/src/index.ts +2 -1
- package/src/processors/jsonschemabuilder.ts +9 -9
- package/src/type.ts +1 -0
- package/templates/basic/apischema.eta +8 -4
- package/templates/basic/controller.eta +21 -5
- package/templates/basic/jsonschema.eta +2 -0
- package/templates/basic/model.eta +4 -7
- package/templates/basic/module.eta +2 -0
- package/templates/basic/pageindex.vue.eta +28 -15
- package/templates/basic/pageindexwithid.vue.eta +13 -1
- package/templates/basic/service.eta +11 -9
- package/templates/basic/simpleappclient.eta +9 -8
- package/templates/basic/type.eta +2 -1
- package/templates/nest/SimpleAppController.eta +5 -5
- package/templates/nest/SimpleAppService.eta +87 -31
- package/templates/nest/TenantMiddleware.eta +39 -0
- package/templates/nest/User.eta +115 -0
- package/templates/nest/app.module.eta +24 -4
- package/templates/nest/inputvalidation-exception.eta +6 -0
- package/templates/nest/nest.env.eta +12 -1
- package/templates/nest/nest.main.eta +14 -3
- package/templates/nest/oauth2-redirect.eta +79 -0
- package/templates/nuxt/components.crudsimple.vue.eta +60 -48
- package/templates/nuxt/components.debugdocdata.vue.eta +12 -4
- package/templates/nuxt/components.eventmonitor.vue.eta +17 -11
- package/templates/nuxt/components.menus.vue.eta +14 -12
- package/templates/nuxt/composables.getautocomplete.ts.eta +19 -8
- package/templates/nuxt/composables.getmenus.ts.eta +27 -9
- package/templates/nuxt/env.eta +12 -0
- package/templates/nuxt/layouts.default.vue.eta +10 -3
- package/templates/nuxt/nuxt.config.ts.eta +10 -6
- package/templates/nuxt/pages.[xorg].index.vue.eta +19 -0
- package/templates/nuxt/pages.index.vue.eta +17 -1
- package/templates/nuxt/pages.login.vue.eta +20 -0
- package/templates/nuxt/plugins.simpleapp.ts.eta +12 -4
- package/templates/nuxt/server.api.auth.logout.ts.eta +12 -0
- package/templates/nuxt/server.api.auth[...].ts.eta +144 -0
- package/templates/nuxt/server.api.ts.eta +33 -19
- package/src/createproject.ts +0 -121
- package/src/index2.ts-old +0 -132
- package/src/installdependency.sh +0 -5
- package/src/installnest.ts +0 -0
- package/src/installnuxt.ts +0 -0
- package/templates/basic/backend.config.eta +0 -1
- package/templates/basic/beforesave.eta +0 -7
- package/templates/basic/controller2.eta +0 -86
- package/templates/basic/frontend.config.eta +0 -1
- package/templates/basic/model-converter.etabackup +0 -21
- package/templates/basic/readme.eta +0 -3
- package/templates/basic/service.etabackupe +0 -106
- package/templates/basic/type.etabackup +0 -23
- package/templates/basic/uischema.eta +0 -13
|
@@ -1,29 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator during initialization.
|
|
3
|
+
* DO NOT MODIFY IT BY HAND.
|
|
4
|
+
* last change 2023-09-09
|
|
5
|
+
* author: Ks Tan
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
|
|
1
9
|
import axios from 'axios';
|
|
2
|
-
|
|
3
|
-
|
|
10
|
+
import { getServerSession } from '#auth'
|
|
11
|
+
import type { Session } from 'next-auth';
|
|
4
12
|
|
|
5
13
|
export default defineEventHandler(async (event) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
type additionalprops = {accessToken?:string}
|
|
15
|
+
let session:any=null
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
session = await getServerSession(event)
|
|
20
|
+
|
|
21
|
+
} catch (error) {
|
|
22
|
+
return sendRedirect(event, '/login', 401)
|
|
23
|
+
}
|
|
12
24
|
|
|
13
25
|
return new Promise<any>(async (resolve, reject) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
26
|
+
if(!session) {
|
|
27
|
+
//if(!session || !session.accessToken) {
|
|
28
|
+
reject({ statusMessage: 'Unauthorized', statusCode: 401 });
|
|
29
|
+
throw createError({ statusMessage: 'Unauthorized', statusCode: 401 })
|
|
30
|
+
}
|
|
18
31
|
// console.log("------hihi------")
|
|
19
32
|
const seperateSymbol = '.';
|
|
20
33
|
// const seperateSymbol = '&';
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
34
|
+
const xOrg = event.context.params?.xorg ?? ''
|
|
35
|
+
const documentLink = event.context.params?._ ?? ''
|
|
36
|
+
// const platform = event.context.params?.platform ?? ''
|
|
37
|
+
|
|
24
38
|
|
|
25
39
|
// console.error("event.context???",event.context)
|
|
26
|
-
|
|
40
|
+
const accessToken = session?.accessToken;
|
|
27
41
|
|
|
28
42
|
// const allowPlatform = ['report-api', 'cloudapi'];
|
|
29
43
|
// if(!key || !platform || !allowPlatform.includes(platform) || !accessToken) {
|
|
@@ -60,14 +74,14 @@ export default defineEventHandler(async (event) => {
|
|
|
60
74
|
// }
|
|
61
75
|
|
|
62
76
|
const frontEndRes = event.node.res;
|
|
63
|
-
const url = process.env.SIMPLEAPP_BACKEND_URL +
|
|
77
|
+
const url = process.env.SIMPLEAPP_BACKEND_URL + '/' + documentLink;
|
|
64
78
|
// console.warn('backend server-----',req.method,url,forwardData)
|
|
65
79
|
const axiosConfig: any = {
|
|
66
80
|
method: req.method,
|
|
67
81
|
url: url,
|
|
68
82
|
headers: {
|
|
69
|
-
|
|
70
|
-
|
|
83
|
+
Authorization: `Bearer ${accessToken}`,
|
|
84
|
+
'X-Org': xOrg,
|
|
71
85
|
},
|
|
72
86
|
data: forwardData,
|
|
73
87
|
params: forwardData,
|
package/src/createproject.ts
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { exec ,spawn} from "child_process";
|
|
2
|
-
import {mkdirSync, writeFileSync} from 'fs'
|
|
3
|
-
import * as constants from './constant'
|
|
4
|
-
import { Logger, ILogObj } from "tslog";
|
|
5
|
-
const log: Logger<ILogObj> = new Logger();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const { Eta } = require('eta');
|
|
9
|
-
|
|
10
|
-
const checkNodeJS= (callback)=>{
|
|
11
|
-
return exec(`npx -v`,(error, stdout, stderr)=>{
|
|
12
|
-
if(error){
|
|
13
|
-
throw ("Nodejs not exists")
|
|
14
|
-
}else{
|
|
15
|
-
callback()
|
|
16
|
-
}
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const checkNestCli = (callback)=>{
|
|
21
|
-
log.info("setting up nest backend")
|
|
22
|
-
return exec(`npx -v`, (error, stdout, stderr)=>{
|
|
23
|
-
if(error){
|
|
24
|
-
return exec(`npm i -g @nestjs/cli`, (error, stdout, stderr)=>{
|
|
25
|
-
callback()
|
|
26
|
-
})
|
|
27
|
-
}else{
|
|
28
|
-
callback()
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const installDependency = async () =>{
|
|
34
|
-
log.info("installDependency 'npm install -g pnpm @nestjs/cli @openapitools/openapi-generator-cli nuxi'")
|
|
35
|
-
return await exec("npm install -g pnpm @nestjs/cli @openapitools/openapi-generator-cli nuxi")
|
|
36
|
-
}
|
|
37
|
-
export const createNuxt= (targetfolder:string,callback)=>{
|
|
38
|
-
log.info("setting up nuxt frontend ${targetfolder}")
|
|
39
|
-
|
|
40
|
-
log.info(`frontend nuxt project "${targetfolder}" created, installing module`)
|
|
41
|
-
exec(`cd ${targetfolder};pnpm install;pnpm install -D @types/node @vueuse/nuxt @sidebase/nuxt-auth @vueuse/core nuxt-security prettier @nuxtjs/tailwindcss`, (error, stdout, stderr)=>{
|
|
42
|
-
//;pnpm install
|
|
43
|
-
console.log(error, stdout, stderr)
|
|
44
|
-
exec(`cd ${targetfolder};pnpm install --save ajv dotenv @fullcalendar/core @fullcalendar/vue3 quill uuid ajv-formats primeflex primeicons prettier primevue axios json-schema mitt @simitgroup/simpleapp-vue-component@latest`, (error, stdout, stderr)=>{
|
|
45
|
-
console.log(error, stdout, stderr)
|
|
46
|
-
|
|
47
|
-
mkdirSync(`${targetfolder}/assets/css/`,{recursive:true})
|
|
48
|
-
mkdirSync(`${targetfolder}/layouts`,{recursive:true})
|
|
49
|
-
mkdirSync(`${targetfolder}/components`,{recursive:true})
|
|
50
|
-
mkdirSync(`${targetfolder}/server/api`,{recursive:true})
|
|
51
|
-
mkdirSync(`${targetfolder}/pages`,{recursive:true})
|
|
52
|
-
mkdirSync(`${targetfolder}/plugins`,{recursive:true})
|
|
53
|
-
const eta = new Eta({views: `${constants.templatedir}/nuxt`});
|
|
54
|
-
const variables=[]
|
|
55
|
-
const writes = {
|
|
56
|
-
'./app.vue.eta':'app.vue',
|
|
57
|
-
'./components.eventmonitor.vue.eta':'components/EventMonitor.vue',
|
|
58
|
-
'./components.menus.vue.eta':'components/Menus.vue',
|
|
59
|
-
'./components.crudsimple.vue.eta':'components/CrudSimple.vue',
|
|
60
|
-
'./components.debugdocdata.vue.eta':'components/DebugDocumentData.vue',
|
|
61
|
-
'./layouts.default.vue.eta':'layouts/default.vue',
|
|
62
|
-
'./server.api.ts.eta':'server/api/[...].ts',
|
|
63
|
-
'./nuxt.config.ts.eta':'nuxt.config.ts',
|
|
64
|
-
'./pages.index.vue.eta':'pages/index.vue',
|
|
65
|
-
'./plugins.simpleapp.ts.eta':'plugins/simpleapp.ts',
|
|
66
|
-
'./tailwind.config.ts.eta':'tailwind.config.ts',
|
|
67
|
-
'./tailwind.css.eta':'assets/css/tailwind.css',
|
|
68
|
-
'./env.eta':'.env',
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const templates = Object.getOwnPropertyNames(writes)
|
|
72
|
-
for(let i=0; i<templates.length;i++){
|
|
73
|
-
const template = templates[i]
|
|
74
|
-
const filename = writes[template]
|
|
75
|
-
const txt = eta.render(template, variables);
|
|
76
|
-
const file =`${targetfolder}/${filename}`
|
|
77
|
-
log.info("writing ",file)
|
|
78
|
-
writeFileSync(file, txt);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
log.info("nuxt project completed")
|
|
82
|
-
callback()
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export const createNest= (targetfolder:string,callback)=>{
|
|
90
|
-
// checkNestCli(()=>{
|
|
91
|
-
|
|
92
|
-
log.info(`creating backend project ${targetfolder}`)
|
|
93
|
-
exec(`cd ${targetfolder};pnpm install --save @nestjs/swagger @nestjs/mongoose mongoose ajv ajv-formats @nestjs/config`,async (error, stdout, stderr)=>{
|
|
94
|
-
// log.info(`dependency installed`)
|
|
95
|
-
if(!error){
|
|
96
|
-
exec(`pnpm install ajv ajv-formats axios json-schema`, (error, stdout, stderr)=>{
|
|
97
|
-
const eta = new Eta({views: constants.templatedir});
|
|
98
|
-
const variables=[]
|
|
99
|
-
const txtEnv = eta.render('./nest.env.eta', variables);
|
|
100
|
-
const txtMain = eta.render('./nest.main.eta', variables);
|
|
101
|
-
|
|
102
|
-
writeFileSync(`${targetfolder}/.env`, txtEnv);
|
|
103
|
-
writeFileSync(`${targetfolder}/src/main.ts`, txtMain);
|
|
104
|
-
const tsconfigpath = process.cwd()+'/'+`${targetfolder}/tsconfig.json`
|
|
105
|
-
const tsconfig = require(tsconfigpath)
|
|
106
|
-
tsconfig.compilerOptions.esModuleInterop=true
|
|
107
|
-
tsconfig.compilerOptions.resolveJsonModule=true
|
|
108
|
-
writeFileSync(tsconfigpath, JSON.stringify(tsconfig));
|
|
109
|
-
|
|
110
|
-
log.info("nest project completed")
|
|
111
|
-
callback()
|
|
112
|
-
})
|
|
113
|
-
} else{
|
|
114
|
-
log.error(stderr)
|
|
115
|
-
throw error
|
|
116
|
-
}
|
|
117
|
-
})
|
|
118
|
-
//
|
|
119
|
-
// })
|
|
120
|
-
|
|
121
|
-
}
|
package/src/index2.ts-old
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { error } from "console"
|
|
4
|
-
|
|
5
|
-
const program = require("commander") // add this line
|
|
6
|
-
const Fieldtypes= require( './type')
|
|
7
|
-
const generator= require( './generate')
|
|
8
|
-
const fs = require( 'fs')
|
|
9
|
-
const createproject =require( './createproject')
|
|
10
|
-
const {exec} = require( "child_process")
|
|
11
|
-
|
|
12
|
-
const capitalizeFirstLetter= require( './libs')
|
|
13
|
-
const {Logger, ILogObj} = require( "tslog");
|
|
14
|
-
|
|
15
|
-
const log :typeof Logger= new Logger();
|
|
16
|
-
|
|
17
|
-
const figlet = require("figlet");
|
|
18
|
-
// const program = new Command();
|
|
19
|
-
const pj = require('../package.json')
|
|
20
|
-
|
|
21
|
-
let version=pj.version
|
|
22
|
-
program
|
|
23
|
-
.version(version)
|
|
24
|
-
.description("An simpleapp CLI tool for generate frontend (vuejs) and backend(nestjs) codes")
|
|
25
|
-
.option("-c, --config-file <value>", 'configuration file content such as:{"definationsFolder":"./definations", "backendFolder":"./nestproject/src/docs", "frontendFolder":"./nuxt/server"}')
|
|
26
|
-
// .option("-s, --definations-folder <value>", "load defination files from which folder")
|
|
27
|
-
// .option("-b, --backend-folder <value>", "Create backend code at which folder")
|
|
28
|
-
// .option("-f, --frontend-folder <value>", "Create frontend code at which folder")
|
|
29
|
-
// .option("-i, --openapi3-yaml <value>", 'openapi3.yaml generated by backend server')
|
|
30
|
-
.parse(process.argv);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const options = program.opts();
|
|
34
|
-
console.log(figlet.textSync(`SimpleApp Generator ${version}`));
|
|
35
|
-
// console.log(options)
|
|
36
|
-
let path=''
|
|
37
|
-
if(!options.configFile){
|
|
38
|
-
log.error("Config file parameter is required. Example: simpleapp-generator -c ./config.json")
|
|
39
|
-
throw "Undefine configuration file"
|
|
40
|
-
}
|
|
41
|
-
else if(options.configFile && options.configFile[0]=='/'){
|
|
42
|
-
path=options.configFile
|
|
43
|
-
}
|
|
44
|
-
else if(options.configFile){
|
|
45
|
-
path=process.cwd()+'/'+options.configFile
|
|
46
|
-
}else{
|
|
47
|
-
log.error("undefine configuration file, use command simpleapp-generator -c <configfilename.json>")
|
|
48
|
-
throw error
|
|
49
|
-
}
|
|
50
|
-
const configs = require(path)
|
|
51
|
-
console.log("configurations: ",configs)
|
|
52
|
-
const definationsFolder = configs.definationsFolder ?? options.definationsFolder
|
|
53
|
-
const backendFolder = configs.backendFolder ?? options.backendFolder
|
|
54
|
-
const frontendFolder = configs.frontendFolder ?? options.frontendFolder
|
|
55
|
-
const openapi3Yaml:string = configs.openapi3Yaml ?? options.openapi3Yaml
|
|
56
|
-
|
|
57
|
-
const runGenNext = async (callback)=>{
|
|
58
|
-
let isnestready=false
|
|
59
|
-
if(!fs.existsSync(backendFolder)){
|
|
60
|
-
console.log("Nest does not exists, begin install nodejs environment tools: [pnpm, @nestjs/cli, @openapitools/openapi-generator-cli, nuxi]")
|
|
61
|
-
isnestready = await exec("npm install -g pnpm @nestjs/cli @openapitools/openapi-generator-cli nuxi",async (a,b,c)=>{
|
|
62
|
-
console.log("result of environment tools:",a,b,c)
|
|
63
|
-
console.log(`Install new nest backend: 'nest new -p pnpm ${backendFolder}'`)
|
|
64
|
-
return await exec(`nest new -p pnpm ${backendFolder}`,(a,b,c)=>{
|
|
65
|
-
console.log("new nest result",a,b,c)
|
|
66
|
-
return true
|
|
67
|
-
})
|
|
68
|
-
})
|
|
69
|
-
}else{
|
|
70
|
-
isnestready=true
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if(isnestready){
|
|
76
|
-
if(!fs.existsSync(`${backendFolder}/.env`)){
|
|
77
|
-
log.info(`initial nest configuratoin for simpleapp generator`)
|
|
78
|
-
await createNest(backendFolder,callback)
|
|
79
|
-
}else{
|
|
80
|
-
log.warn(`.env file exists, skip nest initialization`)
|
|
81
|
-
callback()
|
|
82
|
-
}
|
|
83
|
-
}else{
|
|
84
|
-
log.error('nest not ready, which shouldnot continue')
|
|
85
|
-
throw error
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
const runGenNuxt = async (callback)=>{
|
|
91
|
-
|
|
92
|
-
if(!fs.existsSync(frontendFolder)){
|
|
93
|
-
log.error(`${frontendFolder} does not exists, please run "npx nuxi@latest init ${frontendFolder}"`)
|
|
94
|
-
}else if(!fs.existsSync(`${frontendFolder}/.env`)){
|
|
95
|
-
log.info(`initial nuxt configuratoin for simpleapp generator`)
|
|
96
|
-
createNuxt(frontendFolder,callback)
|
|
97
|
-
}else{
|
|
98
|
-
log.warn(`.env file exists, skip nuxt initialization`)
|
|
99
|
-
callback()
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const generateCode = async () =>{
|
|
105
|
-
|
|
106
|
-
await runGenNext(async ()=>{
|
|
107
|
-
log.info("runGenNext (backen) done")
|
|
108
|
-
await runGenNuxt( async ()=>{
|
|
109
|
-
log.info("runGenNuxt (frontend) done")
|
|
110
|
-
generator.initialize(definationsFolder,backendFolder,frontendFolder)
|
|
111
|
-
exec(`cd ${frontendFolder};npx prettier --write "./pages/**/*.vue" "./simpleapp/**/*" `)
|
|
112
|
-
exec(`cd ${backendFolder};npx run format `)
|
|
113
|
-
if(openapi3Yaml !=''){
|
|
114
|
-
|
|
115
|
-
exec(`openapi-generator-cli generate -i ${openapi3Yaml} -o ${frontendFolder}/simpleapp/openapi -g typescript-axios --skip-validate-spec`,(error, stdout, stderr)=>{
|
|
116
|
-
if(error){
|
|
117
|
-
log.error(stderr);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
})
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
log.info("generate code: ")
|
|
127
|
-
generateCode()
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
// pnpm exec prettier ./src/docs --write
|
|
132
|
-
// pnpm exec prettier ./apiclients --write
|
package/src/installdependency.sh
DELETED
package/src/installnest.ts
DELETED
|
File without changes
|
package/src/installnuxt.ts
DELETED
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const API_BASE_URL = 'http://localhost:3000';
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file was automatically generated by simpleapp generator.
|
|
3
|
-
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
4
|
-
* and regenerate this file.
|
|
5
|
-
*/
|
|
6
|
-
import { <%= it.typename %> } from './<%= it.doctype %>.type';
|
|
7
|
-
export const beforeSave = (doc: <%= it.typename %>) => {}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file was automatically generated by simpleapp generator.
|
|
3
|
-
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
4
|
-
* and regenerate this file.
|
|
5
|
-
*/
|
|
6
|
-
import {
|
|
7
|
-
Controller,
|
|
8
|
-
Get,
|
|
9
|
-
Put,
|
|
10
|
-
Post,
|
|
11
|
-
Delete,
|
|
12
|
-
Body,
|
|
13
|
-
Param,
|
|
14
|
-
Type,
|
|
15
|
-
} from '@nestjs/common';
|
|
16
|
-
import { <%= it.doctype %>Service } from './<%= it.doctype %>.service';
|
|
17
|
-
import * as <%= it.doctype %>type from './<%= it.doctype %>.type';
|
|
18
|
-
import * as <%= it.doctype %>apischema from './<%= it.doctype %>.apischema';
|
|
19
|
-
import { ApiTags, ApiBody, ApiResponse,ApiOperation } from '@nestjs/swagger';
|
|
20
|
-
|
|
21
|
-
const doctype = '<%= it.doctype %>'.toUpperCase();
|
|
22
|
-
@ApiTags(doctype)
|
|
23
|
-
@Controller(doctype.toLowerCase())
|
|
24
|
-
export class <%= it.doctype %>Controller {
|
|
25
|
-
constructor(private readonly service: <%= it.doctype %>Service) {}
|
|
26
|
-
|
|
27
|
-
/********************ok*****************/
|
|
28
|
-
@Get()
|
|
29
|
-
@ApiResponse({
|
|
30
|
-
status: 200,
|
|
31
|
-
description: 'Found',
|
|
32
|
-
})
|
|
33
|
-
@ApiResponse({ status: 500, description: 'Internal error' })
|
|
34
|
-
@ApiOperation({ operationId: 'runList' })
|
|
35
|
-
async list() {
|
|
36
|
-
return this.service.list();
|
|
37
|
-
}
|
|
38
|
-
/********************ok*****************/
|
|
39
|
-
@Get(':id')
|
|
40
|
-
@ApiResponse({ status: 200, description: 'Founds', type: <%= it.fullApiSchemaName %> })
|
|
41
|
-
@ApiResponse({ status: 404, description: 'Document not found' })
|
|
42
|
-
@ApiResponse({ status: 500, description: 'Internal error' })
|
|
43
|
-
@ApiOperation({ operationId: 'runFindOne' })
|
|
44
|
-
async findOne(@Param('id') id: string) {
|
|
45
|
-
const result = await this.service.findById(id)
|
|
46
|
-
return result as <%= it.fullApiSchemaName %>;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/********************ok*****************/
|
|
50
|
-
@Post()
|
|
51
|
-
@ApiResponse({ status: 201, description: 'success', type: <%= it.fullApiSchemaName %> })
|
|
52
|
-
@ApiResponse({ status: 400, description: 'bad request' })
|
|
53
|
-
@ApiResponse({ status: 500, description: 'internal error' })
|
|
54
|
-
@ApiBody({ description: 'Data', type: <%= it.fullApiSchemaName %> })
|
|
55
|
-
@ApiOperation({ operationId: 'runCreate' })
|
|
56
|
-
async create(@Body() data: <%= it.fullApiSchemaName %>) {
|
|
57
|
-
//const newdata: <%= it.fullTypeName %> = { ...data };
|
|
58
|
-
const newdata: persontype.Person = {} as persontype.Person; //= { ...data };
|
|
59
|
-
Object.assign(newdata, data); //
|
|
60
|
-
return this.service.setData(newdata).create();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/********************ok*****************/
|
|
64
|
-
@Put(':id')
|
|
65
|
-
@ApiResponse({ status: 200, description: 'success', type: <%= it.fullApiSchemaName %> })
|
|
66
|
-
@ApiResponse({ status: 404, description: 'Document not found' })
|
|
67
|
-
@ApiResponse({ status: 500, description: 'Internal error' })
|
|
68
|
-
@ApiBody({ description: 'Data', type: <%= it.fullApiSchemaName %> })
|
|
69
|
-
@ApiOperation({ operationId: 'runUpdate' })
|
|
70
|
-
async update(@Param('id') id: string, @Body() data: <%= it.fullApiSchemaName %>) {
|
|
71
|
-
//const newdata: <%= it.fullTypeName %> = { ...data };
|
|
72
|
-
const newdata: persontype.Person = {} as persontype.Person; //= { ...data };
|
|
73
|
-
Object.assign(newdata, data); //
|
|
74
|
-
return this.service.findIdThenUpdate(id, newdata);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/********************ok*****************/
|
|
78
|
-
@Delete(':id')
|
|
79
|
-
@ApiResponse({ status: 200, description: 'success', type: <%= it.fullApiSchemaName %> })
|
|
80
|
-
@ApiResponse({ status: 404, description: 'Document not found' })
|
|
81
|
-
@ApiResponse({ status: 500, description: 'Internal error' })
|
|
82
|
-
@ApiOperation({ operationId: 'runDelete' })
|
|
83
|
-
async delete(@Param('id') id: string) {
|
|
84
|
-
return this.service.findIdThenDelete(id);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const API_BASE_URL = useRuntimeConfig().public.API_BASE_URL
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file was automatically generated by simpleapp generator.
|
|
3
|
-
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
4
|
-
* and regenerate this file.
|
|
5
|
-
*/
|
|
6
|
-
<% const schema = it.schema %>
|
|
7
|
-
<% const typeclass = it.doctype+'type' %>
|
|
8
|
-
import { Schema } from 'mongoose';
|
|
9
|
-
import { beforeSave } from './<%= it.doctype %>.beforesave';
|
|
10
|
-
import {<%= it.typename%>JsonSchema } from './<%= it.doctype %>.jsonschema'
|
|
11
|
-
import { createMongooseSchema } from 'convert-json-schema-to-mongoose';
|
|
12
|
-
import { <%= it.typename%> } from './<%= it.doctype %>.type';
|
|
13
|
-
|
|
14
|
-
// import { <%Object.keys(it.models).forEach(function(key) { %> <%=key %>, <%})%> } from './<%= it.doctype %>.type';
|
|
15
|
-
const schema1 = <%= it.typename%>JsonSchema
|
|
16
|
-
|
|
17
|
-
const schemasetting = createMongooseSchema(schema1,schema1)
|
|
18
|
-
|
|
19
|
-
export const <%= it.doctype %>MongoSchema = new Schema(schemasetting)
|
|
20
|
-
.post('validate', (doc: <%= it.typename %>) => beforeSave(doc))
|
|
21
|
-
.pre('save', () => {});
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import { InjectModel } from '@nestjs/mongoose';
|
|
3
|
-
import { Model } from 'mongoose';
|
|
4
|
-
import Ajv from 'ajv';
|
|
5
|
-
import addFormats from 'ajv-formats';
|
|
6
|
-
import addKeyword from "ajv-keywords";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import * as <%= it.doctype %>type from './<%= it.doctype %>.type';
|
|
10
|
-
import * as <%= it.doctype %>apischema from './<%= it.doctype %>.apischema';
|
|
11
|
-
|
|
12
|
-
//import { <%= it.typename %> } from './<%= it.doctype %>.type';
|
|
13
|
-
//import { <%= it.apiSchemaName %> } from './<%= it.doctype %>.apischema';
|
|
14
|
-
import {
|
|
15
|
-
NotFoundException,
|
|
16
|
-
InternalServerErrorException,
|
|
17
|
-
} from '@nestjs/common/exceptions';
|
|
18
|
-
@Injectable()
|
|
19
|
-
export class <%= it.doctype %>Service {
|
|
20
|
-
private jsonschema = <%~ JSON.stringify(it.jsonschema) %>;
|
|
21
|
-
|
|
22
|
-
constructor(
|
|
23
|
-
@InjectModel('<%= it.name %>') private readonly doc: Model<<%= it.fullTypeName %>>,
|
|
24
|
-
) {}
|
|
25
|
-
|
|
26
|
-
getSchema() {
|
|
27
|
-
return this.doc.schema.obj;
|
|
28
|
-
}
|
|
29
|
-
async list() {
|
|
30
|
-
try {
|
|
31
|
-
const products = await this.doc.find();
|
|
32
|
-
const productlist = products.map((p: <%= it.fullTypeName %>) => {
|
|
33
|
-
return p;
|
|
34
|
-
});
|
|
35
|
-
// console.log(products);
|
|
36
|
-
return productlist;
|
|
37
|
-
} catch (err) {
|
|
38
|
-
throw new InternalServerErrorException(err.message);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
async findById(id: string) {
|
|
42
|
-
let data;
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
data = await this.doc.findById(id);
|
|
46
|
-
} catch (err) {
|
|
47
|
-
//error
|
|
48
|
-
throw new InternalServerErrorException(err.message);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (!data) {
|
|
52
|
-
//data not found
|
|
53
|
-
throw new NotFoundException('Document Not found:');
|
|
54
|
-
}
|
|
55
|
-
return data;
|
|
56
|
-
}
|
|
57
|
-
async create(data: <%= it.fullTypeName %>) {
|
|
58
|
-
let result;
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
delete data._id;
|
|
62
|
-
this.validateData(data);
|
|
63
|
-
const newdoc = new this.doc(data);
|
|
64
|
-
result = await newdoc.save();
|
|
65
|
-
} catch (err) {
|
|
66
|
-
throw new InternalServerErrorException(err.message);
|
|
67
|
-
}
|
|
68
|
-
return result as <%= it.fullTypeName %>;
|
|
69
|
-
}
|
|
70
|
-
async update(id: string, data: <%= it.fullTypeName %>) {
|
|
71
|
-
const existingdata = await this.findById(id);
|
|
72
|
-
try {
|
|
73
|
-
this.validateData(data);
|
|
74
|
-
const result = await existingdata.updateOne(data);
|
|
75
|
-
return result;
|
|
76
|
-
} catch (err) {
|
|
77
|
-
throw new InternalServerErrorException(err.message);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
async delete(id: string) {
|
|
81
|
-
const data = await this.findById(id);
|
|
82
|
-
try {
|
|
83
|
-
const deleteresult = await this.doc.findByIdAndDelete(id);
|
|
84
|
-
return deleteresult;
|
|
85
|
-
} catch (err) {
|
|
86
|
-
throw new InternalServerErrorException(err.message);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
validateData(data: <%=it.doctype %>type.<%= it.typename %>) {
|
|
91
|
-
const ajv = new Ajv({ allErrors: true });
|
|
92
|
-
addFormats(ajv);
|
|
93
|
-
ajv.addKeyword('example');
|
|
94
|
-
|
|
95
|
-
const validate = ajv.compile(this.jsonschema);
|
|
96
|
-
const valid = validate(data);
|
|
97
|
-
if (!valid) {
|
|
98
|
-
console.log(validate.errors);
|
|
99
|
-
const erromsg: string[] = [];
|
|
100
|
-
for (let i = 0; i < validate.errors.length; i++) {
|
|
101
|
-
erromsg.push(validate.errors[i].message);
|
|
102
|
-
}
|
|
103
|
-
throw new InternalServerErrorException(erromsg.join('\n'));
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
<%Object.keys(it.models).forEach(function(prop){ %>
|
|
2
|
-
<% let schema = it.models[prop] %>
|
|
3
|
-
export type <%= prop %> = {
|
|
4
|
-
<% if(it.apiSchemaName == prop ) {%>
|
|
5
|
-
_id?: string;
|
|
6
|
-
doctype?: string;
|
|
7
|
-
<% } %>
|
|
8
|
-
<%Object.keys(schema.model).forEach(function(key){ %>
|
|
9
|
-
<% const obj = schema.model[key] %>
|
|
10
|
-
<% if(typeof obj == 'string') {%>
|
|
11
|
-
<%= key %>?: <%= obj %>; //child object
|
|
12
|
-
<% }else if( Array.isArray( obj)){%>
|
|
13
|
-
<%= key %>?: <%= obj[0] %>[]; //array
|
|
14
|
-
<% }else if( obj.type == 'array'){%>
|
|
15
|
-
<%= key %>?: <%= obj.items.type %>[]; //array
|
|
16
|
-
<% }else{%>
|
|
17
|
-
<%= key %> <% if(!obj.required || obj.required==false){%>?<%}%>: <%= obj.type %>; // <%~ JSON.stringify(obj) %>
|
|
18
|
-
<% } %>
|
|
19
|
-
<%})%>
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
<%})%>
|
|
23
|
-
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export <%= it.typename %>UiSchema <%= it.typename %> = {
|
|
2
|
-
id: {type: "string",format:"text",title:"ID"},
|
|
3
|
-
doctype: {type: "string",format:"text",title:"ID"},
|
|
4
|
-
<%Object.keys(it.schema).forEach(function(prop) { %>
|
|
5
|
-
<%=prop %>: {
|
|
6
|
-
<% Object.keys(it.schema[prop]).forEach(function(fkey){ %>
|
|
7
|
-
<%=fkey %>: {type: "<%= it.schema[prop][fkey].datatype %>;",format:"<%= it.schema[prop][fkey].type %>;",title:"<%= it.schema[prop][fkey].title %>;"},
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
<% }) %>
|
|
11
|
-
};
|
|
12
|
-
<%}) %>
|
|
13
|
-
};
|