@simitgroup/simpleapp-generator 1.0.19 → 1.0.21
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 +13 -10
- package/backend1/.env +5 -0
- package/backend1/.eslintrc.js +25 -0
- package/backend1/.prettierrc +4 -0
- package/backend1/README.md +73 -0
- package/backend1/nest-cli.json +8 -0
- package/backend1/package.json +75 -0
- package/backend1/pnpm-lock.yaml +5459 -0
- package/backend1/src/app.controller.js +71 -0
- package/backend1/src/app.controller.js.map +1 -0
- package/backend1/src/app.controller.spec.js +21 -0
- package/backend1/src/app.controller.spec.js.map +1 -0
- package/backend1/src/app.controller.spec.ts +22 -0
- package/backend1/src/app.controller.ts +12 -0
- package/backend1/src/app.module.js +67 -0
- package/backend1/src/app.module.js.map +1 -0
- package/backend1/src/app.module.ts +10 -0
- package/backend1/src/app.service.js +64 -0
- package/backend1/src/app.service.js.map +1 -0
- package/backend1/src/app.service.ts +8 -0
- package/backend1/src/class/SimpleAppController.js +38 -0
- package/backend1/src/class/SimpleAppController.js.map +1 -0
- package/backend1/src/class/SimpleAppController.ts +69 -0
- package/backend1/src/class/SimpleAppService.js +264 -0
- package/backend1/src/class/SimpleAppService.js.map +1 -0
- package/backend1/src/class/SimpleAppService.ts +213 -0
- package/backend1/src/main.js +22 -0
- package/backend1/src/main.js.map +1 -0
- package/backend1/src/main.ts +20 -0
- package/backend1/test/app.e2e-spec.js +45 -0
- package/backend1/test/app.e2e-spec.js.map +1 -0
- package/backend1/test/app.e2e-spec.ts +24 -0
- package/backend1/test/jest-e2e.json +9 -0
- package/backend1/tsconfig.build.json +4 -0
- package/backend1/tsconfig.json +1 -0
- package/dist/createproject.js +6 -1
- package/dist/createproject.js.map +1 -1
- package/dist/framework.js +161 -0
- package/dist/framework.js.map +1 -0
- package/dist/generate.js +2 -2
- package/dist/generate.js.map +1 -1
- package/dist/index.js +54 -58
- package/dist/index.js.map +1 -1
- package/dist/index2.js +118 -0
- package/dist/index2.js.map +1 -0
- package/dist/installdependency.js +20 -0
- package/dist/installdependency.js.map +1 -0
- package/dist/installnest.js +2 -0
- package/dist/installnest.js.map +1 -0
- package/dist/installnuxt.js +2 -0
- package/dist/installnuxt.js.map +1 -0
- package/dist/validation.js +2 -0
- package/dist/validation.js.map +1 -0
- package/frontend1/README.md +63 -0
- package/frontend1/app.vue +8 -0
- package/frontend1/assets/css/tailwind.css +28 -0
- package/frontend1/components/CrudSimple.vue +112 -0
- package/frontend1/components/DebugDocumentData.vue +20 -0
- package/frontend1/components/EventMonitor.vue +79 -0
- package/frontend1/components/Menus.vue +18 -0
- package/frontend1/layouts/default.vue +10 -0
- package/frontend1/nuxt.config.js +42 -0
- package/frontend1/nuxt.config.js.map +1 -0
- package/frontend1/nuxt.config.ts +42 -0
- package/frontend1/package-lock.json +11877 -0
- package/frontend1/package.json +38 -0
- package/frontend1/pages/index.vue +3 -0
- package/frontend1/plugins/simpleapp.js +73 -0
- package/frontend1/plugins/simpleapp.js.map +1 -0
- package/frontend1/plugins/simpleapp.ts +73 -0
- package/frontend1/pnpm-lock.yaml +8339 -0
- package/frontend1/public/favicon.ico +0 -0
- package/frontend1/server/api/[...].js +117 -0
- package/frontend1/server/api/[...].js.map +1 -0
- package/frontend1/server/api/[...].ts +131 -0
- package/frontend1/server/tsconfig.json +3 -0
- package/frontend1/tailwind.config.js +10 -0
- package/frontend1/tailwind.config.js.map +1 -0
- package/frontend1/tailwind.config.ts +9 -0
- package/frontend1/tsconfig.json +4 -0
- package/openapitools.json +0 -0
- package/package.json +2 -6
- package/sampleconfig.json +2 -2
- package/src/createproject.ts +5 -0
- package/src/framework.ts +133 -0
- package/src/generate.ts +2 -2
- package/src/index.ts +38 -69
- package/src/index2.ts +132 -0
- package/src/installdependency.sh +5 -0
- package/src/installdependency.ts +4 -0
- package/src/installnest.ts +0 -0
- package/src/installnuxt.ts +0 -0
- package/src/validation.ts +0 -0
- package/templates/basic/pageindex.vue.eta +9 -9
- package/templates/nuxt/plugins.simpleapp.ts.eta +3 -3
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
36
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
37
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
38
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
39
|
+
};
|
|
40
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.SimpleAppService = void 0;
|
|
45
|
+
const common_1 = require("@nestjs/common");
|
|
46
|
+
const ajv_1 = __importDefault(require("ajv"));
|
|
47
|
+
const ajv_formats_1 = __importDefault(require("ajv-formats"));
|
|
48
|
+
const foreignkeys_json_1 = __importDefault(require("../dicts/foreignkeys.json"));
|
|
49
|
+
const exceptions_1 = require("@nestjs/common/exceptions");
|
|
50
|
+
let SimpleAppService = (() => {
|
|
51
|
+
let _classDecorators = [(0, common_1.Injectable)()];
|
|
52
|
+
let _classDescriptor;
|
|
53
|
+
let _classExtraInitializers = [];
|
|
54
|
+
let _classThis;
|
|
55
|
+
var SimpleAppService = _classThis = class {
|
|
56
|
+
constructor(newdoc) {
|
|
57
|
+
this.jsonschema = { type: 'object', properties: {}, required: [] };
|
|
58
|
+
this.documentIdentityCode = 'code';
|
|
59
|
+
this.documentIdentityName = 'label';
|
|
60
|
+
this.documentName = 'category';
|
|
61
|
+
this.documentType = 'CAT';
|
|
62
|
+
this.LIMITPERPAGE = 20;
|
|
63
|
+
this.data = { _id: '' };
|
|
64
|
+
this.errorlist = [];
|
|
65
|
+
this.getRecordId = () => this.data._id;
|
|
66
|
+
this.setSchema = (newschema) => (this.jsonschema = newschema);
|
|
67
|
+
this.getSchema = () => this.doc.schema.obj;
|
|
68
|
+
this.getData = () => {
|
|
69
|
+
//console.log('thisdata', this.data);
|
|
70
|
+
return this.data;
|
|
71
|
+
};
|
|
72
|
+
this.setData = (newdata) => {
|
|
73
|
+
delete newdata._id;
|
|
74
|
+
this.data = Object.assign({}, newdata);
|
|
75
|
+
return this;
|
|
76
|
+
};
|
|
77
|
+
this.doc = newdoc;
|
|
78
|
+
}
|
|
79
|
+
async list() {
|
|
80
|
+
try {
|
|
81
|
+
const products = await this.doc.find();
|
|
82
|
+
const productlist = products.map((p) => {
|
|
83
|
+
return p;
|
|
84
|
+
});
|
|
85
|
+
// console.log(products);
|
|
86
|
+
return productlist;
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
throw new exceptions_1.InternalServerErrorException(err.message);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async getAutoComplete(keyword) {
|
|
93
|
+
try {
|
|
94
|
+
const filter1 = {};
|
|
95
|
+
const filter2 = {};
|
|
96
|
+
filter1[this.documentIdentityCode] = { $regex: keyword };
|
|
97
|
+
filter2[this.documentIdentityName] = { $regex: keyword };
|
|
98
|
+
const filterobj = { $or: [filter1, filter2] };
|
|
99
|
+
const projections = {
|
|
100
|
+
id: `\$_id`,
|
|
101
|
+
label: `\$${this.documentIdentityCode}`,
|
|
102
|
+
name: `\$${this.documentIdentityName}`,
|
|
103
|
+
};
|
|
104
|
+
const products = await this.doc.find(filterobj, projections, {
|
|
105
|
+
limit: this.LIMITPERPAGE,
|
|
106
|
+
});
|
|
107
|
+
const productlist = products.map((p) => {
|
|
108
|
+
return p;
|
|
109
|
+
});
|
|
110
|
+
return productlist;
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
throw new exceptions_1.InternalServerErrorException(err.message);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async findById(id) {
|
|
117
|
+
try {
|
|
118
|
+
//console.log('findById', id);
|
|
119
|
+
this.data = await this.doc.findById(id);
|
|
120
|
+
//console.log('findById done', this.data);
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
//error
|
|
124
|
+
throw new exceptions_1.InternalServerErrorException(err.message);
|
|
125
|
+
}
|
|
126
|
+
if (!this.data) {
|
|
127
|
+
//data not found
|
|
128
|
+
throw new exceptions_1.NotFoundException('Document Not found:');
|
|
129
|
+
}
|
|
130
|
+
//console.log('this.data', this.data);
|
|
131
|
+
return this.data;
|
|
132
|
+
// return this;
|
|
133
|
+
}
|
|
134
|
+
async create() {
|
|
135
|
+
let result;
|
|
136
|
+
try {
|
|
137
|
+
delete this.data._id;
|
|
138
|
+
this.validateData(this.data);
|
|
139
|
+
const newdoc = new this.doc(this.data);
|
|
140
|
+
result = await newdoc.save();
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
throw new exceptions_1.InternalServerErrorException(err.message);
|
|
144
|
+
}
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
async update() {
|
|
148
|
+
const id = this.getRecordId();
|
|
149
|
+
this.findIdThenUpdate(id, this.data);
|
|
150
|
+
}
|
|
151
|
+
async delete() {
|
|
152
|
+
const id = this.getRecordId();
|
|
153
|
+
const dependency = await this.getRelatedRecords(id);
|
|
154
|
+
if (!dependency) {
|
|
155
|
+
return await this.findIdThenDelete(id);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
return dependency;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
hook(type, data) {
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
validateData(data) {
|
|
165
|
+
const ajv = new ajv_1.default({ allErrors: true });
|
|
166
|
+
(0, ajv_formats_1.default)(ajv);
|
|
167
|
+
ajv.addFormat('field-autocomplete-code', /.*$/);
|
|
168
|
+
ajv.addFormat('field-autocomplete-name', /.*$/);
|
|
169
|
+
ajv.addFormat('x-text', /.*$/);
|
|
170
|
+
ajv.addFormat('x-html', /.*$/);
|
|
171
|
+
ajv.addKeyword({
|
|
172
|
+
keyword: 'x-foreignkey',
|
|
173
|
+
type: 'string',
|
|
174
|
+
});
|
|
175
|
+
if (!this.hook('pre-validation', data)) {
|
|
176
|
+
const erromsg = [];
|
|
177
|
+
for (let i = 0; i < this.errorlist.length; i++) {
|
|
178
|
+
erromsg.push(this.errorlist[i].message);
|
|
179
|
+
}
|
|
180
|
+
throw new exceptions_1.InternalServerErrorException(erromsg.join('\n'));
|
|
181
|
+
}
|
|
182
|
+
const validate = ajv.compile(this.jsonschema);
|
|
183
|
+
const valid = validate(data);
|
|
184
|
+
if (!valid) {
|
|
185
|
+
//console.log(validate.errors);
|
|
186
|
+
const erromsg = [];
|
|
187
|
+
for (let i = 0; i < validate.errors.length; i++) {
|
|
188
|
+
erromsg.push(validate.errors[i].message);
|
|
189
|
+
}
|
|
190
|
+
throw new exceptions_1.InternalServerErrorException(erromsg.join('\n'));
|
|
191
|
+
}
|
|
192
|
+
this.hook('post-validation', data);
|
|
193
|
+
}
|
|
194
|
+
async findIdThenDelete(id) {
|
|
195
|
+
// const data = await this.findById(id);
|
|
196
|
+
try {
|
|
197
|
+
//console.log('deletedeletedeletedelete');
|
|
198
|
+
const dependency = await this.getRelatedRecords(id);
|
|
199
|
+
if (!dependency) {
|
|
200
|
+
const deleteresult = await this.doc.findByIdAndDelete(id);
|
|
201
|
+
return deleteresult;
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
return Promise.reject(dependency);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
catch (err) {
|
|
208
|
+
throw new exceptions_1.InternalServerErrorException(err.message);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
async findIdThenUpdate(id, data) {
|
|
212
|
+
// const existingdata = await this.findById(id);
|
|
213
|
+
try {
|
|
214
|
+
//console.log('findIdThenUpdate', id);
|
|
215
|
+
this.validateData(data);
|
|
216
|
+
// const result = await existingdata.doc.updateOne(data);
|
|
217
|
+
const result = await this.doc.findByIdAndUpdate(id, data);
|
|
218
|
+
return result;
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
throw new exceptions_1.InternalServerErrorException(err.message);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
//find what foreign key constraint
|
|
225
|
+
async getRelatedRecords(id) {
|
|
226
|
+
const foreignkeysettings = foreignkeys_json_1.default[this.documentName];
|
|
227
|
+
//console.log('foreignkeysettings', foreignkeysettings);
|
|
228
|
+
const propkeys = Object.getOwnPropertyNames(foreignkeysettings);
|
|
229
|
+
if (propkeys.length > 0) {
|
|
230
|
+
//console.log('Have properties');
|
|
231
|
+
for (let i = 0; i < propkeys.length; i++) {
|
|
232
|
+
const collectionname = propkeys[i];
|
|
233
|
+
//console.log('run ', i, collectionname);
|
|
234
|
+
const fobjs = foreignkeysettings[propkeys[i]];
|
|
235
|
+
const collection = this.doc.db.collection(collectionname);
|
|
236
|
+
//single schema may have multiple foreign key link here, loop all
|
|
237
|
+
for (let j = 0; j < fobjs.length; j++) {
|
|
238
|
+
const fkey = fobjs[j];
|
|
239
|
+
const filter = {};
|
|
240
|
+
filter[fkey] = id;
|
|
241
|
+
//console.log('getRelatedRecords get filter', collectionname, filter);
|
|
242
|
+
const result = await collection.findOne(filter);
|
|
243
|
+
//console.log('getRelatedRecords', result);
|
|
244
|
+
if (result) {
|
|
245
|
+
return Promise.reject(result);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return Promise.resolve(null);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
__setFunctionName(_classThis, "SimpleAppService");
|
|
254
|
+
(() => {
|
|
255
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
256
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
257
|
+
SimpleAppService = _classThis = _classDescriptor.value;
|
|
258
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
259
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
260
|
+
})();
|
|
261
|
+
return SimpleAppService = _classThis;
|
|
262
|
+
})();
|
|
263
|
+
exports.SimpleAppService = SimpleAppService;
|
|
264
|
+
//# sourceMappingURL=SimpleAppService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SimpleAppService.js","sourceRoot":"","sources":["SimpleAppService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA4C;AAG5C,8CAAsB;AACtB,8DAAqC;AACrC,iFAAoD;AACpD,0DAGmC;IAEtB,gBAAgB;4BAD5B,IAAA,mBAAU,GAAE;;;;;QAWX,YAAY,MAAgB;YATlB,eAAU,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;YAC9D,yBAAoB,GAAG,MAAM,CAAC;YAC9B,yBAAoB,GAAG,OAAO,CAAC;YAC/B,iBAAY,GAAG,UAAU,CAAC;YAC1B,iBAAY,GAAG,KAAK,CAAC;YACrB,iBAAY,GAAG,EAAE,CAAC;YAClB,SAAI,GAAM,EAAE,GAAG,EAAE,EAAE,EAAO,CAAC;YAE3B,cAAS,GAAG,EAAE,CAAC;YAIzB,gBAAW,GAAG,GAAW,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;YAC1C,cAAS,GAAG,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;YACzD,cAAS,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC;YAC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CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;wBACrC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;wBACtB,MAAM,MAAM,GAAG,EAAE,CAAC;wBAClB,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;wBAClB,sEAAsE;wBACtE,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;wBAChD,2CAA2C;wBAC3C,IAAI,MAAM,EAAE;4BACV,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;yBAC/B;qBACF;iBACF;aACF;YACD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;;;;;QAxMH,6KAyMC;;;QAzMY,uDAAgB;;;;AAAhB,4CAAgB"}
|
|
@@ -0,0 +1,213 @@
|
|
|
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 foreignkeys from '../dicts/foreignkeys.json';
|
|
7
|
+
import {
|
|
8
|
+
NotFoundException,
|
|
9
|
+
InternalServerErrorException,
|
|
10
|
+
} from '@nestjs/common/exceptions';
|
|
11
|
+
@Injectable()
|
|
12
|
+
export class SimpleAppService<T extends { _id?: string }> {
|
|
13
|
+
protected jsonschema = { type: 'object', properties: {}, required: [] };
|
|
14
|
+
protected documentIdentityCode = 'code';
|
|
15
|
+
protected documentIdentityName = 'label';
|
|
16
|
+
protected documentName = 'category';
|
|
17
|
+
protected documentType = 'CAT';
|
|
18
|
+
protected LIMITPERPAGE = 20;
|
|
19
|
+
protected data: T = { _id: '' } as T;
|
|
20
|
+
protected doc: Model<T>;
|
|
21
|
+
protected errorlist = [];
|
|
22
|
+
constructor(newdoc: Model<T>) {
|
|
23
|
+
this.doc = newdoc;
|
|
24
|
+
}
|
|
25
|
+
getRecordId = (): string => this.data._id;
|
|
26
|
+
setSchema = (newschema) => (this.jsonschema = newschema);
|
|
27
|
+
getSchema = () => this.doc.schema.obj;
|
|
28
|
+
getData = () => {
|
|
29
|
+
//console.log('thisdata', this.data);
|
|
30
|
+
return this.data;
|
|
31
|
+
};
|
|
32
|
+
setData = (newdata: T) => {
|
|
33
|
+
delete newdata._id;
|
|
34
|
+
this.data = { ...newdata };
|
|
35
|
+
return this;
|
|
36
|
+
};
|
|
37
|
+
async list() {
|
|
38
|
+
try {
|
|
39
|
+
const products = await this.doc.find();
|
|
40
|
+
const productlist = products.map((p: T) => {
|
|
41
|
+
return p;
|
|
42
|
+
});
|
|
43
|
+
// console.log(products);
|
|
44
|
+
return productlist;
|
|
45
|
+
} catch (err) {
|
|
46
|
+
throw new InternalServerErrorException(err.message);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async getAutoComplete(keyword: string) {
|
|
50
|
+
try {
|
|
51
|
+
const filter1 = {};
|
|
52
|
+
const filter2 = {};
|
|
53
|
+
filter1[this.documentIdentityCode] = { $regex: keyword };
|
|
54
|
+
filter2[this.documentIdentityName] = { $regex: keyword };
|
|
55
|
+
const filterobj = { $or: [filter1, filter2] };
|
|
56
|
+
const projections = {
|
|
57
|
+
id: `\$_id`,
|
|
58
|
+
label: `\$${this.documentIdentityCode}`,
|
|
59
|
+
name: `\$${this.documentIdentityName}`,
|
|
60
|
+
};
|
|
61
|
+
const products = await this.doc.find(filterobj, projections, {
|
|
62
|
+
limit: this.LIMITPERPAGE,
|
|
63
|
+
});
|
|
64
|
+
const productlist = products.map((p: T) => {
|
|
65
|
+
return p;
|
|
66
|
+
});
|
|
67
|
+
return productlist;
|
|
68
|
+
} catch (err) {
|
|
69
|
+
throw new InternalServerErrorException(err.message);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async findById(id: string) {
|
|
73
|
+
try {
|
|
74
|
+
//console.log('findById', id);
|
|
75
|
+
this.data = await this.doc.findById(id);
|
|
76
|
+
//console.log('findById done', this.data);
|
|
77
|
+
} catch (err) {
|
|
78
|
+
//error
|
|
79
|
+
throw new InternalServerErrorException(err.message);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!this.data) {
|
|
83
|
+
//data not found
|
|
84
|
+
throw new NotFoundException('Document Not found:');
|
|
85
|
+
}
|
|
86
|
+
//console.log('this.data', this.data);
|
|
87
|
+
return this.data;
|
|
88
|
+
// return this;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async create() {
|
|
92
|
+
let result;
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
delete this.data._id;
|
|
96
|
+
this.validateData(this.data);
|
|
97
|
+
const newdoc = new this.doc(this.data);
|
|
98
|
+
result = await newdoc.save();
|
|
99
|
+
} catch (err) {
|
|
100
|
+
throw new InternalServerErrorException(err.message);
|
|
101
|
+
}
|
|
102
|
+
return result as T;
|
|
103
|
+
}
|
|
104
|
+
async update() {
|
|
105
|
+
const id: string = this.getRecordId();
|
|
106
|
+
this.findIdThenUpdate(id, this.data);
|
|
107
|
+
}
|
|
108
|
+
async delete() {
|
|
109
|
+
|
|
110
|
+
const id: string = this.getRecordId();
|
|
111
|
+
const dependency = await this.getRelatedRecords(id);
|
|
112
|
+
if (!dependency) {
|
|
113
|
+
return await this.findIdThenDelete(id);
|
|
114
|
+
} else {
|
|
115
|
+
return dependency;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
hook(type: string, data: T) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
validateData(data: T) {
|
|
122
|
+
const ajv = new Ajv({ allErrors: true });
|
|
123
|
+
addFormats(ajv);
|
|
124
|
+
ajv.addFormat('field-autocomplete-code', /.*$/);
|
|
125
|
+
ajv.addFormat('field-autocomplete-name', /.*$/);
|
|
126
|
+
ajv.addFormat('x-text',/.*$/)
|
|
127
|
+
ajv.addFormat('x-html',/.*$/)
|
|
128
|
+
ajv.addKeyword({
|
|
129
|
+
keyword: 'x-foreignkey',
|
|
130
|
+
type: 'string',
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
if (!this.hook('pre-validation', data)) {
|
|
134
|
+
const erromsg: string[] = [];
|
|
135
|
+
for (let i = 0; i < this.errorlist.length; i++) {
|
|
136
|
+
erromsg.push(this.errorlist[i].message);
|
|
137
|
+
}
|
|
138
|
+
throw new InternalServerErrorException(erromsg.join('\n'));
|
|
139
|
+
}
|
|
140
|
+
const validate = ajv.compile(this.jsonschema);
|
|
141
|
+
const valid = validate(data);
|
|
142
|
+
if (!valid) {
|
|
143
|
+
//console.log(validate.errors);
|
|
144
|
+
const erromsg: string[] = [];
|
|
145
|
+
for (let i = 0; i < validate.errors.length; i++) {
|
|
146
|
+
erromsg.push(validate.errors[i].message);
|
|
147
|
+
}
|
|
148
|
+
throw new InternalServerErrorException(erromsg.join('\n'));
|
|
149
|
+
}
|
|
150
|
+
this.hook('post-validation', data);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async findIdThenDelete(id: string) {
|
|
154
|
+
// const data = await this.findById(id);
|
|
155
|
+
try {
|
|
156
|
+
//console.log('deletedeletedeletedelete');
|
|
157
|
+
const dependency = await this.getRelatedRecords(id);
|
|
158
|
+
if (!dependency) {
|
|
159
|
+
const deleteresult = await this.doc.findByIdAndDelete(id);
|
|
160
|
+
return deleteresult;
|
|
161
|
+
} else {
|
|
162
|
+
return Promise.reject(dependency);
|
|
163
|
+
}
|
|
164
|
+
} catch (err) {
|
|
165
|
+
throw new InternalServerErrorException(err.message);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async findIdThenUpdate(id: string, data: T) {
|
|
170
|
+
// const existingdata = await this.findById(id);
|
|
171
|
+
|
|
172
|
+
try {
|
|
173
|
+
//console.log('findIdThenUpdate', id);
|
|
174
|
+
this.validateData(data);
|
|
175
|
+
// const result = await existingdata.doc.updateOne(data);
|
|
176
|
+
const result = await this.doc.findByIdAndUpdate(id, data);
|
|
177
|
+
|
|
178
|
+
return result;
|
|
179
|
+
} catch (err) {
|
|
180
|
+
throw new InternalServerErrorException(err.message);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
//find what foreign key constraint
|
|
185
|
+
async getRelatedRecords(id: string) {
|
|
186
|
+
const foreignkeysettings = foreignkeys[this.documentName];
|
|
187
|
+
//console.log('foreignkeysettings', foreignkeysettings);
|
|
188
|
+
const propkeys = Object.getOwnPropertyNames(foreignkeysettings);
|
|
189
|
+
|
|
190
|
+
if (propkeys.length > 0) {
|
|
191
|
+
//console.log('Have properties');
|
|
192
|
+
for (let i = 0; i < propkeys.length; i++) {
|
|
193
|
+
const collectionname = propkeys[i];
|
|
194
|
+
//console.log('run ', i, collectionname);
|
|
195
|
+
const fobjs = foreignkeysettings[propkeys[i]];
|
|
196
|
+
const collection = this.doc.db.collection(collectionname);
|
|
197
|
+
//single schema may have multiple foreign key link here, loop all
|
|
198
|
+
for (let j = 0; j < fobjs.length; j++) {
|
|
199
|
+
const fkey = fobjs[j];
|
|
200
|
+
const filter = {};
|
|
201
|
+
filter[fkey] = id;
|
|
202
|
+
//console.log('getRelatedRecords get filter', collectionname, filter);
|
|
203
|
+
const result = await collection.findOne(filter);
|
|
204
|
+
//console.log('getRelatedRecords', result);
|
|
205
|
+
if (result) {
|
|
206
|
+
return Promise.reject(result);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return Promise.resolve(null);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@nestjs/core");
|
|
4
|
+
const app_module_1 = require("./app.module");
|
|
5
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
6
|
+
async function bootstrap() {
|
|
7
|
+
var _a;
|
|
8
|
+
const app = await core_1.NestFactory.create(app_module_1.AppModule);
|
|
9
|
+
app.enableCors();
|
|
10
|
+
const config = new swagger_1.DocumentBuilder()
|
|
11
|
+
.setTitle(process.env.PROJECT_NAME)
|
|
12
|
+
.setDescription(process.env.PROJECT_DESCRIPTION)
|
|
13
|
+
.setVersion(process.env.PROJECT_VERSION)
|
|
14
|
+
.build();
|
|
15
|
+
const document = swagger_1.SwaggerModule.createDocument(app, config);
|
|
16
|
+
swagger_1.SwaggerModule.setup('api', app, document, {
|
|
17
|
+
swaggerOptions: { showExtensions: true },
|
|
18
|
+
});
|
|
19
|
+
await app.listen((_a = process.env.HTTP_PORT) !== null && _a !== void 0 ? _a : 8000); //listen which port
|
|
20
|
+
}
|
|
21
|
+
bootstrap();
|
|
22
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["main.ts"],"names":[],"mappings":";;AAAA,uCAA2C;AAC3C,6CAAyC;AACzC,6CAAiE;AAEjE,KAAK,UAAU,SAAS;;IACtB,MAAM,GAAG,GAAG,MAAM,kBAAW,CAAC,MAAM,CAAC,sBAAS,CAAC,CAAC;IAChD,GAAG,CAAC,UAAU,EAAE,CAAC;IACjB,MAAM,MAAM,GAAG,IAAI,yBAAe,EAAE;SACjC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;SAClC,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;SAC/C,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;SACvC,KAAK,EAAE,CAAC;IACX,MAAM,QAAQ,GAAG,uBAAa,CAAC,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC3D,uBAAa,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE;QACxC,cAAc,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE;KACzC,CAAC,CAAC;IAEH,MAAM,GAAG,CAAC,MAAM,CAAC,MAAA,OAAO,CAAC,GAAG,CAAC,SAAS,mCAAI,IAAI,CAAC,CAAC,CAAC,mBAAmB;AACtE,CAAC;AACD,SAAS,EAAE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { NestFactory } from '@nestjs/core';
|
|
2
|
+
import { AppModule } from './app.module';
|
|
3
|
+
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
|
|
4
|
+
|
|
5
|
+
async function bootstrap() {
|
|
6
|
+
const app = await NestFactory.create(AppModule);
|
|
7
|
+
app.enableCors();
|
|
8
|
+
const config = new DocumentBuilder()
|
|
9
|
+
.setTitle(process.env.PROJECT_NAME)
|
|
10
|
+
.setDescription(process.env.PROJECT_DESCRIPTION)
|
|
11
|
+
.setVersion(process.env.PROJECT_VERSION)
|
|
12
|
+
.build();
|
|
13
|
+
const document = SwaggerModule.createDocument(app, config);
|
|
14
|
+
SwaggerModule.setup('api', app, document, {
|
|
15
|
+
swaggerOptions: { showExtensions: true },
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
await app.listen(process.env.HTTP_PORT ?? 8000); //listen which port
|
|
19
|
+
}
|
|
20
|
+
bootstrap();
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const testing_1 = require("@nestjs/testing");
|
|
27
|
+
const request = __importStar(require("supertest"));
|
|
28
|
+
const app_module_1 = require("./../src/app.module");
|
|
29
|
+
describe('AppController (e2e)', () => {
|
|
30
|
+
let app;
|
|
31
|
+
beforeEach(async () => {
|
|
32
|
+
const moduleFixture = await testing_1.Test.createTestingModule({
|
|
33
|
+
imports: [app_module_1.AppModule],
|
|
34
|
+
}).compile();
|
|
35
|
+
app = moduleFixture.createNestApplication();
|
|
36
|
+
await app.init();
|
|
37
|
+
});
|
|
38
|
+
it('/ (GET)', () => {
|
|
39
|
+
return request(app.getHttpServer())
|
|
40
|
+
.get('/')
|
|
41
|
+
.expect(200)
|
|
42
|
+
.expect('Hello World!');
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=app.e2e-spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.e2e-spec.js","sourceRoot":"","sources":["app.e2e-spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAsD;AAEtD,mDAAqC;AACrC,oDAAgD;AAEhD,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,IAAI,GAAqB,CAAC;IAE1B,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,MAAM,aAAa,GAAkB,MAAM,cAAI,CAAC,mBAAmB,CAAC;YAClE,OAAO,EAAE,CAAC,sBAAS,CAAC;SACrB,CAAC,CAAC,OAAO,EAAE,CAAC;QAEb,GAAG,GAAG,aAAa,CAAC,qBAAqB,EAAE,CAAC;QAC5C,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IACnB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;QACjB,OAAO,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;aAChC,GAAG,CAAC,GAAG,CAAC;aACR,MAAM,CAAC,GAAG,CAAC;aACX,MAAM,CAAC,cAAc,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
|
2
|
+
import { INestApplication } from '@nestjs/common';
|
|
3
|
+
import * as request from 'supertest';
|
|
4
|
+
import { AppModule } from './../src/app.module';
|
|
5
|
+
|
|
6
|
+
describe('AppController (e2e)', () => {
|
|
7
|
+
let app: INestApplication;
|
|
8
|
+
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
const moduleFixture: TestingModule = await Test.createTestingModule({
|
|
11
|
+
imports: [AppModule],
|
|
12
|
+
}).compile();
|
|
13
|
+
|
|
14
|
+
app = moduleFixture.createNestApplication();
|
|
15
|
+
await app.init();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('/ (GET)', () => {
|
|
19
|
+
return request(app.getHttpServer())
|
|
20
|
+
.get('/')
|
|
21
|
+
.expect(200)
|
|
22
|
+
.expect('Hello World!');
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"compilerOptions":{"module":"commonjs","declaration":true,"removeComments":true,"emitDecoratorMetadata":true,"experimentalDecorators":true,"allowSyntheticDefaultImports":true,"target":"ES2021","sourceMap":true,"outDir":"./dist","baseUrl":"./","incremental":true,"skipLibCheck":true,"strictNullChecks":false,"noImplicitAny":false,"strictBindCallApply":false,"forceConsistentCasingInFileNames":false,"noFallthroughCasesInSwitch":false,"esModuleInterop":true,"resolveJsonModule":true}}
|
package/dist/createproject.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.createNest = exports.createNuxt = void 0;
|
|
26
|
+
exports.createNest = exports.createNuxt = exports.installDependency = void 0;
|
|
27
27
|
const child_process_1 = require("child_process");
|
|
28
28
|
const fs_1 = require("fs");
|
|
29
29
|
const constants = __importStar(require("./constant"));
|
|
@@ -53,6 +53,11 @@ const checkNestCli = (callback) => {
|
|
|
53
53
|
}
|
|
54
54
|
});
|
|
55
55
|
};
|
|
56
|
+
const installDependency = async () => {
|
|
57
|
+
log.info("installDependency 'npm install -g pnpm @nestjs/cli @openapitools/openapi-generator-cli nuxi'");
|
|
58
|
+
return await (0, child_process_1.exec)("npm install -g pnpm @nestjs/cli @openapitools/openapi-generator-cli nuxi");
|
|
59
|
+
};
|
|
60
|
+
exports.installDependency = installDependency;
|
|
56
61
|
const createNuxt = (targetfolder, callback) => {
|
|
57
62
|
log.info("setting up nuxt frontend ${targetfolder}");
|
|
58
63
|
log.info(`frontend nuxt project "${targetfolder}" created, installing module`);
|