@solidstarters/solid-core 1.2.96 → 1.2.97

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.96",
3
+ "version": "1.2.97",
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",
@@ -3,6 +3,7 @@ import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper';
3
3
  import { ISelectionProvider, ISelectionProviderContext } from "../interfaces";
4
4
  import { SecurityRule } from 'src/entities/security-rule.entity';
5
5
  import { EntityManager } from 'typeorm';
6
+ import { Locale } from 'src/entities/locale.entity';
6
7
 
7
8
  type ControllerMetadata = {
8
9
  name: string;
@@ -33,6 +34,7 @@ export enum RESERVED_SOLID_KEYWORDS {
33
34
  userPasswordHistory = "userPasswordHistory",
34
35
  userMetadata = "userMetadata",
35
36
  user = "user",
37
+ locale = "locale"
36
38
  }
37
39
 
38
40
  @Injectable()
@@ -44,6 +46,7 @@ export class SolidRegistry {
44
46
  private controllers: Set<ControllerMetadata> = new Set();
45
47
  private modules: Set<InstanceWrapper> = new Set();
46
48
  private securityRules: SecurityRule[] = [];
49
+ private locales : Locale[] = [];
47
50
 
48
51
  registerController(name: string, methodNames: string[]): void {
49
52
  this.controllers.add({ name: name, methods: methodNames });
@@ -117,6 +120,15 @@ export class SolidRegistry {
117
120
  this.securityRules = securityRules;
118
121
  }
119
122
 
123
+ registerlocales(locales : Locale[]){
124
+ this.locales = locales;
125
+ }
126
+
127
+ //TODO:getlocales from locale model and return default locale where isDefault:true
128
+ getDefaultLocale(): Locale | null {
129
+ return this.locales.find(locale => locale.isDefault === true) || null;
130
+ }
131
+
120
132
  getSecurityRules(modelSingularName: string, roleNames: string[] = []): SecurityRule[] {
121
133
  // If no role is provided, return all security rules for the model
122
134
  if (roleNames.length === 0) {
@@ -2,12 +2,14 @@ import { Brackets, SelectQueryBuilder, WhereExpressionBuilder } from "typeorm";
2
2
  import { BasicFilterDto } from "../dtos/basic-filters.dto";
3
3
  import { classify } from "@angular-devkit/core/src/utils/strings";
4
4
  import { ActiveUserData } from "src/interfaces/active-user-data.interface";
5
+ import { SolidRegistry } from "src/helpers/solid-registry";
6
+ import { Logger } from "@nestjs/common";
7
+
5
8
 
6
9
  export class CrudHelperService {
7
10
  constructor(
8
-
9
11
  ) { }
10
-
12
+ private readonly logger = new Logger(CrudHelperService.name);
11
13
 
12
14
  private orderOptions(sort: any[] = []) {
13
15
  const orderOptions = {};
@@ -154,8 +156,8 @@ export class CrudHelperService {
154
156
  private hasJoins(queryBuilder: SelectQueryBuilder<any>): boolean {
155
157
  return queryBuilder.expressionMap.joinAttributes.length > 0;
156
158
  }
157
-
158
- buildFilterQuery(qb: SelectQueryBuilder<any>, basicFilterDto: BasicFilterDto, entityAlias: string, internationalisation?: boolean, draftPublishWorkflow?: boolean): SelectQueryBuilder<any> { // TODO : Check how to pass a type to SelectQueryBuilder instead of any
159
+
160
+ buildFilterQuery(qb: SelectQueryBuilder<any>, basicFilterDto: BasicFilterDto, entityAlias: string, internationalisation?: boolean, draftPublishWorkflow?: boolean,moduleRef?:any): SelectQueryBuilder<any> { // TODO : Check how to pass a type to SelectQueryBuilder instead of any
159
161
  let { limit, offset, showSoftDeleted, filters } = basicFilterDto;
160
162
  const { fields, sort, groupBy, populate = [], populateMedia = [], locale, status } = basicFilterDto;
161
163
 
@@ -190,10 +192,14 @@ export class CrudHelperService {
190
192
  if (internationalisation) {
191
193
  // If locale is not provided in the filter dto, then assume it is the default locale to be used.
192
194
  if (!finalLocale) {
193
- // TODO: get the default locale from the database.
194
- // This should be replaced with the actual default locale from the database, make sure to cache this request.
195
- // @Sundaram consult with Oswald and use a registry based approach to fetch the default locale, making sure that it gets cached and we don't have to query again and again.
196
- finalLocale = 'en';
195
+ //Get default locale from registry
196
+ const solidRegistry = moduleRef.get(SolidRegistry, { strict: false });
197
+ const defaultLocale = solidRegistry.getDefaultLocale();
198
+ if(defaultLocale){
199
+ finalLocale = defaultLocale.locale;
200
+ }else{
201
+ finalLocale = 'en';
202
+ }
197
203
  }
198
204
  qb.andWhere(`${entityAlias}.localeName = :locale`, { locale: finalLocale });
199
205
  }
@@ -426,13 +426,15 @@ export class CRUDService<T> { // Add two generic value i.e Person,CreatePersonDt
426
426
  // Create above query on pincode table using query builder
427
427
  var qb: SelectQueryBuilder<T> = this.repo.createQueryBuilder(alias)
428
428
  qb = this.crudHelperService.buildFilterQuery(qb, basicFilterDto, alias);
429
-
429
+ if(internationalisation && draftPublishWorkflow){
430
+ qb = this.crudHelperService.buildFilterQuery(qb, basicFilterDto, alias,internationalisation, draftPublishWorkflow,this.moduleRef);
431
+ }
430
432
 
431
433
  if (basicFilterDto.groupBy) {
432
434
  // Get the records and the count
433
- const { groupMeta, groupRecords } = await this.handleGroupFind(qb, groupFilter, populateGroup, alias, populateMedia, internationalisation, draftPublishWorkflow);
435
+ const { groupMeta, groupRecords } = await this.handleGroupFind(qb, groupFilter, populateGroup, alias, populateMedia);
434
436
  const totalGroups = await this.crudHelperService.countGroupedRecords(qb, basicFilterDto, alias);
435
- qb = this.crudHelperService.buildFilterQuery(qb, basicFilterDto, alias, internationalisation, draftPublishWorkflow);
437
+ qb = this.crudHelperService.buildFilterQuery(qb, basicFilterDto, alias);
436
438
 
437
439
  return {
438
440
  meta: {
@@ -463,7 +465,7 @@ export class CRUDService<T> { // Add two generic value i.e Person,CreatePersonDt
463
465
  return this.wrapFindResponse(offset, limit, count, entities);
464
466
  }
465
467
 
466
- private async handleGroupFind(qb: SelectQueryBuilder<T>, groupFilter: BasicFilterDto, populateGroup: boolean, alias: string, populateMedia: string[], internationalisation: boolean, draftPublishWorkflow: boolean) {
468
+ private async handleGroupFind(qb: SelectQueryBuilder<T>, groupFilter: BasicFilterDto, populateGroup: boolean, alias: string, populateMedia: string[]) {
467
469
  const groupByResult = await qb.getRawMany();
468
470
 
469
471
  const groupMeta = [];
@@ -472,7 +474,7 @@ export class CRUDService<T> { // Add two generic value i.e Person,CreatePersonDt
472
474
  for (const group of groupByResult) {
473
475
  if (populateGroup) {
474
476
  let groupByQb: SelectQueryBuilder<T> = this.repo.createQueryBuilder(alias);
475
- groupByQb = this.crudHelperService.buildFilterQuery(groupByQb, groupFilter, alias, internationalisation, draftPublishWorkflow);
477
+ groupByQb = this.crudHelperService.buildFilterQuery(groupByQb, groupFilter, alias);
476
478
  groupByQb = this.crudHelperService.buildGroupByRecordsQuery(groupByQb, group, alias);
477
479
  const [entities, count] = await groupByQb.getManyAndCount();
478
480
 
@@ -1,4 +1,4 @@
1
- import { Injectable } from '@nestjs/common';
1
+ import { Injectable, Logger, OnApplicationBootstrap } from '@nestjs/common';
2
2
  import { InjectEntityManager, InjectRepository } from '@nestjs/typeorm';
3
3
  import { DiscoveryService, ModuleRef } from "@nestjs/core";
4
4
  import { EntityManager, Repository } from 'typeorm';
@@ -12,8 +12,9 @@ import { CrudHelperService } from 'src/services/crud-helper.service';
12
12
  import { ModelMetadata } from 'src/entities/model-metadata.entity';
13
13
  import { RequestContextService } from './request-context.service';
14
14
  import { Locale } from 'src/entities/locale.entity';
15
+ import { SolidRegistry } from 'src/helpers/solid-registry';
15
16
  @Injectable()
16
- export class LocaleService extends CRUDService<Locale>{
17
+ export class LocaleService extends CRUDService<Locale> implements OnApplicationBootstrap{
17
18
  constructor(
18
19
  readonly modelMetadataService: ModelMetadataService,
19
20
  readonly moduleMetadataService: ModuleMetadataService,
@@ -29,9 +30,19 @@ export class LocaleService extends CRUDService<Locale>{
29
30
  readonly moduleRef: ModuleRef,
30
31
  @InjectRepository(ModelMetadata)
31
32
  private readonly modelMetadataRepo: Repository<ModelMetadata>,
32
- readonly requestContextService: RequestContextService
33
+ readonly requestContextService: RequestContextService,
34
+ readonly solidRegistry: SolidRegistry,
33
35
  ) {
34
36
  super(modelMetadataService, moduleMetadataService, configService, fileService, discoveryService, crudHelperService,entityManager, repo, 'locale', 'solid-core', moduleRef);
35
37
  }
36
-
38
+ private readonly logger = new Logger(LocaleService.name)
39
+ onApplicationBootstrap() {
40
+ // Load the security rules from the database
41
+ this.loadLocales();
42
+ }
43
+ async loadLocales() {
44
+ const locales = await this.repo.find();
45
+ this.logger.debug(`Loaded ${locales.length} locales into registry`);
46
+ this.solidRegistry.registerlocales(locales);
47
+ }
37
48
  }
@@ -1,8 +1,8 @@
1
+ import { Logger } from '@nestjs/common';
1
2
  import { TransformFnParams } from 'class-transformer';
2
-
3
+ const logger = new Logger('datetimeTransformer');
3
4
  const datetimeTransformer = ({ value }: TransformFnParams): Date | null => {
4
- console.log("date time transformer debug", value);
5
-
5
+ logger.debug("date time transformer debug", value);
6
6
  if (value === '' || value === undefined || value === null) return null;
7
7
 
8
8
  const parsed = new Date(value);