@solidstarters/solid-core 1.2.2 → 1.2.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidstarters/solid-core",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "This module is a NestJS module containing all the required core providers required by a Solid application",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,7 +18,7 @@ export class BasicFilterDto extends PaginationQueryDto {
18
18
  @ApiProperty({ description: "groupBy" })
19
19
  readonly groupBy?: string[];
20
20
 
21
-
21
+
22
22
  @IsOptional()
23
23
  @ApiProperty({ description: "populate" })
24
24
  readonly populate?: string[];
@@ -44,4 +44,8 @@ export class BasicFilterDto extends PaginationQueryDto {
44
44
  @IsOptional()
45
45
  @ApiProperty({ description: "populateGroup" })
46
46
  readonly populateGroup?: boolean;
47
+
48
+ @IsOptional()
49
+ @ApiProperty({ description: "groupFilter" })
50
+ groupFilter?: BasicFilterDto
47
51
  }
@@ -163,7 +163,7 @@ export class CRUDService<T> { //Add two generic value i.e Person,CreatePersonDto
163
163
 
164
164
  //TODO: Will the updates be partial i.e PATCH or full i.e PUT
165
165
  async update(id: number, updateDto: any, files: Express.Multer.File[] = [], isPartialUpdate: boolean = false): Promise<T> {
166
- if (!id) {
166
+ if (!id) {
167
167
  throw new Error('Id is required for update');
168
168
  }
169
169
  const entity = await this.repo.findOne({
@@ -239,7 +239,7 @@ export class CRUDService<T> { //Add two generic value i.e Person,CreatePersonDto
239
239
  }
240
240
  }
241
241
 
242
- private fieldCrudManager(fieldMetadata: FieldMetadata, entityManager: EntityManager, isPartialUpdate: boolean=false): FieldCrudManager {
242
+ private fieldCrudManager(fieldMetadata: FieldMetadata, entityManager: EntityManager, isPartialUpdate: boolean = false): FieldCrudManager {
243
243
  const commonOptions = { required: fieldMetadata.required && !isPartialUpdate, fieldName: fieldMetadata.name };
244
244
  switch (fieldMetadata.type) {
245
245
  case SolidFieldType.shortText: {
@@ -262,11 +262,11 @@ export class CRUDService<T> { //Add two generic value i.e Person,CreatePersonDto
262
262
  const options = { ...commonOptions };
263
263
  return new JsonFieldCrudManager(options);
264
264
  }
265
- case SolidFieldType.int:{
265
+ case SolidFieldType.int: {
266
266
  const options = { ...commonOptions, min: fieldMetadata.min, max: fieldMetadata.max };
267
267
  return new IntFieldCrudManager(options);
268
268
  }
269
- case SolidFieldType.decimal:{
269
+ case SolidFieldType.decimal: {
270
270
  const options = { ...commonOptions, min: fieldMetadata.min, max: fieldMetadata.max };
271
271
  return new DecimalFieldCrudManager(options);
272
272
  }
@@ -274,21 +274,21 @@ export class CRUDService<T> { //Add two generic value i.e Person,CreatePersonDto
274
274
  const options = { ...commonOptions, min: fieldMetadata.min, max: fieldMetadata.max };
275
275
  return new BigIntFieldCrudManager(options);
276
276
  }
277
- case SolidFieldType.email:{
278
- const options = { ...commonOptions, max: fieldMetadata.max?? MAX_EMAIL_LENGTH, regexPattern: fieldMetadata.regexPattern };
277
+ case SolidFieldType.email: {
278
+ const options = { ...commonOptions, max: fieldMetadata.max ?? MAX_EMAIL_LENGTH, regexPattern: fieldMetadata.regexPattern };
279
279
  return new EmailFieldCrudManager(options);
280
280
  }
281
281
  case SolidFieldType.date:
282
- case SolidFieldType.datetime:{
282
+ case SolidFieldType.datetime: {
283
283
  const options = { ...commonOptions };
284
284
  return new DateFieldCrudManager(options);
285
285
  }
286
- case SolidFieldType.password:{
286
+ case SolidFieldType.password: {
287
287
  const options = { ...commonOptions, min: fieldMetadata.min, max: fieldMetadata.max, regexPattern: fieldMetadata.regexPattern };
288
288
  return new PasswordFieldCrudManager(options);
289
289
  }
290
290
  case SolidFieldType.mediaSingle:
291
- case SolidFieldType.mediaMultiple:{
291
+ case SolidFieldType.mediaMultiple: {
292
292
  // update will need to delete the existing media and save the new media
293
293
  // case 'mediaSingle':
294
294
  // Use the EntityController to extract uploaded content & pass to the entity service.
@@ -357,13 +357,13 @@ export class CRUDService<T> { //Add two generic value i.e Person,CreatePersonDto
357
357
  }
358
358
  }
359
359
  else throw new Error('Relation type not supported in crud service');
360
- // return (fieldMetadata.relationType === 'many-to-one') ? new ManyToOneRelationFieldCrudManager(fieldMetadata, entityManager) : new ManyToManyRelationFieldCrudManager(fieldMetadata, entityManager); //FIXME many-to-many pending
361
- // ManyToOne -> fieldId. The value is saved as is. No transformation is required
362
- // OneToMany -> fieldIds. Get the value of the oneToMany field side. No transformation is required (While saving special provision to be made)
363
- // ManyToMany
364
- // break;
360
+ // return (fieldMetadata.relationType === 'many-to-one') ? new ManyToOneRelationFieldCrudManager(fieldMetadata, entityManager) : new ManyToManyRelationFieldCrudManager(fieldMetadata, entityManager); //FIXME many-to-many pending
361
+ // ManyToOne -> fieldId. The value is saved as is. No transformation is required
362
+ // OneToMany -> fieldIds. Get the value of the oneToMany field side. No transformation is required (While saving special provision to be made)
363
+ // ManyToMany
364
+ // break;
365
365
  }
366
- case SolidFieldType.selectionStatic:{
366
+ case SolidFieldType.selectionStatic: {
367
367
 
368
368
  // Validation against the selectionStatic values. No transformation is required
369
369
  // If the value is not in the selectionStatic values, then throw
@@ -380,12 +380,12 @@ export class CRUDService<T> { //Add two generic value i.e Person,CreatePersonDto
380
380
  const options = { ...commonOptions, selectionDynamicProvider: fieldMetadata.selectionDynamicProvider, selectionDynamicProviderCtxt: fieldMetadata.selectionDynamicProviderCtxt, selectionValueType: fieldMetadata.selectionValueType as SelectionValueType, discoveryService: this.discoveryService };
381
381
  return new SelectionDynamicFieldCrudManager(options);
382
382
  }
383
- case SolidFieldType.uuid:{
383
+ case SolidFieldType.uuid: {
384
384
  const options = { ...commonOptions };
385
385
  // If no value is provided, then generate a uuid. Add to the dto
386
386
  return new UUIDFieldCrudManager(options);
387
387
  }
388
- case SolidFieldType.computed:{
388
+ case SolidFieldType.computed: {
389
389
 
390
390
  // The value will be computed by the computed provider
391
391
  // Invoke the appropriate computed provider, get the value and add to the dto
@@ -401,7 +401,7 @@ export class CRUDService<T> { //Add two generic value i.e Person,CreatePersonDto
401
401
  async find(basicFilterDto: BasicFilterDto) {
402
402
  const alias = 'entity';
403
403
  // Extract the required keys from the input query
404
- let { limit, offset, populateMedia, populateGroup } = basicFilterDto;
404
+ let { limit, offset, populateMedia, populateGroup,groupFilter } = basicFilterDto;
405
405
 
406
406
  // Create above query on pincode table using query builder
407
407
  var qb: SelectQueryBuilder<T> = this.repo.createQueryBuilder(alias)
@@ -409,7 +409,7 @@ export class CRUDService<T> { //Add two generic value i.e Person,CreatePersonDto
409
409
 
410
410
  if (basicFilterDto.groupBy) {
411
411
  // Get the records and the count
412
- const { groupMeta, groupRecords } = await this.handleGroupFind(qb, populateGroup, alias, populateMedia);
412
+ const { groupMeta, groupRecords } = await this.handleGroupFind(qb, groupFilter,populateGroup, alias, populateMedia);
413
413
  return {
414
414
  groupMeta,
415
415
  groupRecords,
@@ -417,7 +417,7 @@ export class CRUDService<T> { //Add two generic value i.e Person,CreatePersonDto
417
417
  }
418
418
  else {
419
419
  // Get the records and the count
420
- const {meta, records} = await this.handleNonGroupFind(qb, populateMedia, offset, limit);
420
+ const { meta, records } = await this.handleNonGroupFind(qb, populateMedia, offset, limit);
421
421
  return {
422
422
  meta,
423
423
  records,
@@ -433,10 +433,10 @@ export class CRUDService<T> { //Add two generic value i.e Person,CreatePersonDto
433
433
  await this.handlePopulateMedia(populateMedia, entities);
434
434
  }
435
435
 
436
- return this.wrapFindResponse(offset, limit, count, entities);
436
+ return this.wrapFindResponse(offset, limit, count, entities);
437
437
  }
438
438
 
439
- private async handleGroupFind(qb: SelectQueryBuilder<T>, populateGroup: boolean, alias: string, populateMedia: string[]) {
439
+ private async handleGroupFind(qb: SelectQueryBuilder<T>, groupFilter: BasicFilterDto,populateGroup: boolean, alias: string, populateMedia: string[]) {
440
440
  const groupByResult = await qb.getRawMany();
441
441
 
442
442
  const groupMeta = [];
@@ -446,11 +446,11 @@ export class CRUDService<T> { //Add two generic value i.e Person,CreatePersonDto
446
446
  if (populateGroup) {
447
447
  let groupByQb: SelectQueryBuilder<T> = this.repo.createQueryBuilder(alias);
448
448
  // For the group by records, apply the basic filter
449
- const basicFilterDto = {
450
- limit: DEFAULT_LIMIT,
451
- offset: DEFAULT_OFFSET,
452
- };
453
- groupByQb = this.crudHelperService.buildFilterQuery(groupByQb, basicFilterDto, alias);
449
+ // const basicFilterDto = {
450
+ // limit: DEFAULT_LIMIT,
451
+ // offset: DEFAULT_OFFSET,
452
+ // };
453
+ groupByQb = this.crudHelperService.buildFilterQuery(groupByQb, groupFilter, alias);
454
454
  groupByQb = this.crudHelperService.buildGroupByRecordsQuery(groupByQb, group, alias);
455
455
  const [entities, count] = await groupByQb.getManyAndCount();
456
456
 
@@ -459,7 +459,7 @@ export class CRUDService<T> { //Add two generic value i.e Person,CreatePersonDto
459
459
  if (populateMedia && populateMedia.length > 0) {
460
460
  await this.handlePopulateMedia(populateMedia, entities);
461
461
  }
462
- const groupData = this.wrapFindResponse(basicFilterDto.offset, basicFilterDto.limit, count, entities);
462
+ const groupData = this.wrapFindResponse(groupFilter.offset, groupFilter.limit, count, entities);
463
463
  groupRecords.push(this.crudHelperService.createGroupRecords(group, alias, groupData));
464
464
  }
465
465
  groupMeta.push(this.crudHelperService.createGroupMeta(group, alias));