@simitgroup/simpleapp-generator 1.2.0 → 1.2.2
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/dist/framework.js +1 -1
- package/package.json +1 -1
- package/templates/basic/nest/service.ts.eta +4 -42
- package/templates/basic/nest/type.ts.eta +7 -0
- package/templates/nest/src/simpleapp/generate/processors/simpleapp.processor.ts.eta +56 -33
- package/templates/nest/src/simpleapp/generate/types/index.ts.eta +5 -57
- package/templates/nest/src/simpleapp/generate/types/simpleapp.type.ts.eta +76 -0
- package/templates/nest/src/simpleapp/services/autoinc.service.ts.eta +3 -35
- package/templates/nest/src/simpleapp/services/branch.service.ts.eta +19 -43
- package/templates/nest/src/simpleapp/services/docno.service.ts.eta +3 -36
- package/templates/nest/src/simpleapp/services/org.service.ts.eta +8 -36
- package/templates/nest/src/simpleapp/services/perm.service.ts.eta +3 -46
- package/templates/nest/src/simpleapp/services/tenant.service.ts.eta +9 -39
- package/templates/nuxt/components/list/ListView.vue.eta +7 -7
- package/templates/nuxt/components/simpleApp/SimpleAppInput.vue.eta +11 -1
- package/templates/nuxt/composables/getOpenApi.generate.ts.eta +9 -48
- package/templates/nuxt/nuxt.config.ts._eta +1 -1
- package/templates/nuxt/pages/profile.vue.eta +8 -9
- package/templates/nuxt/plugins/20.simpleapp-userstore.ts.eta +27 -8
- package/templates/nuxt/server/api/[xorg]/[...].ts.eta +1 -1
- package/templates/nuxt/server/api/profile/[...].ts.eta +1 -1
- package/templates/nuxt/server/api/profile/index.ts.eta +1 -1
- package/templates/nuxt/types/user.ts.eta +34 -1
- package/templates/project/lang/default._json +12 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/templates/nest/src/simpleapp/generate/types/apievent.type.ts.eta +0 -22
package/dist/framework.js
CHANGED
|
@@ -99,7 +99,7 @@ const prepareNest = (callback) => {
|
|
|
99
99
|
const targetfolder = config.backendFolder;
|
|
100
100
|
log.info(`creating backend project ${targetfolder}`);
|
|
101
101
|
if (!fs_1.default.existsSync(`${targetfolder}/.env`)) {
|
|
102
|
-
(0, child_process_1.exec)(`cd ${targetfolder};pnpm install --save @nestjs/event-emitter dayjs bpmn-server@2.0.
|
|
102
|
+
(0, child_process_1.exec)(`cd ${targetfolder};pnpm install --save @nestjs/event-emitter dayjs bpmn-server@2.0.8-alpha2 moment @casl/ability jsonpath yaml lodash @types/lodash nest-keycloak-connect keycloak-connect bpmn-client @nestjs/serve-static jsonwebtoken axios @darkwolf/base64url json-schema @wearenova/mongoose-tenant @nestjs/swagger @nestjs/mongoose mongoose ajv ajv-formats ajv-errors @nestjs/config`, async (error, stdout, stderr) => {
|
|
103
103
|
// log.info(`dependency installed`)
|
|
104
104
|
if (!error) {
|
|
105
105
|
// fs.mkdirSync(`${targetfolder}/public_html`,{recursive:true})
|
package/package.json
CHANGED
|
@@ -9,9 +9,9 @@ import { Model } from 'mongoose';
|
|
|
9
9
|
import { Injectable } from '@nestjs/common';
|
|
10
10
|
import { UserContext } from '../generate/commons/user.context';
|
|
11
11
|
import { <%= it.typename %>Processor } from '../generate/processors/<%= it.doctype %>.processor';
|
|
12
|
-
import { <%= it.typename %>} from '../generate/types
|
|
13
|
-
|
|
14
|
-
export { <%= it.typename %>} from '../generate/types
|
|
12
|
+
import { <%= it.typename %>,<%= it.typename %>Hooks} from '../generate/types';
|
|
13
|
+
|
|
14
|
+
export { <%= it.typename %>} from '../generate/types';
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
@Injectable()
|
|
@@ -19,51 +19,13 @@ export class <%= it.typename %>Service extends <%= it.typename %>Processor {
|
|
|
19
19
|
<% const config = it.jsonschema['x-simpleapp-config']%>
|
|
20
20
|
<%if(config['loseDataIsolation']){%>protected strictIsolation = false;<%}%>
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
public hooks: <%= it.typename %>Hooks = {}
|
|
23
23
|
constructor(
|
|
24
24
|
@InjectModel('<%= it.typename %>') mydoc: Model<<%= it.typename %>>
|
|
25
25
|
){
|
|
26
26
|
super(mydoc)
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
// hook = async (appuser:UserContext,type: HookType, data?: any) => {
|
|
30
|
-
// switch(type){
|
|
31
|
-
// case HookType.init: //data = undefined
|
|
32
|
-
// break;
|
|
33
|
-
// case HookType.beforeSearch: //data = filters
|
|
34
|
-
// break;
|
|
35
|
-
// case HookType.afterSearch: //data = search result
|
|
36
|
-
// break;
|
|
37
|
-
// case HookType.beforeValidation: //data = documentdata
|
|
38
|
-
// break;
|
|
39
|
-
// case HookType.afterValidation: //data = documentdata
|
|
40
|
-
// break;
|
|
41
|
-
// case HookType.beforeCreate: //data = documentdata
|
|
42
|
-
// break;
|
|
43
|
-
// case HookType.afterCreate: //data = after create result (final data from mongodb)
|
|
44
|
-
// break;
|
|
45
|
-
// case HookType.beforeUpdate: //data = documentdata
|
|
46
|
-
// break;
|
|
47
|
-
// case HookType.afterUpdate: //data = after update result (return from mongodb)
|
|
48
|
-
// break;
|
|
49
|
-
// case HookType.beforeDelete: //data = record _id
|
|
50
|
-
// break;
|
|
51
|
-
// case HookType.afterDelete: //data = deleted result
|
|
52
|
-
// break;
|
|
53
|
-
// case HookType.beforeFetchRecord: //data = record _id
|
|
54
|
-
// break;
|
|
55
|
-
// case HookType.afterFetchRecord: //data = document data
|
|
56
|
-
// break;
|
|
57
|
-
// case HookType.beforeSetStatus: //data = document data
|
|
58
|
-
// break;
|
|
59
|
-
// case HookType.afterSetStatus: //data = document data
|
|
60
|
-
// break;
|
|
61
|
-
// default:
|
|
62
|
-
// break;
|
|
63
|
-
// }
|
|
64
|
-
// return true;
|
|
65
|
-
// };
|
|
66
|
-
|
|
67
29
|
/***************************** begin x-document-api definitions *****************************************/
|
|
68
30
|
<% for(let i=0;i<it.apiSettings.length;i++){%>
|
|
69
31
|
<% let api = it.apiSettings[i] %>
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* last change 2023-09-09
|
|
6
6
|
* Author: Ks Tan
|
|
7
7
|
*/
|
|
8
|
+
import {DefaultHooks} from "../types"
|
|
8
9
|
|
|
9
10
|
<%Object.keys(it.models).forEach(function(prop){ %>
|
|
10
11
|
<% let schema = it.models[prop] %>
|
|
@@ -26,3 +27,9 @@
|
|
|
26
27
|
}
|
|
27
28
|
<%})%>
|
|
28
29
|
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
export type <%=it.typename%>Hooks = DefaultHooks<<%=it.typename%>> & {
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
}
|
|
@@ -31,12 +31,12 @@ import {
|
|
|
31
31
|
} from '@nestjs/common/exceptions';
|
|
32
32
|
import { UserContext } from '../commons/user.context';
|
|
33
33
|
import { DocNumberFormatGenerator } from '../commons/docnogenerator.service';
|
|
34
|
-
import { IsolationType,
|
|
34
|
+
import { IsolationType, DefaultHooks, MoreProjectionType } from '../types';
|
|
35
35
|
@Injectable()
|
|
36
36
|
export class SimpleAppService<T extends { _id?: string }> {
|
|
37
37
|
@Inject(EventEmitter2)
|
|
38
38
|
protected eventEmitter: EventEmitter2;
|
|
39
|
-
|
|
39
|
+
protected hooks: DefaultHooks<T> = {};
|
|
40
40
|
protected logger = new Logger();
|
|
41
41
|
protected strictIsolation = true;
|
|
42
42
|
protected jsonschema = { type: 'object', properties: {}, required: [] };
|
|
@@ -73,7 +73,7 @@ export class SimpleAppService<T extends { _id?: string }> {
|
|
|
73
73
|
this.documentName = docname;
|
|
74
74
|
this.doc = newdoc;
|
|
75
75
|
this.isolationtype = isolationtype;
|
|
76
|
-
this.
|
|
76
|
+
if (this.hooks.init) this.hooks.init();
|
|
77
77
|
// this.tenantdoc = tenantdoc
|
|
78
78
|
}
|
|
79
79
|
getDocumentType = () => this.documentType;
|
|
@@ -81,6 +81,7 @@ export class SimpleAppService<T extends { _id?: string }> {
|
|
|
81
81
|
getRecordId = (): string => this.data._id;
|
|
82
82
|
setSchema = (newschema) => (this.jsonschema = newschema);
|
|
83
83
|
getSchema = () => this.doc.schema.obj;
|
|
84
|
+
getHooks = () => this.hooks;
|
|
84
85
|
getData = () => {
|
|
85
86
|
//console.log('thisdata', this.data);
|
|
86
87
|
return this.data;
|
|
@@ -181,12 +182,15 @@ export class SimpleAppService<T extends { _id?: string }> {
|
|
|
181
182
|
*/
|
|
182
183
|
private async searchNoIsolation(appuser: UserContext, filters: Object) {
|
|
183
184
|
try {
|
|
184
|
-
|
|
185
|
+
if (this.hooks.beforeSearch)
|
|
186
|
+
await this.hooks.beforeSearch(appuser, filters);
|
|
185
187
|
const products = await this.doc.find(filters);
|
|
186
188
|
const productlist = products.map((p: T) => {
|
|
187
189
|
return p;
|
|
188
190
|
});
|
|
189
|
-
|
|
191
|
+
if (this.hooks.afterSearch)
|
|
192
|
+
await this.hooks.afterSearch(appuser, productlist);
|
|
193
|
+
|
|
190
194
|
// console.log(products);
|
|
191
195
|
return productlist;
|
|
192
196
|
} catch (err) {
|
|
@@ -224,7 +228,9 @@ export class SimpleAppService<T extends { _id?: string }> {
|
|
|
224
228
|
|
|
225
229
|
// console.log("initial search",filters)
|
|
226
230
|
const newfilters = { ...filters, ...isolationFilter };
|
|
227
|
-
|
|
231
|
+
|
|
232
|
+
if (this.hooks.beforeSearch)
|
|
233
|
+
await this.hooks.beforeSearch(appuser, newfilters);
|
|
228
234
|
// console.log("before _find",newfilters)
|
|
229
235
|
// console.log("this.doc",this.doc)
|
|
230
236
|
const products = await this.doc
|
|
@@ -235,7 +241,9 @@ export class SimpleAppService<T extends { _id?: string }> {
|
|
|
235
241
|
return p;
|
|
236
242
|
});
|
|
237
243
|
// console.log("after map",productlist)
|
|
238
|
-
|
|
244
|
+
if (this.hooks.afterSearch)
|
|
245
|
+
await this.hooks.afterSearch(appuser, productlist);
|
|
246
|
+
|
|
239
247
|
// console.log(products);
|
|
240
248
|
return productlist;
|
|
241
249
|
} catch (err) {
|
|
@@ -244,9 +252,12 @@ export class SimpleAppService<T extends { _id?: string }> {
|
|
|
244
252
|
// return this;
|
|
245
253
|
}
|
|
246
254
|
async findById(appuser: UserContext, id: string) {
|
|
247
|
-
|
|
255
|
+
if (this.hooks.beforeFetchRecord)
|
|
256
|
+
await this.hooks.beforeFetchRecord(appuser, id);
|
|
248
257
|
const data = await this.search(appuser, { _id: id });
|
|
249
|
-
|
|
258
|
+
if (this.hooks.afterFetchRecord)
|
|
259
|
+
await this.hooks.afterFetchRecord(appuser, data[0]);
|
|
260
|
+
|
|
250
261
|
if (data.length == 1) {
|
|
251
262
|
// console.log('data0', data[0]);
|
|
252
263
|
return data[0];
|
|
@@ -276,8 +287,7 @@ export class SimpleAppService<T extends { _id?: string }> {
|
|
|
276
287
|
await this.genNewDocNo(appuser, data);
|
|
277
288
|
}
|
|
278
289
|
|
|
279
|
-
await this.
|
|
280
|
-
|
|
290
|
+
if (this.hooks.beforeCreate) await this.hooks.beforeCreate(appuser, data);
|
|
281
291
|
let isolationFilter: any = { ...appuser.getCreateFilter() };
|
|
282
292
|
isolationFilter = this.polishIsolationFilter(isolationFilter, data);
|
|
283
293
|
|
|
@@ -287,11 +297,10 @@ export class SimpleAppService<T extends { _id?: string }> {
|
|
|
287
297
|
this.logger.debug(data, 'SimpleAppService');
|
|
288
298
|
Object.assign(data, isolationFilter);
|
|
289
299
|
this.reCalculateValue(data);
|
|
290
|
-
await this.validateData(appuser, data);
|
|
291
|
-
this.logger.debug(
|
|
292
|
-
this.logger.debug(data, 'SimpleAppService');
|
|
293
|
-
|
|
300
|
+
await this.validateData(appuser, data);
|
|
301
|
+
this.logger.debug(data, `after create validation`);
|
|
294
302
|
this.applyNestedDateTime(appuser, data, 'create');
|
|
303
|
+
this.logger.debug(data, `Create Record ${this.documentName}`);
|
|
295
304
|
const newdoc = new this.doc(data);
|
|
296
305
|
await this.identifyForeignKeys(appuser, data);
|
|
297
306
|
try {
|
|
@@ -306,7 +315,8 @@ export class SimpleAppService<T extends { _id?: string }> {
|
|
|
306
315
|
// this.doc
|
|
307
316
|
|
|
308
317
|
// result = await newdoc.save()
|
|
309
|
-
|
|
318
|
+
|
|
319
|
+
if (this.hooks.afterCreate) await this.hooks.afterCreate(appuser, result);
|
|
310
320
|
|
|
311
321
|
return result as T;
|
|
312
322
|
}
|
|
@@ -345,9 +355,6 @@ export class SimpleAppService<T extends { _id?: string }> {
|
|
|
345
355
|
}
|
|
346
356
|
}
|
|
347
357
|
};
|
|
348
|
-
hook = async (appuser: UserContext, type: string, data?: any) => {
|
|
349
|
-
return true;
|
|
350
|
-
};
|
|
351
358
|
async validateData(appuser: UserContext, data: T) {
|
|
352
359
|
const ajv = new Ajv({ allErrors: true, useDefaults: true });
|
|
353
360
|
addFormats(ajv);
|
|
@@ -360,14 +367,18 @@ export class SimpleAppService<T extends { _id?: string }> {
|
|
|
360
367
|
|
|
361
368
|
ajv.addKeyword({ keyword: 'x-foreignkey', schemaType: 'string' });
|
|
362
369
|
ajv.addKeyword({ keyword: 'x-simpleapp-config', schemaType: 'object' });
|
|
363
|
-
|
|
364
|
-
|
|
370
|
+
this.logger.debug('run hook during validation');
|
|
371
|
+
let issuccess = true;
|
|
372
|
+
if (this.hooks.beforeValidation) {
|
|
373
|
+
issuccess = await this.hooks.beforeValidation(appuser, data);
|
|
374
|
+
}
|
|
375
|
+
// const issuccess = await this.hook(appuser, HookType.beforeValidation, data);
|
|
365
376
|
if (!issuccess) {
|
|
366
377
|
const errormsg: string[] = [];
|
|
367
378
|
for (let i = 0; i < this.errorlist.length; i++) {
|
|
368
379
|
errormsg.push(this.errorlist[i].message);
|
|
369
380
|
}
|
|
370
|
-
|
|
381
|
+
|
|
371
382
|
throw new BadRequestException(
|
|
372
383
|
'Before validation hook failed',
|
|
373
384
|
errormsg as HttpExceptionOptions,
|
|
@@ -389,7 +400,8 @@ export class SimpleAppService<T extends { _id?: string }> {
|
|
|
389
400
|
validate.errors as HttpExceptionOptions,
|
|
390
401
|
);
|
|
391
402
|
}
|
|
392
|
-
|
|
403
|
+
if (this.hooks.afterValidation)
|
|
404
|
+
await this.hooks.afterValidation(appuser, data);
|
|
393
405
|
}
|
|
394
406
|
|
|
395
407
|
polishIsolationFilter = (filterIsolation: any, data: any = {}) => {
|
|
@@ -431,7 +443,7 @@ export class SimpleAppService<T extends { _id?: string }> {
|
|
|
431
443
|
|
|
432
444
|
let dependency;
|
|
433
445
|
try {
|
|
434
|
-
await this.
|
|
446
|
+
if (this.hooks.beforeDelete) await this.hooks.beforeDelete(appuser, id);
|
|
435
447
|
this.logger.debug('delete record', this.documentName, id);
|
|
436
448
|
dependency = await this.getRelatedRecords(id);
|
|
437
449
|
//console.log('dependency', dependency);
|
|
@@ -452,8 +464,9 @@ export class SimpleAppService<T extends { _id?: string }> {
|
|
|
452
464
|
' delete result' + this.doc.collection.name,
|
|
453
465
|
);
|
|
454
466
|
// this.doc.findByIdAndDelete(id)
|
|
455
|
-
await this.hook(appuser, HookType.afterDelete, deleteresult);
|
|
456
467
|
|
|
468
|
+
if (this.hooks.afterDelete)
|
|
469
|
+
await this.hooks.afterDelete(appuser, deleteresult, id);
|
|
457
470
|
//this.doc.findByIdAndDelete(id);
|
|
458
471
|
return deleteresult;
|
|
459
472
|
} else {
|
|
@@ -481,7 +494,9 @@ export class SimpleAppService<T extends { _id?: string }> {
|
|
|
481
494
|
if (!existingdata) {
|
|
482
495
|
throw new NotFoundException(`${id} not found`, 'not found');
|
|
483
496
|
}
|
|
484
|
-
|
|
497
|
+
|
|
498
|
+
if (this.hooks.beforeUpdate)
|
|
499
|
+
await this.hooks.beforeUpdate(appuser, id, data);
|
|
485
500
|
|
|
486
501
|
const dbsession = appuser.getDBSession();
|
|
487
502
|
if (!dbsession.inTransaction()) {
|
|
@@ -508,7 +523,9 @@ export class SimpleAppService<T extends { _id?: string }> {
|
|
|
508
523
|
.findOneAndUpdate(isolationFilter, data)
|
|
509
524
|
.session(dbsession);
|
|
510
525
|
appuser.addUpdatedRecordId(this.documentName, data._id);
|
|
511
|
-
|
|
526
|
+
|
|
527
|
+
if (this.hooks.afterUpdate)
|
|
528
|
+
await this.hooks.afterUpdate(appuser, id, result);
|
|
512
529
|
return await this.findById(appuser, id);
|
|
513
530
|
} catch (err) {
|
|
514
531
|
throw new InternalServerErrorException(err.message);
|
|
@@ -590,17 +607,23 @@ export class SimpleAppService<T extends { _id?: string }> {
|
|
|
590
607
|
}
|
|
591
608
|
|
|
592
609
|
data['documentStatus'] = docstatus;
|
|
593
|
-
await this.hook(appuser, HookType.beforeSetStatus, data);
|
|
610
|
+
// await this.hook(appuser, HookType.beforeSetStatus, data);
|
|
611
|
+
if (this.hooks.beforeSetStatus)
|
|
612
|
+
await this.hooks.beforeSetStatus(appuser, docstatus, data);
|
|
594
613
|
if (data && !data['created']) {
|
|
595
614
|
const createresult = await this.create(appuser, data);
|
|
596
|
-
|
|
615
|
+
if (this.hooks.afterSetStatus)
|
|
616
|
+
await this.hooks.afterSetStatus(appuser, docstatus, createresult);
|
|
617
|
+
|
|
597
618
|
return createresult;
|
|
598
619
|
} else {
|
|
599
|
-
const originalresult = await this.findById(appuser,id)
|
|
600
|
-
const newdata = {...originalresult
|
|
620
|
+
const originalresult = await this.findById(appuser, id);
|
|
621
|
+
const newdata = { ...originalresult, ...data };
|
|
601
622
|
const updateresult = await this.findIdThenUpdate(appuser, id, newdata);
|
|
602
|
-
const finaldata = await this.findById(appuser,id)
|
|
603
|
-
|
|
623
|
+
const finaldata = await this.findById(appuser, id);
|
|
624
|
+
if (this.hooks.afterSetStatus)
|
|
625
|
+
await this.hooks.afterSetStatus(appuser, docstatus, finaldata);
|
|
626
|
+
|
|
604
627
|
return updateresult;
|
|
605
628
|
}
|
|
606
629
|
}
|
|
@@ -1,59 +1,7 @@
|
|
|
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 type ForeignKey = {
|
|
8
|
-
_id: string;
|
|
9
|
-
label: string;
|
|
10
|
-
};
|
|
11
|
-
export type ModifiedCollection = {
|
|
12
|
-
[key: string]: string[];
|
|
13
|
-
};
|
|
14
|
-
export type ModifiedRecords = {
|
|
15
|
-
createds: ModifiedCollection;
|
|
16
|
-
updateds: ModifiedCollection;
|
|
17
|
-
deleteds: ModifiedCollection;
|
|
18
|
-
};
|
|
19
|
-
export type DocNumberFormatResult = {
|
|
20
|
-
formatId: string;
|
|
21
|
-
formatName: string;
|
|
22
|
-
result: string;
|
|
23
|
-
};
|
|
24
1
|
|
|
25
|
-
export type SearchBody = {
|
|
26
|
-
filter?: Object;
|
|
27
2
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export enum IsolationType {
|
|
35
|
-
'none' = 'none',
|
|
36
|
-
'org' = 'org',
|
|
37
|
-
'tenant' = 'tenant',
|
|
38
|
-
'branch' = 'branch',
|
|
39
|
-
}
|
|
40
|
-
export enum HookType {
|
|
41
|
-
'init' = 'init',
|
|
42
|
-
'beforeSearch' = 'beforeSearch',
|
|
43
|
-
'afterSearch' = 'afterSearch',
|
|
44
|
-
'beforeValidation' = 'beforeValidation',
|
|
45
|
-
'afterValidation' = 'afterValidation',
|
|
46
|
-
'beforeCreate' = 'beforeCreate',
|
|
47
|
-
'afterCreate' = 'afterCreate',
|
|
48
|
-
'beforeUpdate' = 'beforeUpdate',
|
|
49
|
-
'afterUpdate' = 'afterUpdate',
|
|
50
|
-
'beforeDelete' = 'beforeDelete',
|
|
51
|
-
'afterDelete' = 'afterDelete',
|
|
52
|
-
'beforeFetchRecord' = 'beforeFetchRecord',
|
|
53
|
-
'afterFetchRecord' = 'afterFetchRecord',
|
|
54
|
-
'beforeSetStatus'='beforeSetStatus',
|
|
55
|
-
'afterSetStatus'='afterSetStatus'
|
|
56
|
-
}
|
|
57
|
-
export type MoreProjectionType = {
|
|
58
|
-
[key: string]: string;
|
|
59
|
-
};
|
|
3
|
+
<%for(let i=0; i<it.modules.length;i++){ %>
|
|
4
|
+
<% const d = it.modules[i] %>
|
|
5
|
+
export * from './<%= d['doctype']%>.type'
|
|
6
|
+
<%}%>
|
|
7
|
+
export * from './simpleapp.type'
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2024-01-25
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
7
|
+
import { UserContext } from 'src/simpleapp/generate/commons/user.context';
|
|
8
|
+
export type ForeignKey = {
|
|
9
|
+
_id: string;
|
|
10
|
+
label: string;
|
|
11
|
+
};
|
|
12
|
+
export type ModifiedCollection = {
|
|
13
|
+
[key: string]: string[];
|
|
14
|
+
};
|
|
15
|
+
export type ModifiedRecords = {
|
|
16
|
+
createds: ModifiedCollection;
|
|
17
|
+
updateds: ModifiedCollection;
|
|
18
|
+
deleteds: ModifiedCollection;
|
|
19
|
+
};
|
|
20
|
+
export type DocNumberFormatResult = {
|
|
21
|
+
formatId: string;
|
|
22
|
+
formatName: string;
|
|
23
|
+
result: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type SearchBody = {
|
|
27
|
+
filter?: Object;
|
|
28
|
+
|
|
29
|
+
fields?: any[];
|
|
30
|
+
|
|
31
|
+
sorts?: any[];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
export enum IsolationType {
|
|
36
|
+
'none' = 'none',
|
|
37
|
+
'org' = 'org',
|
|
38
|
+
'tenant' = 'tenant',
|
|
39
|
+
'branch' = 'branch',
|
|
40
|
+
}
|
|
41
|
+
export type DefaultHooks<T> = {
|
|
42
|
+
init?: () => Promise<void> ;
|
|
43
|
+
beforeSearch?: (appuser:UserContext,filter:any) => Promise<void> ;
|
|
44
|
+
afterSearch?: (appuser:UserContext,data:T[]) => Promise<void> ;
|
|
45
|
+
beforeValidation?: (appuser:UserContext,data:T) => Promise<boolean> ;
|
|
46
|
+
afterValidation?: (appuser:UserContext,data:T) => Promise<void> ;
|
|
47
|
+
beforeCreate?: (appuser:UserContext,data:T) => Promise<void> ;
|
|
48
|
+
afterCreate?: (appuser:UserContext,data:T) => Promise<void> ;
|
|
49
|
+
beforeUpdate?: (appuser:UserContext,id:string,data:T) => Promise<void> ;
|
|
50
|
+
afterUpdate?: (appuser:UserContext,id:string,data:T) => Promise<void> ;
|
|
51
|
+
beforeDelete?: (appuser:UserContext,id:string) => Promise<void> ;
|
|
52
|
+
afterDelete?: (appuser:UserContext,data:any,id:string) => Promise<void> ;
|
|
53
|
+
beforeFetchRecord?: (appuser:UserContext,id:string) => Promise<void> ;
|
|
54
|
+
afterFetchRecord?: (appuser:UserContext,data:T) => Promise<void> ;
|
|
55
|
+
beforeSetStatus?: (appuser:UserContext,id:string,data:T) => Promise<void> ;
|
|
56
|
+
afterSetStatus ?: (appuser:UserContext,id:string,data:T) => Promise<void> ;
|
|
57
|
+
};
|
|
58
|
+
export type MoreProjectionType = {
|
|
59
|
+
[key: string]: string;
|
|
60
|
+
};
|
|
61
|
+
export type ApiEvent = {
|
|
62
|
+
_id: string
|
|
63
|
+
created: string
|
|
64
|
+
updated?:string
|
|
65
|
+
duration: number
|
|
66
|
+
createdBy: string
|
|
67
|
+
path: string
|
|
68
|
+
ip: string
|
|
69
|
+
method: string
|
|
70
|
+
headers: any
|
|
71
|
+
data?: any
|
|
72
|
+
statusCode:number
|
|
73
|
+
status:string
|
|
74
|
+
errMsg?:string
|
|
75
|
+
errData?: any
|
|
76
|
+
}
|
|
@@ -9,49 +9,17 @@ import { Model } from 'mongoose';
|
|
|
9
9
|
import { Injectable } from '@nestjs/common';
|
|
10
10
|
import { AutoincreamentProcessor } from '../generate/processors/autoinc.processor';
|
|
11
11
|
|
|
12
|
-
import { Autoincreament } from '../generate/types
|
|
12
|
+
import { Autoincreament,AutoincreamentHooks } from '../generate/types';
|
|
13
13
|
import { UserContext } from '../generate/commons/user.context';
|
|
14
|
-
export { Autoincreament } from '../generate/types
|
|
14
|
+
export { Autoincreament } from '../generate/types';
|
|
15
15
|
|
|
16
16
|
@Injectable()
|
|
17
17
|
export class AutoincreamentService extends AutoincreamentProcessor {
|
|
18
|
+
hooks: AutoincreamentHooks = {};
|
|
18
19
|
constructor(@InjectModel('Autoincreament') mydoc: Model<Autoincreament>) {
|
|
19
20
|
super(mydoc);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
// hook = async (appuser:UserContext,type: string, data?: any) => {
|
|
23
|
-
// switch(type){
|
|
24
|
-
// case 'init':
|
|
25
|
-
// break;
|
|
26
|
-
// case 'beforeSearch':
|
|
27
|
-
// break;
|
|
28
|
-
// case 'afterSearch':
|
|
29
|
-
// break;
|
|
30
|
-
// case 'beforeValidation':
|
|
31
|
-
// break;
|
|
32
|
-
// case 'afterValidation':
|
|
33
|
-
// break;
|
|
34
|
-
// case 'beforeCreate':
|
|
35
|
-
// break;
|
|
36
|
-
// case 'afterCreate':
|
|
37
|
-
// break;
|
|
38
|
-
// case 'beforeUpdate':
|
|
39
|
-
// break;
|
|
40
|
-
// case 'afterUpdate':
|
|
41
|
-
// break;
|
|
42
|
-
// case 'beforeDelete':
|
|
43
|
-
// break;
|
|
44
|
-
// case 'afterDelete':
|
|
45
|
-
// break;
|
|
46
|
-
// case 'beforeFetchRecord':
|
|
47
|
-
// break;
|
|
48
|
-
// case 'afterFetchRecord':
|
|
49
|
-
// break;
|
|
50
|
-
// default:
|
|
51
|
-
// break;
|
|
52
|
-
// }
|
|
53
|
-
// return true;
|
|
54
|
-
// };
|
|
55
23
|
|
|
56
24
|
async runGenerateNextNo(
|
|
57
25
|
appuser: UserContext,
|
|
@@ -8,16 +8,22 @@ import { InjectModel } from '@nestjs/mongoose';
|
|
|
8
8
|
import { Model } from 'mongoose';
|
|
9
9
|
import { Injectable, InternalServerErrorException } from '@nestjs/common';
|
|
10
10
|
import { BranchProcessor } from '../generate/processors/branch.processor';
|
|
11
|
-
import { Branch } from '../generate/types
|
|
11
|
+
import { Branch, BranchHooks } from '../generate/types';
|
|
12
12
|
import { alldocuments } from '../generate/commons/dicts/documents';
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
import { AutoincreamentService } from './autoinc.service';
|
|
15
15
|
import { UserContext } from '../generate/commons/user.context';
|
|
16
16
|
import { Docnoformat, DocnoformatService } from './docno.service';
|
|
17
|
+
|
|
18
|
+
export { Branch } from '../generate/types';
|
|
17
19
|
// import { Docnoformat } from '../generate/types/docno.type';
|
|
18
20
|
@Injectable()
|
|
19
21
|
export class BranchService extends BranchProcessor {
|
|
20
22
|
protected strictIsolation = false;
|
|
23
|
+
protected hooks: BranchHooks = {
|
|
24
|
+
beforeCreate: async (appuser: UserContext, data: Branch) => await this.branchBeforeCreate(appuser,data),
|
|
25
|
+
afterCreate: async (appuser: UserContext, data: Branch) => await this.branchAfterCreate(appuser,data),
|
|
26
|
+
};
|
|
21
27
|
constructor(
|
|
22
28
|
@InjectModel('Branch') mydoc: Model<Branch>,
|
|
23
29
|
private increament: AutoincreamentService,
|
|
@@ -25,47 +31,17 @@ export class BranchService extends BranchProcessor {
|
|
|
25
31
|
) {
|
|
26
32
|
super(mydoc);
|
|
27
33
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// case 'afterValidation':
|
|
40
|
-
// break;
|
|
41
|
-
case 'beforeCreate':
|
|
42
|
-
const searchresult = await this.increament.runGenerateNextNo(
|
|
43
|
-
appuser,
|
|
44
|
-
'branch',
|
|
45
|
-
'branchId',
|
|
46
|
-
);
|
|
47
|
-
data.branchId = searchresult.nextno;
|
|
48
|
-
break;
|
|
49
|
-
case 'afterCreate':
|
|
50
|
-
await this.generateDefaultDocNumbers(appuser, data);
|
|
51
|
-
break;
|
|
52
|
-
// case 'beforeUpdate':
|
|
53
|
-
// break;
|
|
54
|
-
// case 'afterUpdate':
|
|
55
|
-
// break;
|
|
56
|
-
// case 'beforeDelete':
|
|
57
|
-
// break;
|
|
58
|
-
// case 'afterDelete':
|
|
59
|
-
// break;
|
|
60
|
-
// case 'beforeFetchRecord':
|
|
61
|
-
// break;
|
|
62
|
-
// case 'afterFetchRecord':
|
|
63
|
-
// break;
|
|
64
|
-
// default:
|
|
65
|
-
// break;
|
|
66
|
-
}
|
|
67
|
-
return true;
|
|
68
|
-
};
|
|
34
|
+
async branchBeforeCreate(appuser: UserContext, data: Branch) {
|
|
35
|
+
const searchresult = await this.increament.runGenerateNextNo(
|
|
36
|
+
appuser,
|
|
37
|
+
'branch',
|
|
38
|
+
'branchId',
|
|
39
|
+
);
|
|
40
|
+
data.branchId = searchresult.nextno;
|
|
41
|
+
}
|
|
42
|
+
async branchAfterCreate(appuser: UserContext, data: Branch) {
|
|
43
|
+
await this.generateDefaultDocNumbers(appuser, data);
|
|
44
|
+
}
|
|
69
45
|
|
|
70
46
|
generateDefaultDocNumbers = async (appuser, data) => {
|
|
71
47
|
const branchName = data.branchName;
|
|
@@ -8,55 +8,22 @@ import { InjectModel } from '@nestjs/mongoose';
|
|
|
8
8
|
import { Model } from 'mongoose';
|
|
9
9
|
import { Injectable, InternalServerErrorException } from '@nestjs/common';
|
|
10
10
|
import { DocnoformatProcessor } from '../generate/processors/docno.processor';
|
|
11
|
-
import { Docnoformat } from '../generate/types
|
|
11
|
+
import { Docnoformat,DocnoformatHooks } from '../generate/types';
|
|
12
12
|
import { UserContext } from '../generate/commons/user.context';
|
|
13
13
|
import * as moment from 'moment';
|
|
14
14
|
import { DocNumberFormatGenerator } from '../generate/commons/docnogenerator.service';
|
|
15
|
-
export { Docnoformat } from '../generate/types
|
|
15
|
+
export { Docnoformat } from '../generate/types';
|
|
16
16
|
|
|
17
17
|
@Injectable()
|
|
18
18
|
export class DocnoformatService extends DocnoformatProcessor {
|
|
19
19
|
protected strictIsolation = false;
|
|
20
|
+
hooks: DocnoformatHooks = {};
|
|
20
21
|
constructor(
|
|
21
22
|
@InjectModel('Docnoformat') mydoc: Model<Docnoformat>,
|
|
22
23
|
) {
|
|
23
24
|
super(mydoc);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
// hook = async (type: string, data?: any) => {
|
|
27
|
-
// switch(type){
|
|
28
|
-
// case 'init':
|
|
29
|
-
// break;
|
|
30
|
-
// case 'beforeSearch':
|
|
31
|
-
// break;
|
|
32
|
-
// case 'afterSearch':
|
|
33
|
-
// break;
|
|
34
|
-
// case 'beforeValidation':
|
|
35
|
-
// break;
|
|
36
|
-
// case 'afterValidation':
|
|
37
|
-
// break;
|
|
38
|
-
// case 'beforeCreate':
|
|
39
|
-
// break;
|
|
40
|
-
// case 'afterCreate':
|
|
41
|
-
// break;
|
|
42
|
-
// case 'beforeUpdate':
|
|
43
|
-
// break;
|
|
44
|
-
// case 'afterUpdate':
|
|
45
|
-
// break;
|
|
46
|
-
// case 'beforeDelete':
|
|
47
|
-
// break;
|
|
48
|
-
// case 'afterDelete':
|
|
49
|
-
// break;
|
|
50
|
-
// case 'beforeFetchRecord':
|
|
51
|
-
// break;
|
|
52
|
-
// case 'afterFetchRecord':
|
|
53
|
-
// break;
|
|
54
|
-
// default:
|
|
55
|
-
// break;
|
|
56
|
-
// }
|
|
57
|
-
// return true;
|
|
58
|
-
// };
|
|
59
|
-
|
|
60
27
|
/**
|
|
61
28
|
* list document number format and prepare sample of docformat
|
|
62
29
|
* @param appuser
|