@simitgroup/simpleapp-generator 2.0.0-a-alpha → 2.0.0-b-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ReleaseNote.md +5 -0
- package/package.json +1 -1
- package/templates/basic/nest/controller.ts.eta +14 -1
- package/templates/basic/nest/module.ts.eta +3 -2
- package/templates/basic/nest/service.ts.eta +6 -2
- package/templates/nest/src/simple-app/.core/features/log/log.module.ts.eta +3 -3
- package/templates/nest/src/simple-app/.core/features/simple-app-core-features.module.ts.eta +3 -3
- package/templates/nest/src/simple-app/.core/features/webhook/run-webhook.service.ts.eta +13 -6
- package/templates/nest/src/simple-app/.core/features/webhook/schemas/webhook.schema.ts.eta +13 -13
- package/templates/nest/src/simple-app/.core/features/webhook/webhook.module.ts.eta +4 -3
- package/templates/nest/src/simple-app/.core/framework/base/simple-app.controller.ts.eta +8 -1
- package/templates/nest/src/simple-app/.core/framework/base/simple-app.service.ts.eta +10 -22
package/ReleaseNote.md
CHANGED
package/package.json
CHANGED
|
@@ -172,6 +172,18 @@ export class <%= it.typename %>Controller extends SimpleAppController<
|
|
|
172
172
|
<%}%>
|
|
173
173
|
|
|
174
174
|
|
|
175
|
+
@Patch('bulk-patch')
|
|
176
|
+
@ApiResponse({ status: 200, description: 'success',})
|
|
177
|
+
@Roles(Role.SuperAdmin, Role.SuperUser, Role.<%= it.typename%>_update)
|
|
178
|
+
@ApiResponse({ status: 404, description: 'Document not found' })
|
|
179
|
+
@ApiResponse({ status: 500, description: 'Internal error' })
|
|
180
|
+
@ApiBody({ description: 'Data', type: schemas.PatchManyRequest<schemas.<%= it.typename%>> })
|
|
181
|
+
@ApiOperation({ operationId: 'runPatchMany' })
|
|
182
|
+
<%~ drawMiniAppScope('patch-many') %>
|
|
183
|
+
async patchMany(@AppUser() appuser: UserContext, @Param('id') id: string, @Body() patchManyData: schemas.PatchManyRequest<schemas.<%= it.typename%>>) {
|
|
184
|
+
return await this._patchMany(appuser, id, patchManyData);
|
|
185
|
+
}
|
|
186
|
+
|
|
175
187
|
|
|
176
188
|
/***************************** start status control api definitions *****************************************/
|
|
177
189
|
<%for(let s=0; s<it.docStatusSettings.length; s++){ %>
|
|
@@ -286,6 +298,7 @@ export class <%= it.typename %>Controller extends SimpleAppController<
|
|
|
286
298
|
return data;
|
|
287
299
|
}
|
|
288
300
|
}
|
|
289
|
-
|
|
290
301
|
<%}%>
|
|
302
|
+
|
|
303
|
+
|
|
291
304
|
}
|
|
@@ -12,9 +12,10 @@ import { <%= it.typename%>MongoSchema } from './<%= camelToKebab(it.resourceName
|
|
|
12
12
|
import { <%= it.typename%>Resolver } from './<%= camelToKebab(it.resourceName)%>.resolver';
|
|
13
13
|
|
|
14
14
|
import { DocumentNoFormatModule} from 'src/simple-app/.core/features/document-no-format/document-no-format.module';
|
|
15
|
-
|
|
15
|
+
import { SimpleAppLogModule } from 'src/simple-app/.core/features/log/log.module';
|
|
16
|
+
import { SimpleAppWebhookModule } from 'src/simple-app/.core/features/webhook/webhook.module';
|
|
16
17
|
@Module({
|
|
17
|
-
imports: [ DocumentNoFormatModule,
|
|
18
|
+
imports: [ DocumentNoFormatModule,SimpleAppLogModule,SimpleAppWebhookModule,
|
|
18
19
|
MongooseModule.forFeature([
|
|
19
20
|
{ name: '<%= it.typename%>', schema: <%= it.typename%>MongoSchema },
|
|
20
21
|
])],
|
|
@@ -21,6 +21,8 @@ import { DocumentNoFormatService } from 'src/simple-app/.core/features/document-
|
|
|
21
21
|
|
|
22
22
|
import * as defaultValue from './<%= camelToKebab(it.resourceName) %>.default'
|
|
23
23
|
import * as schema from './<%= camelToKebab(it.resourceName) %>.schema';
|
|
24
|
+
import { SimpleAppLogService } from 'src/simple-app/.core/features/log/log.service';
|
|
25
|
+
import { RunWebhookService } from 'src/simple-app/.core/features/webhook/run-webhook.service';
|
|
24
26
|
//export * from './<%= camelToKebab(it.resourceName) %>.schema';
|
|
25
27
|
|
|
26
28
|
|
|
@@ -47,9 +49,11 @@ export class <%= it.typename %>Service extends SimpleAppService<schema.<%= it.ty
|
|
|
47
49
|
constructor(
|
|
48
50
|
@InjectModel('<%= it.typename %>') mydoc: Model<schema.<%= it.typename %>>,
|
|
49
51
|
@Inject(forwardRef(() => EventEmitter2)) event2:EventEmitter2,
|
|
50
|
-
docNoGen:DocumentNoFormatService
|
|
52
|
+
docNoGen:DocumentNoFormatService,
|
|
53
|
+
logSvc: SimpleAppLogService,
|
|
54
|
+
webhookSvc:RunWebhookService
|
|
51
55
|
) {
|
|
52
|
-
super('<%= it.doctype.toUpperCase() %>','<%= it.name %>',mydoc,IsolationType.<%=it.isolationtype%>,event2,docNoGen);
|
|
56
|
+
super('<%= it.doctype.toUpperCase() %>','<%= it.name %>',mydoc,IsolationType.<%=it.isolationtype%>,event2,docNoGen,logSvc,webhookSvc);
|
|
53
57
|
this.setSchema(<%= it.typename%>JsonSchema)
|
|
54
58
|
this.setData(defaultValue.Default<%=it.typename%>(crypto.randomUUID()))
|
|
55
59
|
<%if(it.moreAutoComplete.length>0){%>
|
|
@@ -7,14 +7,14 @@
|
|
|
7
7
|
import { Module } from '@nestjs/common';
|
|
8
8
|
import { MongooseModule } from '@nestjs/mongoose';
|
|
9
9
|
import { ApiEventMongoSchema,DocumentEventMongoSchema } from './schemas';
|
|
10
|
-
|
|
10
|
+
import {SimpleAppLogService} from './log.service'
|
|
11
11
|
@Module({
|
|
12
12
|
imports: [MongooseModule.forFeature([
|
|
13
13
|
{ name: 'ApiEvent', schema: ApiEventMongoSchema },
|
|
14
14
|
{ name: 'DocumentEvent', schema: DocumentEventMongoSchema }
|
|
15
15
|
])],
|
|
16
16
|
controllers: [],
|
|
17
|
-
providers: [],
|
|
18
|
-
exports: [MongooseModule],
|
|
17
|
+
providers: [SimpleAppLogService],
|
|
18
|
+
exports: [MongooseModule,SimpleAppLogService],
|
|
19
19
|
})
|
|
20
20
|
export class SimpleAppLogModule {}
|
|
@@ -16,7 +16,7 @@ import { SimpleAppSoftwarePolicyModule } from './policy/policy.module';
|
|
|
16
16
|
import { SimpleAppMiniAppModule } from './mini-app/mini-app.module';
|
|
17
17
|
import { ProfileModule } from './profile/profile.module';
|
|
18
18
|
import { SimpleAppUserContextModule } from './user-context/user-context.module';
|
|
19
|
-
import {
|
|
19
|
+
import { SimpleAppWebhookModule } from './webhook/webhook.module';
|
|
20
20
|
import { AutoIncreamentModule } from './auto-increament/auto-increament.module';
|
|
21
21
|
@Module({
|
|
22
22
|
imports: [
|
|
@@ -28,7 +28,7 @@ import { AutoIncreamentModule } from './auto-increament/auto-increament.module';
|
|
|
28
28
|
MaintenanceModule,
|
|
29
29
|
ProfileModule,
|
|
30
30
|
SimpleAppUserContextModule,
|
|
31
|
-
|
|
31
|
+
SimpleAppWebhookModule,
|
|
32
32
|
SimpleAppMiniAppModule,
|
|
33
33
|
SimpleAppSoftwarePolicyModule,
|
|
34
34
|
],
|
|
@@ -43,7 +43,7 @@ import { AutoIncreamentModule } from './auto-increament/auto-increament.module';
|
|
|
43
43
|
MaintenanceModule,
|
|
44
44
|
ProfileModule,
|
|
45
45
|
SimpleAppUserContextModule,
|
|
46
|
-
|
|
46
|
+
SimpleAppWebhookModule,
|
|
47
47
|
SimpleAppMiniAppModule,
|
|
48
48
|
SimpleAppSoftwarePolicyModule,
|
|
49
49
|
],
|
|
@@ -8,24 +8,31 @@ import { alldocuments } from '../document-no-format/document.dict';
|
|
|
8
8
|
export class RunWebhookService {
|
|
9
9
|
@Inject(EventEmitter2)
|
|
10
10
|
protected eventEmitter: EventEmitter2;
|
|
11
|
-
|
|
11
|
+
protected systemWebhooks : Webhook[] = []
|
|
12
12
|
protected logger = new Logger();
|
|
13
13
|
protected maxRetries = 5;
|
|
14
14
|
public constructor() {}
|
|
15
|
+
public addWebhook = (wh:Webhook)=> this.systemWebhooks.push(wh)
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* trigger
|
|
18
19
|
*/
|
|
19
20
|
async run(appuser: UserContext, documentName: string, actionName: string, data: any) {
|
|
20
|
-
if (process.env.WEBHOOK_ONOFF && process.env.WEBHOOK_ONOFF.toLowerCase() == 'on')
|
|
21
|
-
|
|
21
|
+
if (process.env.WEBHOOK_ONOFF && process.env.WEBHOOK_ONOFF.toLowerCase() == 'on') {
|
|
22
|
+
return await this.runRealtimeWebhook(appuser, documentName, actionName, data);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.logger.warn(`Webhook off, not run for ${documentName}:${actionName}`);
|
|
26
|
+
}
|
|
22
27
|
}
|
|
23
28
|
|
|
24
|
-
async
|
|
29
|
+
async runRealtimeWebhook(appuser: UserContext, documentName: string, actionName: string, data: any) {
|
|
25
30
|
this.logger.debug(`Run webhook ${documentName}, ${actionName}`);
|
|
26
31
|
|
|
27
|
-
const
|
|
28
|
-
|
|
32
|
+
const userWebhooks = appuser.getWebHooks().filter((wh) => wh.resourceName == documentName && wh.eventType == actionName && wh.active);
|
|
33
|
+
const systemWebhooks = this.systemWebhooks.filter((wh) => wh.resourceName == documentName && wh.eventType == actionName && wh.active);
|
|
34
|
+
const webhooks = []
|
|
35
|
+
webhooks.concat(userWebhooks).concat(systemWebhooks)
|
|
29
36
|
|
|
30
37
|
const systemVars = {
|
|
31
38
|
$xOrg: appuser.getXOrg(),
|
|
@@ -10,7 +10,7 @@ import GraphQLJSON, { GraphQLJSONObject } from 'graphql-type-json';
|
|
|
10
10
|
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
|
11
11
|
|
|
12
12
|
@ObjectType()
|
|
13
|
-
@Schema({collection:'webhook'})
|
|
13
|
+
@Schema({ collection: 'webhook' })
|
|
14
14
|
export class WebhookBasicAuth {
|
|
15
15
|
@Prop()
|
|
16
16
|
@Field()
|
|
@@ -61,35 +61,35 @@ export class Webhook {
|
|
|
61
61
|
@Prop()
|
|
62
62
|
@Field()
|
|
63
63
|
@ApiProperty({ type: 'string', required: false, format: 'uuid', default: '' })
|
|
64
|
-
_id
|
|
64
|
+
_id?: string;
|
|
65
65
|
@Prop()
|
|
66
66
|
@Field()
|
|
67
67
|
@ApiProperty({ type: 'string', required: false, default: '' })
|
|
68
|
-
created
|
|
68
|
+
created?: string;
|
|
69
69
|
@Prop()
|
|
70
70
|
@Field()
|
|
71
71
|
@ApiProperty({ type: 'string', required: false, default: '' })
|
|
72
|
-
updated
|
|
72
|
+
updated?: string;
|
|
73
73
|
@Prop()
|
|
74
74
|
@Field()
|
|
75
75
|
@ApiProperty({ type: 'string', required: false, default: '' })
|
|
76
|
-
createdBy
|
|
76
|
+
createdBy?: string;
|
|
77
77
|
@Prop()
|
|
78
78
|
@Field()
|
|
79
79
|
@ApiProperty({ type: 'string', required: false, default: '' })
|
|
80
|
-
updatedBy
|
|
80
|
+
updatedBy?: string;
|
|
81
81
|
@Prop()
|
|
82
82
|
@Field()
|
|
83
83
|
@ApiProperty({ type: 'number', required: false, default: 1 })
|
|
84
|
-
tenantId
|
|
84
|
+
tenantId?: number;
|
|
85
85
|
@Prop()
|
|
86
86
|
@Field()
|
|
87
87
|
@ApiProperty({ type: 'number', required: false, default: 1 })
|
|
88
|
-
orgId
|
|
88
|
+
orgId?: number;
|
|
89
89
|
@Prop()
|
|
90
90
|
@Field()
|
|
91
91
|
@ApiProperty({ type: 'number', required: false, default: 1 })
|
|
92
|
-
branchId
|
|
92
|
+
branchId?: number;
|
|
93
93
|
@Prop()
|
|
94
94
|
@Field()
|
|
95
95
|
@ApiProperty({ type: 'string', required: true, default: '' })
|
|
@@ -105,11 +105,11 @@ export class Webhook {
|
|
|
105
105
|
@Prop()
|
|
106
106
|
@Field()
|
|
107
107
|
@ApiProperty({ type: 'string', required: false, description: 'apikey authentication use none + headers props', default: '' })
|
|
108
|
-
authentication
|
|
108
|
+
authentication?: string;
|
|
109
109
|
@Prop()
|
|
110
110
|
@Field()
|
|
111
111
|
@ApiProperty({ type: 'string', required: false, format: 'text', default: '' })
|
|
112
|
-
description
|
|
112
|
+
description?: string;
|
|
113
113
|
@Prop()
|
|
114
114
|
@Field()
|
|
115
115
|
@ApiProperty({ type: 'string', required: false, description: 'POST,PUT body template', format: 'text', default: '*' })
|
|
@@ -136,11 +136,11 @@ export class Webhook {
|
|
|
136
136
|
retryAttemps: number;
|
|
137
137
|
@Field()
|
|
138
138
|
@ApiProperty({ type: () => WebhookBasicAuth, required: false })
|
|
139
|
-
basicAuth
|
|
139
|
+
basicAuth?: WebhookBasicAuth;
|
|
140
140
|
@Prop()
|
|
141
141
|
@Field(() => [WebhookHeaders])
|
|
142
142
|
@ApiProperty({ type: () => [WebhookHeaders], required: false })
|
|
143
|
-
headers
|
|
143
|
+
headers?: WebhookHeaders[];
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
/***************************************** Start Auto Complete *****************************************/
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { Module } from '@nestjs/common';
|
|
8
8
|
import { MongooseModule } from '@nestjs/mongoose';
|
|
9
9
|
import { WebhookMongoSchema,WebhookLogMongoSchema } from './schemas';
|
|
10
|
+
import { RunWebhookService } from './run-webhook.service';
|
|
10
11
|
@Module({
|
|
11
12
|
imports: [ MongooseModule.forFeature([
|
|
12
13
|
{ name: 'Webhook', schema: WebhookMongoSchema },
|
|
@@ -14,7 +15,7 @@ import { WebhookMongoSchema,WebhookLogMongoSchema } from './schemas';
|
|
|
14
15
|
])
|
|
15
16
|
],
|
|
16
17
|
controllers: [],
|
|
17
|
-
providers: [],
|
|
18
|
-
exports: [MongooseModule],
|
|
18
|
+
providers: [RunWebhookService],
|
|
19
|
+
exports: [MongooseModule,RunWebhookService],
|
|
19
20
|
})
|
|
20
|
-
export class
|
|
21
|
+
export class SimpleAppWebhookModule {}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { Controller, Get, Put, Post, Delete, Body, Param, Type } from '@nestjs/common';
|
|
8
8
|
// import { ApiTags, ApiBody, ApiResponse, ApiOperation } from '@nestjs/swagger';
|
|
9
9
|
import { UserContext } from '../../features/user-context/user.context';
|
|
10
|
-
import { SearchBody, TextSearchBody } from '../schemas';
|
|
10
|
+
import { SearchBody, TextSearchBody,PatchManyRequest } from '../schemas';
|
|
11
11
|
const doctype = 'person'.toUpperCase();
|
|
12
12
|
type ServiceType = {
|
|
13
13
|
list: Function;
|
|
@@ -74,4 +74,11 @@ export class SimpleAppController<TService extends ServiceType, TApiSchema> {
|
|
|
74
74
|
async _delete(appuser: UserContext, id: string) {
|
|
75
75
|
return this.service.findIdThenDelete(appuser, id);
|
|
76
76
|
}
|
|
77
|
+
async _patchMany(appuser: UserContext, id: string, patchManyData: PatchManyRequest<TApiSchema>) {
|
|
78
|
+
return this.service.findIdThenPatch(appuser, id, patchManyData) as TApiSchema;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async _deleteMany(appuser: UserContext, data: SearchBody) {
|
|
82
|
+
return this.service.findIdThenDelete(appuser, data);
|
|
83
|
+
}
|
|
77
84
|
}
|
|
@@ -23,6 +23,7 @@ import { DocumentNoFormatService } from '../../features/document-no-format/docum
|
|
|
23
23
|
import { UserContext } from '../../features/user-context/user.context';
|
|
24
24
|
import { RunWebhookService } from '../../features/webhook/run-webhook.service';
|
|
25
25
|
import { UniqueKeyExistResponse, DeleteResultType, IsolationType, MoreProjectionType, SchemaFields, TextSearchBody, PatchManyRequest } from '../schemas';
|
|
26
|
+
import { SimpleAppLogService } from '../../features/log/log.service';
|
|
26
27
|
|
|
27
28
|
@Injectable()
|
|
28
29
|
export class SimpleAppService<T extends SchemaFields> {
|
|
@@ -61,10 +62,10 @@ export class SimpleAppService<T extends SchemaFields> {
|
|
|
61
62
|
protected withDocNumberFormat = false;
|
|
62
63
|
protected foreignkeys = {};
|
|
63
64
|
private eventEmitter: EventEmitter2;
|
|
64
|
-
|
|
65
|
+
private logSvc:SimpleAppLogService;
|
|
65
66
|
// protected userprovider = new UserContext() ;
|
|
66
67
|
|
|
67
|
-
constructor(doctype: string, docname: string, newdoc: Model<T>, isolationtype: IsolationType = IsolationType.org, eventEmitter: EventEmitter2, docnogenerator: DocumentNoFormatService) {
|
|
68
|
+
constructor(doctype: string, docname: string, newdoc: Model<T>, isolationtype: IsolationType = IsolationType.org, eventEmitter: EventEmitter2, docnogenerator: DocumentNoFormatService,logSvc: SimpleAppLogService,runWebHook: RunWebhookService) {
|
|
68
69
|
// console.log("-------init simpleapp service abstract class -------userprovider=",typeof this.userprovider)
|
|
69
70
|
this.eventEmitter = eventEmitter;
|
|
70
71
|
this.documentType = doctype.toUpperCase();
|
|
@@ -72,7 +73,8 @@ export class SimpleAppService<T extends SchemaFields> {
|
|
|
72
73
|
this.doc = newdoc;
|
|
73
74
|
this.docnogenerator = docnogenerator;
|
|
74
75
|
this.isolationtype = isolationtype;
|
|
75
|
-
|
|
76
|
+
this.logSvc = logSvc
|
|
77
|
+
this.runWebHook = runWebHook
|
|
76
78
|
// this.tenantdoc = tenantdoc
|
|
77
79
|
}
|
|
78
80
|
getDocumentType = () => this.documentType;
|
|
@@ -1274,30 +1276,16 @@ export class SimpleAppService<T extends SchemaFields> {
|
|
|
1274
1276
|
//only realtime webhook supported at this moment
|
|
1275
1277
|
async callWebhook(appuser: UserContext, actionName: string, data: any) {
|
|
1276
1278
|
try {
|
|
1277
|
-
|
|
1278
|
-
// await this.runEvent(appuser, 'webhook.run', {
|
|
1279
|
-
// documentName: this.documentName,
|
|
1280
|
-
// actionName: actionName,
|
|
1281
|
-
// data: data,
|
|
1282
|
-
// });
|
|
1279
|
+
await this.runWebHook.run(appuser, this.documentName, actionName, data);
|
|
1283
1280
|
} catch (e) {
|
|
1284
1281
|
throw new InternalServerErrorException(e);
|
|
1285
1282
|
}
|
|
1286
1283
|
}
|
|
1287
1284
|
|
|
1288
|
-
async addAuditEvent(
|
|
1289
|
-
|
|
1290
|
-
// documentName: documentName,
|
|
1291
|
-
// id: id,
|
|
1292
|
-
// eventType: eventType,
|
|
1293
|
-
// data: data,
|
|
1294
|
-
// });
|
|
1285
|
+
async addAuditEvent(appUser: UserContext, documentName: string, id: string, eventType: string, data: any) {
|
|
1286
|
+
await this.logSvc.addEvent(appUser,documentName,id,eventType,data)
|
|
1295
1287
|
}
|
|
1296
|
-
async addManyAuditEvents(
|
|
1297
|
-
|
|
1298
|
-
// documentName: documentName,
|
|
1299
|
-
// eventType: eventType,
|
|
1300
|
-
// datas: datas,
|
|
1301
|
-
// });
|
|
1288
|
+
async addManyAuditEvents(appUser: UserContext, documentName: string, eventType: string, datas: any) {
|
|
1289
|
+
await this.logSvc.addManyEvents(appUser,documentName,eventType,datas)
|
|
1302
1290
|
}
|
|
1303
1291
|
}
|