@simitgroup/simpleapp-generator 2.0.0-n-alpha → 2.0.0-o-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,7 @@
1
+ [2.0.0o-alpha]
2
+ 1. Fix create many bugs
3
+ 2. support request multiple number
4
+
1
5
  [2.0.0n-alpha]
2
6
  1. fix bugs on declare generator version
3
7
  2. show generator version on swagger ui
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simitgroup/simpleapp-generator",
3
- "version": "2.0.0n-alpha",
3
+ "version": "2.0.0o-alpha",
4
4
  "description": "frontend nuxtjs and backend nests code generator using jsonschema",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -27,7 +27,7 @@ async function bootstrap() {
27
27
 
28
28
  const config = new DocumentBuilder()
29
29
  .setTitle(process.env.PROJECT_NAME)
30
- .addServer(process.env.BACKEND_URL)
30
+ .addServer(process.env.APP_SWAGGER_SERVER_URL)
31
31
  .setDescription(`${process.env.PROJECT_DESCRIPTION} (generator: ${generatorVersion})`)
32
32
  .setVersion(process.env.PROJECT_VERSION)
33
33
  .addApiKey(
@@ -186,4 +186,33 @@ export class SimpleAppDocumentNoFormatService {
186
186
  Object.assign(filter, isolationFilter);
187
187
  return await this.docformat.find<DocumentNoFormat>(filter, null, { session: appUser.getDBSession() });
188
188
  }
189
+
190
+ async requestMultipleNumbers(appUser: UserContext, doctype: string, quantity:number, id: string = '') {
191
+ doctype = doctype.toUpperCase();
192
+ const documentNumbers: string[] = []
193
+ const filter = { docNoType: doctype, active: true };
194
+ if (id) {
195
+ filter['_id'] = id;
196
+ }
197
+ //
198
+ Object.assign(filter, appUser.getBranchFilter());
199
+ const result = await this.docformat.find(filter).session(appUser.getDBSession());
200
+ if (result && result.length > 0) {
201
+ const d: DocumentNoFormat = result[0];
202
+ const recordId = d._id;
203
+
204
+ for(let i=0;i<quantity;i++){
205
+ d.nextNumber++
206
+ const newdocno = SimpleAppDocumentNoFormatService.previewDocNo(d);
207
+ documentNumbers.push(newdocno)
208
+
209
+ }
210
+ const updatedata = { nextNumber: d.nextNumber+1 } as DocumentNoFormat;
211
+ const updateresult = await this.docformat.findByIdAndUpdate(recordId, updatedata).session(appUser.getDBSession());
212
+
213
+ return documentNumbers
214
+ } else {
215
+ throw new BadRequestException(`No active document number found for ${doctype}. Please update in Settings > Document Numbering Format`);
216
+ }
217
+ }
189
218
  }
@@ -16,15 +16,13 @@ import addFormats from 'ajv-formats';
16
16
  import { FilterQuery, Model, PipelineStage, mongo } from 'mongoose';
17
17
  // import { CloudApiService } from 'src/cloudapi/cloudapi.service';
18
18
  import { foreignkeys } from '../../features/foreign-key/foreignkeys.dict';
19
- import { CustomException } from '../custom-exception';
20
19
 
21
20
  import { camelToKebab } from 'src/simple-app/_core/utils/string-utils';
22
21
  import { SimpleAppDocumentNoFormatService } from '../../features/document-no-format/document-no-format.service';
22
+ import { SimpleAppLogService } from '../../features/log/log.service';
23
23
  import { UserContext } from '../../features/user-context/user.context';
24
24
  import { RunWebhookService } from '../../features/webhook/run-webhook.service';
25
- import { UniqueKeyExistResponse, DeleteResultType, IsolationType, MoreProjectionType, SchemaFields, TextSearchBody, PatchManyRequest } from '../schemas';
26
- import { SimpleAppLogService } from '../../features/log/log.service';
27
- import { ProcessErrorException } from 'src/simple-app/features/exception/process-error.exception';
25
+ import { DeleteResultType, IsolationType, MoreProjectionType, PatchManyRequest, SchemaFields, TextSearchBody, UniqueKeyExistResponse } from '../schemas';
28
26
 
29
27
  @Injectable()
30
28
  export class SimpleAppService<T extends SchemaFields> {
@@ -108,7 +106,7 @@ export class SimpleAppService<T extends SchemaFields> {
108
106
  public isReadOnly(): boolean {
109
107
  return false;
110
108
  }
111
- reCalculateValue(data: T) {}
109
+ reCalculateValue(data: T) { }
112
110
  getIsolationFilter = (appuser: UserContext) => {
113
111
  let isolationFilter = {};
114
112
  switch (this.isolationtype) {
@@ -483,6 +481,10 @@ export class SimpleAppService<T extends SchemaFields> {
483
481
  try {
484
482
  const result = await this.doc.insertMany(datas, { session: dbsession });
485
483
  await this.addManyAuditEvents(appuser, this.documentName, 'createMany', datas);
484
+ for (const data of datas) {
485
+ appuser.addInsertedRecordId(this.documentName, data._id);
486
+ }
487
+
486
488
  return result;
487
489
  } catch (e) {
488
490
  throw e;
@@ -902,7 +904,7 @@ export class SimpleAppService<T extends SchemaFields> {
902
904
 
903
905
  //patch not suitable trigger afterupdate
904
906
  // if (this.hooks.beforeUpdate) await this.hooks.beforeUpdate(appuser, id, existingdata, data);
905
- await this.runEvent(appuser, this.setHookName('beforePatch'), { id: id, patchData: data,prevData:existingdata }, false);
907
+ await this.runEvent(appuser, this.setHookName('beforePatch'), { id: id, patchData: data, prevData: existingdata }, false);
906
908
  const dbsession = appuser.getDBSession();
907
909
  if (dbsession && !dbsession.inTransaction()) {
908
910
  dbsession.startTransaction({ readPreference: 'primary' });
@@ -935,7 +937,7 @@ export class SimpleAppService<T extends SchemaFields> {
935
937
  await this.addAuditEvent(appuser, this.documentName, id, 'patch', data);
936
938
  }
937
939
  appuser.addUpdatedRecordId(this.documentName, data._id);
938
- await this.runEvent(appuser, this.setHookName('afterPatch'), { id: id, patchData: data, prevData:existingdata }, false);
940
+ await this.runEvent(appuser, this.setHookName('afterPatch'), { id: id, patchData: data, prevData: existingdata }, false);
939
941
  return result; //await this.findById(appuser, id);
940
942
  } catch (err) {
941
943
  this.logger.error(err.message, 'findIdThenPath error');
@@ -1090,13 +1092,12 @@ export class SimpleAppService<T extends SchemaFields> {
1090
1092
  * @param {any} data The data
1091
1093
  * @return {Promise} { description_of_the_return_value }
1092
1094
  */
1093
- async runEvent(appuser: UserContext, eventName: string, payloads: any, enforce: boolean = true) {
1095
+ async runEvent(appuser: UserContext, eventName: string, payloads: any, enforce: boolean = true) {
1094
1096
  try {
1095
1097
  if (enforce && !this.eventEmitter.hasListeners(eventName)) {
1096
1098
  throw new InternalServerErrorException(`${eventName} seems no listener`);
1097
1099
  } else if (this.eventEmitter.hasListeners(eventName)) {
1098
-
1099
- console.log("run eventName",eventName)
1100
+ console.log('run eventName', eventName);
1100
1101
  const res = await this.eventEmitter.emitAsync(eventName, appuser, payloads);
1101
1102
 
1102
1103
  if (!res) {
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <div class="w-full">
3
3
  <div class="flex flex-row">
4
- <label v-if="!hideLabel" :for="fieldid">
4
+ <label v-if="!hideLabel" :for="fieldid" class="mr-2 text-xs text-gray-400">
5
5
  {{ t(documentName) }}
6
6
  </label>
7
7
  <div