@simitgroup/simpleapp-generator 2.0.1-o-alpha → 2.0.1-p-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,9 @@
1
+ [2.0.1p-alpha]
2
+
3
+ 1. fix delete record cant work in transactions, sharded env
4
+
5
+
6
+
1
7
  [2.0.1o-alpha]
2
8
 
3
9
  1. fetch branch image url, and fix maintenance mode data
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simitgroup/simpleapp-generator",
3
- "version": "2.0.1o-alpha",
3
+ "version": "2.0.1p-alpha",
4
4
  "description": "frontend nuxtjs and backend nests code generator using jsonschema",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -357,7 +357,6 @@ export class SimpleAppService<T extends SchemaFields> {
357
357
  }
358
358
  }
359
359
 
360
-
361
360
  /**
362
361
  * create many from array, for performance reason it submit all item in 1 go, so it won't implement hooks
363
362
  * @param appuser
@@ -377,7 +376,7 @@ export class SimpleAppService<T extends SchemaFields> {
377
376
  }
378
377
  const dbsession = appuser.getDBSession();
379
378
  if (dbsession && !dbsession.inTransaction()) {
380
- dbsession.startTransaction({readConcern:{level:"snapshot"},writeConcern:{w:"majority"}, readPreference: 'primary' });
379
+ dbsession.startTransaction({ readConcern: { level: 'snapshot' }, writeConcern: { w: 'majority' }, readPreference: 'primary' });
381
380
  }
382
381
 
383
382
  try {
@@ -404,7 +403,7 @@ export class SimpleAppService<T extends SchemaFields> {
404
403
  }
405
404
  const dbsession = appuser.getDBSession();
406
405
  if (dbsession && !dbsession.inTransaction() && !noStartTransaction) {
407
- dbsession.startTransaction({readConcern:{level:"snapshot"},writeConcern:{w:"majority"}, readPreference: 'primary' });
406
+ dbsession.startTransaction({ readConcern: { level: 'snapshot' }, writeConcern: { w: 'majority' }, readPreference: 'primary' });
408
407
  }
409
408
 
410
409
  this.logger.debug('this.withDocNumberFormat :' + this.withDocNumberFormat + ' && ' + '!data[this.documentIdentityCode] ==' + !data[this.documentIdentityCode]);
@@ -550,7 +549,7 @@ export class SimpleAppService<T extends SchemaFields> {
550
549
  }
551
550
  const dbsession = appuser.getDBSession();
552
551
  if (dbsession && !dbsession.inTransaction()) {
553
- dbsession.startTransaction({readConcern:{level:"snapshot"},writeConcern:{w:"majority"}, readPreference: 'primary' });
552
+ dbsession.startTransaction({ readConcern: { level: 'snapshot' }, writeConcern: { w: 'majority' }, readPreference: 'primary' });
554
553
  }
555
554
 
556
555
  let dependency;
@@ -560,8 +559,7 @@ export class SimpleAppService<T extends SchemaFields> {
560
559
 
561
560
  // if (this.hooks.beforeDelete) await this.hooks.beforeDelete(appuser, id, deletedata);
562
561
  this.logger.debug('delete record', this.documentName, id);
563
- dependency = await this.getRelatedRecords(appuser, id);
564
- //console.log('dependency', dependency);
562
+ await this.identifyForeignKeys(appuser,deletedata)
565
563
  if (!dependency) {
566
564
  const filterIsolation = this.getIsolationFilter(appuser);
567
565
  this.polishIsolationFilter(filterIsolation);
@@ -629,7 +627,7 @@ export class SimpleAppService<T extends SchemaFields> {
629
627
 
630
628
  const dbsession = appuser.getDBSession();
631
629
  if (dbsession && !dbsession.inTransaction() && !noStartTransaction) {
632
- dbsession.startTransaction({readConcern:{level:"snapshot"},writeConcern:{w:"majority"}, readPreference: 'primary' });
630
+ dbsession.startTransaction({ readConcern: { level: 'snapshot' }, writeConcern: { w: 'majority' }, readPreference: 'primary' });
633
631
  }
634
632
  // try {
635
633
  Object.assign(data, appuser.getUpdateFilter());
@@ -688,7 +686,7 @@ export class SimpleAppService<T extends SchemaFields> {
688
686
 
689
687
  const dbsession = appuser.getDBSession();
690
688
  if (dbsession && !dbsession.inTransaction()) {
691
- dbsession.startTransaction({readConcern:{level:"snapshot"},writeConcern:{w:"majority"}, readPreference: 'primary' });
689
+ dbsession.startTransaction({ readConcern: { level: 'snapshot' }, writeConcern: { w: 'majority' }, readPreference: 'primary' });
692
690
  }
693
691
  // try {
694
692
  // Object.assign(data, appuser.getUpdateFilter());
@@ -744,7 +742,7 @@ export class SimpleAppService<T extends SchemaFields> {
744
742
  await this.runEvent(appuser, this.setHookName('beforePatch'), { id: id, patchData: data, prevData: existingdata }, false);
745
743
  const dbsession = appuser.getDBSession();
746
744
  if (dbsession && !dbsession.inTransaction()) {
747
- dbsession.startTransaction({readConcern:{level:"snapshot"},writeConcern:{w:"majority"}, readPreference: 'primary' });
745
+ dbsession.startTransaction({ readConcern: { level: 'snapshot' }, writeConcern: { w: 'majority' }, readPreference: 'primary' });
748
746
  }
749
747
  // try {
750
748
  Object.assign(data, appuser.getUpdateFilter());
@@ -782,7 +780,22 @@ export class SimpleAppService<T extends SchemaFields> {
782
780
  throw new InternalServerErrorException(err.message);
783
781
  }
784
782
  };
785
-
783
+ async deleteMany(appUser:UserContext, filter: FilterQuery<T>){
784
+ const dbsession = appUser.getDBSession();
785
+ if (dbsession && !dbsession.inTransaction()) {
786
+ dbsession.startTransaction({ readConcern: { level: 'snapshot' }, writeConcern: { w: 'majority' }, readPreference: 'primary' });
787
+ }
788
+ const searchResult = await this.search(appUser,filter,[])
789
+ const ids = searchResult.map(row=>row._id)
790
+ const result = await this.doc.deleteMany({_id: {$in: ids}})
791
+ console.log(`Delete ${this.documentName} ids`, ids,result)
792
+ for(const id of ids){
793
+ appUser.addDeletedRecordId(this.documentName,id)
794
+ }
795
+ return result
796
+ //updateMany(isolationFilter, { $set: patch }, { session: dbsession });
797
+
798
+ }
786
799
  async patchMany<T>(appuser: UserContext, data: PatchManyRequest<T>) {
787
800
  // filter = {
788
801
  // _id: '7eb2661a-6ea6-406e-b868-2e8b19c4658b',
@@ -799,7 +812,7 @@ export class SimpleAppService<T extends SchemaFields> {
799
812
  // Get DB Session
800
813
  const dbsession = appuser.getDBSession();
801
814
  if (dbsession && !dbsession.inTransaction()) {
802
- dbsession.startTransaction({readConcern:{level:"snapshot"},writeConcern:{w:"majority"}, readPreference: 'primary' });
815
+ dbsession.startTransaction({ readConcern: { level: 'snapshot' }, writeConcern: { w: 'majority' }, readPreference: 'primary' });
803
816
  }
804
817
 
805
818
  const result = await this.doc.updateMany(isolationFilter, { $set: patch }, { session: dbsession });