Skip to content

Commit

Permalink
fix(refactor): fix strictNull and strictTyping errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerald Baulig committed Mar 8, 2024
1 parent c7a1017 commit 39e58ce
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
18 changes: 18 additions & 0 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,21 @@ export class ManufacturerService extends ServiceBase<ManufacturerListResponse, M
super('manufacturer', topic, logger, new ResourcesAPIBase(db, 'manufacturers', resourceFieldConfig), enableEvents);
}
}

export const getService = (name: string): {
new(
topic: Topic,
db: DatabaseProvider,
cfg: any, logger: any,
enableEvents: boolean
): {}
} => {
switch (name) {
case 'ProductService': return ProductService;
case 'ProductPrototypeService': return ProductPrototypeService;
case 'ProductCategoryService': return ProductCategoryService;
case 'PriceGroupService': return PriceGroupService;
case 'ManufacturerService': return ManufacturerService;
default: throw 'Unknown Service!';
}
}
2 changes: 1 addition & 1 deletion src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createLogger } from '@restorecommerce/logger';
// cfg and logger
const cfg = createServiceConfig(process.cwd());
const loggerCfg = cfg.get('logger') || {};
loggerCfg.esTransformer = (msg) => {
loggerCfg.esTransformer = (msg: any) => {
msg.fields = JSON.stringify(msg.fields);
return msg;
};
Expand Down
21 changes: 14 additions & 7 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createServiceConfig } from '@restorecommerce/service-config';
import { Events, registerProtoMeta } from '@restorecommerce/kafka-client';
import { createLogger } from '@restorecommerce/logger';
import * as chassis from '@restorecommerce/chassis-srv';
import * as catalogServices from './service.js';
import { getService } from './service.js';
import { CatalogCommandInterface } from './commandInterface.js';
import { RedisClientType, createClient } from 'redis';
import { Arango } from '@restorecommerce/chassis-srv/lib/database/provider/arango/base.js';
Expand Down Expand Up @@ -35,11 +35,11 @@ import { ServerReflectionService } from 'nice-grpc-server-reflection';

registerProtoMeta(manufacturerMeta, priceGroupMeta, productCategoryMeta, productPorotoTypeMeta, productMeta, commandInterfaceMeta);

const ServiceDefinitions: any = [manufacturer, price_group, product_category, product_prototype, product];
const ServiceDefinitions = [manufacturer, price_group, product_category, product_prototype, product];

const capitalized = (entity: string): string => {
const labels = entity.split('_').map((element) => {
return element.charAt(0).toUpperCase() + element.substr(1);
return element.charAt(0).toUpperCase() + element.slice(1);
});
return labels.join('');
};
Expand Down Expand Up @@ -83,7 +83,7 @@ export class Worker {
this.cfg = cfg || createServiceConfig(process.cwd());
const loggerCfg = this.cfg.get('logger');
if (loggerCfg) {
loggerCfg.esTransformer = (msg) => {
loggerCfg.esTransformer = (msg: any) => {
msg.fields = JSON.stringify(msg.fields);
return msg;
};
Expand Down Expand Up @@ -163,9 +163,16 @@ export class Worker {
const serviceName = serviceNamesCfg[entity];
if (serviceName) {
const capitalizedName = capitalized(entity);
this.services[entity] = new catalogServices[`${capitalizedName}Service`](
this.topics[`${entity}s.resources`], db, cfg, logger, isEventsEnabled);
const serviceDef = ServiceDefinitions.filter((obj) => obj.fullName.split('.')[2] === entity)[0];
this.services[entity] = new (getService(`${capitalizedName}Service`))(
this.topics[`${entity}s.resources`],
db,
cfg,
logger,
isEventsEnabled
);
const serviceDef = ServiceDefinitions.find(
(obj) => obj.fullName.split('.')[2] === entity
);
await server.bind(serviceName, {
implementation: this.services[entity],
service: serviceDef
Expand Down

0 comments on commit 39e58ce

Please sign in to comment.