Skip to content

Commit

Permalink
Add readonly and make double map in single reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Bereziuk committed Sep 26, 2023
1 parent 9671aae commit e40b206
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/modules/news/news.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class NewsModule {

constructor(
private readonly newsService: NewsService,
@Inject(PUBSUB_PROVIDER) private pubSub: PubSub,
@Inject(PUBSUB_PROVIDER) private readonly pubSub: PubSub,
) {}

onApplicationBootstrap(): void {
Expand Down
16 changes: 5 additions & 11 deletions src/modules/offer/services/offer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import { hasMatchingRole } from '../offer.utils/has-matching-role.util';
import { FirebaseTableReference } from '$/modules/firebase/firebase.types';
import { Scope } from '$modules/auth/auth.constants';
import { Identity } from '$modules/auth/auth.types';
import {
isNotNull,
paginate,
preparePaginatedResult,
} from '$modules/common/common.utils';
import { paginate, preparePaginatedResult } from '$modules/common/common.utils';
import { FirebaseDatabasePath } from '$modules/firebase/firebase.constants';
import { FirebaseService } from '$modules/firebase/firebase.service';
import { PUBSUB_PROVIDER } from '$modules/graphql-pubsub/graphql-pubsub.constants';
Expand Down Expand Up @@ -89,18 +85,17 @@ export class OfferService {

return Object.entries(offers)
.map(([id, offer]) => ({ id, ...offer }))
.map((offer) => {
.reduce((resultOffers: OfferDto[], offer) => {
try {
// * in case data is corrupted, we we should handle it without crashing the app
return OfferDto.adapter.toExternal(offer);
resultOffers.push(OfferDto.adapter.toExternal(offer));
} catch (error) {
this.logger.error(`Error while converting offer ${offer.id}`);
this.logger.error(error);
}

return null;
})
.filter(isNotNull);
return resultOffers;
}, []);
}

async getOffers(args: OfferArgs, identity: Identity): Promise<OfferListDto> {
Expand All @@ -127,7 +122,6 @@ export class OfferService {
return false;
});

// * we don't need to filter by id, as we did it in forEach loop above
nodes = filterOffers({ offers: nodes, filter });

if (ordersBy) {
Expand Down

0 comments on commit e40b206

Please sign in to comment.