@simitgroup/simpleapp-generator 2.0.0-a-alpha → 2.0.0-c-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 CHANGED
@@ -1,3 +1,11 @@
1
+ [2.0.0c-alpha]
2
+ 1. fix profile session keeping error
3
+
4
+ [2.0.0b-alpha]
5
+ 1. fix audit trail
6
+ 2. add patch many api
7
+ 3. fix webhook
8
+
1
9
  [2.0.0a-alpha]
2
10
  1. big restructure of files and folders
3
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simitgroup/simpleapp-generator",
3
- "version": "2.0.0a-alpha",
3
+ "version": "2.0.0c-alpha",
4
4
  "description": "frontend nuxtjs and backend nests code generator using jsonschema",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -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 {}
@@ -43,26 +43,26 @@ export class ProfileController {
43
43
  }
44
44
  }
45
45
 
46
- // @Get('session')
47
- // @Roles(Role.Everyone, Role.User)
48
- // @ApiOperation({
49
- // operationId: 'getSession',
50
- // description: 'Get current user session',
51
- // })
52
- // @ApiResponse({
53
- // status: 200,
54
- // type: () => String,
55
- // description: 'Success',
56
- // })
57
- // @ApiResponse({ status: 401, type: Object, description: 'Expired' })
58
- // async getSession(@AppUser() appuser: UserContext) {
59
- // const result = await this.profileservice.getSession(appuser);
60
- // if (result) {
61
- // return result;
62
- // } else {
63
- // throw new HttpException('Forbidden', HttpStatus.FORBIDDEN);
64
- // }
65
- // }
46
+ @Get('session')
47
+ @Roles(Role.Everyone, Role.User)
48
+ @ApiOperation({
49
+ operationId: 'getSession',
50
+ description: 'Get current user session',
51
+ })
52
+ @ApiResponse({
53
+ status: 200,
54
+ type: () => String,
55
+ description: 'Success',
56
+ })
57
+ @ApiResponse({ status: 401, type: Object, description: 'Expired' })
58
+ async getSession(@AppUser() appuser: UserContext) {
59
+ const result = await this.profileservice.getSession(appuser);
60
+ if (result) {
61
+ return result;
62
+ } else {
63
+ throw new HttpException('Forbidden', HttpStatus.FORBIDDEN);
64
+ }
65
+ }
66
66
 
67
67
  @Get('/tenants')
68
68
  @Roles(Role.Everyone, Role.User)
@@ -90,7 +90,7 @@ export class ProfileController {
90
90
 
91
91
  @Post('/tenant')
92
92
  @Roles(Role.Everyone)
93
- @ApiBody({ description: 'create tenant name', type: RegTenant})
93
+ @ApiBody({ description: 'create tenant name', type: RegTenant })
94
94
  @ApiOperation({
95
95
  operationId: 'createTenant',
96
96
  description: 'create new tenant',
@@ -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 { SimpleWebhookModule } from './webhook/webhook.module';
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
- SimpleWebhookModule,
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
- SimpleWebhookModule,
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') return await this.runRealtimeWebHook(appuser, documentName, actionName, data);
21
- else this.logger.warn(`Webhook off, not run for ${documentName}:${actionName}`);
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 runRealtimeWebHook(appuser: UserContext, documentName: string, actionName: string, data: any) {
29
+ async runRealtimeWebhook(appuser: UserContext, documentName: string, actionName: string, data: any) {
25
30
  this.logger.debug(`Run webhook ${documentName}, ${actionName}`);
26
31
 
27
- const webhooks = appuser.getWebHooks().filter((wh) => wh.resourceName == documentName && wh.eventType == actionName);
28
- // console.log(webhooks);
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: string;
64
+ _id?: string;
65
65
  @Prop()
66
66
  @Field()
67
67
  @ApiProperty({ type: 'string', required: false, default: '' })
68
- created: string;
68
+ created?: string;
69
69
  @Prop()
70
70
  @Field()
71
71
  @ApiProperty({ type: 'string', required: false, default: '' })
72
- updated: string;
72
+ updated?: string;
73
73
  @Prop()
74
74
  @Field()
75
75
  @ApiProperty({ type: 'string', required: false, default: '' })
76
- createdBy: string;
76
+ createdBy?: string;
77
77
  @Prop()
78
78
  @Field()
79
79
  @ApiProperty({ type: 'string', required: false, default: '' })
80
- updatedBy: string;
80
+ updatedBy?: string;
81
81
  @Prop()
82
82
  @Field()
83
83
  @ApiProperty({ type: 'number', required: false, default: 1 })
84
- tenantId: number;
84
+ tenantId?: number;
85
85
  @Prop()
86
86
  @Field()
87
87
  @ApiProperty({ type: 'number', required: false, default: 1 })
88
- orgId: number;
88
+ orgId?: number;
89
89
  @Prop()
90
90
  @Field()
91
91
  @ApiProperty({ type: 'number', required: false, default: 1 })
92
- branchId: number;
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: string;
108
+ authentication?: string;
109
109
  @Prop()
110
110
  @Field()
111
111
  @ApiProperty({ type: 'string', required: false, format: 'text', default: '' })
112
- description: string;
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: WebhookBasicAuth;
139
+ basicAuth?: WebhookBasicAuth;
140
140
  @Prop()
141
141
  @Field(() => [WebhookHeaders])
142
142
  @ApiProperty({ type: () => [WebhookHeaders], required: false })
143
- headers: WebhookHeaders[];
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 SimpleWebhookModule {}
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
- // await this.runWebHook.run(appuser, this.documentName, actionName, data);
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(appuser: UserContext, documentName: string, id: string, eventType: string, data: any) {
1289
- // await this.runEvent(appuser, 'audittrail.add', {
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(appuser: UserContext, documentName: string, eventType: string, datas: any) {
1297
- // await this.runEvent(appuser, 'audittrail.add', {
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
  }