Skip to content

Commit

Permalink
Address pr review comments
Browse files Browse the repository at this point in the history
- addressed pr review comments
- removed redundant filtering in FlyerRepo
- added checks for null return values in FlyerRepo
- alphabetized imports and exports
  • Loading branch information
isaachan100 committed Apr 20, 2023
1 parent 26587b1 commit 81cff13
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
4 changes: 0 additions & 4 deletions src/entities/Flyer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ export class Flyer {
@Property()
imageURL: string;

@Field()
@Property()
isFiltered: boolean;

@Field()
@Property({ default: false })
isTrending: boolean;
Expand Down
16 changes: 6 additions & 10 deletions src/repos/FlyerRepo.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import Filter from 'bad-words';
import { ObjectId } from 'mongodb';
import Fuse from 'fuse.js';
import { Flyer, FlyerModel } from '../entities/Flyer';

import { ObjectId } from 'mongodb';
import {
DEFAULT_LIMIT,
DEFAULT_OFFSET,
FILTERED_WORDS,
MAX_NUM_DAYS_OF_TRENDING_ARTICLES,
} from '../common/constants';
import { Flyer, FlyerModel } from '../entities/Flyer';
import { OrganizationModel } from '../entities/Organization';

const { IS_FILTER_ACTIVE } = process.env;

function isFlyerFiltered(flyer: Flyer) {
if (IS_FILTER_ACTIVE === 'true') {
if (flyer.isFiltered) {
// If the body has been checked already in microservice
return true;
}
const filter = new Filter({ list: FILTERED_WORDS });
return filter.isProfane(flyer.title);
}
Expand Down Expand Up @@ -91,7 +88,7 @@ const getFlyersByOrganizationID = async (
.skip(offset)
.limit(limit)
.then((flyers) => {
return flyers.filter((flyer) => !isFlyerFiltered(flyer));
return flyers.filter((flyer) => flyer !== null && !isFlyerFiltered(flyer));
});
};

Expand All @@ -101,7 +98,6 @@ const getFlyersByOrganizationIDs = async (
offset: number = DEFAULT_OFFSET,
): Promise<Flyer[]> => {
const uniqueOrgIDs = [...new Set(organizationIDs)].map((id) => new ObjectId(id));
console.log(uniqueOrgIDs);
const orgSlugs = await OrganizationModel.find({ _id: { $in: uniqueOrgIDs } }).select('slug');
return getFlyersByOrganizationSlugs(
orgSlugs.map((org) => org.slug),
Expand All @@ -120,7 +116,7 @@ const getFlyersAfterDate = async (since: string, limit = DEFAULT_LIMIT): Promise
.sort({ date: 'desc' })
.limit(limit)
.then((flyers) => {
return flyers.filter((flyer) => !isFlyerFiltered(flyer));
return flyers.filter((flyer) => flyer !== null && !isFlyerFiltered(flyer));
})
);
};
Expand Down Expand Up @@ -222,8 +218,8 @@ export default {
getFlyersByOrganizationIDs,
getFlyersByOrganizationSlug,
getFlyersByOrganizationSlugs,
searchFlyers,
getTrendingFlyers,
incrementShoutouts,
refreshTrendingFlyers,
searchFlyers,
};

0 comments on commit 81cff13

Please sign in to comment.