@simitgroup/simpleapp-generator 2.0.2-h-alpha → 2.0.2-i-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,4 +1,9 @@
1
- [2.0.2h-alpha]
1
+ [2.0.2i-alpha]
2
+
3
+ 1. fix bugs cannot run backend
4
+ 2. fix default search page size to 500
5
+
6
+ [2.0.2i-alpha]
2
7
 
3
8
  1. added error handling event for create,update,delete,setStatus
4
9
  2. improve saga document number generator check max 10 number ahead base on target document's unique key (with data isolation)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simitgroup/simpleapp-generator",
3
- "version": "2.0.2h-alpha",
3
+ "version": "2.0.2i-alpha",
4
4
  "description": "frontend nuxtjs and backend nests code generator using jsonschema",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -81,7 +81,7 @@ export class MiniApp<%= pascalName %>BridgeService {
81
81
  <% if(action === 'list') { %>
82
82
  protected async handleList(message: MiniAppBridgeMessageApi<<%= typeActionName %>>) {
83
83
  const rawBody: any = message.params.body ?? {};
84
- const pageSize = rawBody.pagination?.pageSize ?? 200;
84
+ const pageSize = rawBody.pagination?.pageSize ?? 500;
85
85
  const pageNo = rawBody.pagination?.pageNo ?? 0;
86
86
  const res = await this.api!.runSearch({
87
87
  filter: rawBody.filters,
@@ -17,7 +17,8 @@ export const alldocuments:DocumentDictEntry[] = [
17
17
  documentDate:'<%=conf['documentDate']??""%>',
18
18
  docNumber:<%=conf['generateDocumentNumber']??false%>,
19
19
  docNoPattern: '<%=conf['docNoPattern']%>',
20
- webhook:<%~ JSON.stringify(conf['webhook'])%>
20
+ webhook:<%~ JSON.stringify(conf['webhook'])%>,
21
+ uniqueKey: '<%~ conf['uniqueKey'] ?? '' %>'
21
22
  },
22
23
  <%}%>
23
24
  ]
@@ -151,7 +151,8 @@ export class UserContext extends UserContextInfo {
151
151
  };
152
152
 
153
153
  getDBSession = (): ClientSession => this.dbsession;
154
- getTransStep = () => this.transSteps
154
+ getTransSteps = () => this.transSteps;
155
+ setTransSteps = (steps: StepData[]) => this.transSteps = steps;
155
156
  getId = () => this._id;
156
157
 
157
158
  getUid = () => this.uid;
@@ -8,94 +8,87 @@
8
8
  import { BadRequestException, Injectable, Logger, NestMiddleware, ServiceUnavailableException } from '@nestjs/common';
9
9
  import { InjectConnection, InjectModel } from '@nestjs/mongoose';
10
10
  import { NextFunction, Request, Response } from 'express';
11
- import { Model,Connection, ObjectId } from 'mongoose';
11
+ import { Model, Connection, ObjectId } from 'mongoose';
12
12
  import { UserContext } from '../features/user-context/user.context';
13
13
  import { StepData } from './schemas';
14
14
  @Injectable()
15
- export class SimpleAppDbRevertService{
16
-
15
+ export class SimpleAppDbRevertService {
17
16
  private readonly logger = new Logger(this.constructor.name);
18
17
 
19
- constructor(
20
- @InjectConnection() private readonly connection: Connection,
21
- ) {}
22
-
18
+ constructor(@InjectConnection() private readonly connection: Connection) {}
23
19
 
24
- async revertSteps(transSteps:StepData[]){
25
-
26
- console.log("revert transSteps:",transSteps.length)
27
- for(let i = transSteps.length-1; i>=0; i-- ){
28
- const step = transSteps[i]
29
- console.log("step",step)
30
- switch(step.action){
20
+ async revertSteps(transSteps: StepData[]) {
21
+ this.logger.debug('revert transSteps:'+transSteps.length);
22
+ for (let i = transSteps.length - 1; i >= 0; i--) {
23
+ const step = transSteps[i];
24
+ this.logger.verbose(step, `step ${i} ${step.action}`);
25
+ // console.log("-------------------------")
26
+ switch (step.action) {
31
27
  case 'create':
32
- await this.revertCreate(step)
33
- break;
28
+ await this.revertCreate(step);
29
+ break;
34
30
  case 'update':
35
- await this.revertUpdate(step)
36
- break;
31
+ await this.revertUpdate(step);
32
+ break;
37
33
  case 'patch':
38
- await this.revertUpdate(step)
39
- break;
34
+ await this.revertUpdate(step);
35
+ break;
40
36
  case 'delete':
41
- await this.revertDelete(step)
42
- break;
37
+ await this.revertDelete(step);
38
+ break;
43
39
  case 'createMany':
44
- await this.revertCreateMany(step)
45
- break;
40
+ await this.revertCreateMany(step);
41
+ break;
46
42
  case 'updateMany':
47
- await this.revertUpdateMany(step)
48
- break;
43
+ await this.revertUpdateMany(step);
44
+ break;
49
45
  case 'patchMany':
50
- await this.revertUpdateMany(step)
51
- break;
46
+ await this.revertUpdateMany(step);
47
+ break;
52
48
  case 'deleteMany':
53
- await this.revertDeleteMany(step)
54
- break;
49
+ await this.revertDeleteMany(step);
50
+ break;
55
51
  default:
56
- break;
52
+ break;
57
53
  }
58
54
  }
59
55
  }
60
56
 
61
- async revertCreate(step:StepData){
62
- const collection = this.connection.db.collection(step.collection)
63
- await collection.deleteOne({_id:<any>step.id[0]})
64
- console.log("revert create",step.collection,step.id)
65
- }
66
- async revertUpdate(step:StepData){
67
- const collection = this.connection.db.collection(step.collection)
68
- await collection.updateOne({_id:<any>step.id[0]},step.data[0])
69
- console.log("revert update",step.collection,step.id)
57
+ async revertCreate(step: StepData) {
58
+ const collection = this.connection.db.collection(step.collection);
59
+ await collection.deleteOne({ _id: <any>step.id[0] });
60
+ this.logger.log(`revert create ${step.collection} ${step.id[0]}`);
70
61
  }
71
-
72
- async revertDelete(step:StepData){
73
- const collection = this.connection.db.collection(step.collection)
74
- await collection.insertOne(step.data)
75
- console.log("revert delete",step.collection,step.id)
62
+ async revertUpdate(step: StepData) {
63
+ const collection = this.connection.db.collection(step.collection);
64
+ await collection.updateOne({ _id: <any>step.id[0] }, step.data[0]);
65
+ this.logger.log(`revert update ${step.collection} ${step.id[0]}`);
76
66
  }
77
67
 
68
+ async revertDelete(step: StepData) {
69
+ const collection = this.connection.db.collection(step.collection);
70
+ await collection.insertOne(step.data[0]);
71
+ this.logger.log(`revert delete ${step.collection} ${step.id[0]}`);
72
+ }
78
73
 
79
- async revertCreateMany(step:StepData){
80
- const collection = this.connection.db.collection(step.collection)
81
- await collection.deleteMany({_id: {$in: <any>step.id}})
82
- console.log("revert createmany",step.collection,step.id)
74
+ async revertCreateMany(step: StepData) {
75
+ const collection = this.connection.db.collection(step.collection);
76
+ await collection.deleteMany({ _id: { $in: <any>step.id } });
77
+ this.logger.log(`revert createmany ${step.collection}`,step.id);
83
78
  }
84
79
 
85
- async revertDeleteMany(step:StepData){
86
- const collection = this.connection.db.collection(step.collection)
87
- await collection.insertMany(step.data)
80
+ async revertDeleteMany(step: StepData) {
81
+ const collection = this.connection.db.collection(step.collection);
82
+ await collection.insertMany(step.data);
83
+ this.logger.log(`revert revertDeleteMany ${step.collection}`,step.id);
88
84
  }
89
85
 
90
- async revertUpdateMany(step:StepData){
91
- const collection = this.connection.db.collection(step.collection)
92
- for(let i=0; i < step.id.length;i++){
93
- const id = step.id[i]
94
- await collection.updateMany({_id: <any>id[i]},step.data[i])
86
+ async revertUpdateMany(step: StepData) {
87
+ const collection = this.connection.db.collection(step.collection);
88
+ for (let i = 0; i < step.id.length; i++) {
89
+ const id = step.id[i];
90
+ await collection.updateMany({ _id: <any>id[i] }, step.data[i]);
95
91
  }
96
-
92
+ this.logger.log(`revert revertUpdateMany ${step.collection}`,step.id);
97
93
  }
98
-
99
94
  }
100
-
101
-