Skip to content

Commit

Permalink
Isaac/merge main release (#96)
Browse files Browse the repository at this point in the history
* Add Jest testing (#63)

* Initial boilerplate setup

* Add ArticleFactory, TestingDBConnection, FactoryUtils, placeholder article test file

* Add test cases on getAllArticles

* Create PublicationFactory, add tests for getAllArticles, getArticlesByPublicationID(s), getArticlesByPublicationSlug(s)

* Add hooks

* Update README

* Add pr changes

* Add pr changes

* Add tests for incrementShoutouts, searchArticle, getArticlesAfterDate

* Add publication tests and refactor factory files

* Remove test db open message

* Update src/tests/article.test.ts

Co-authored-by: Archit Mehta <[email protected]>

* Update src/tests/data/ArticleFactory.ts

Co-authored-by: Archit Mehta <[email protected]>

* Refactor code

* Refactor byDate

Co-authored-by: Kidus Zegeye <[email protected]>
Co-authored-by: Archit Mehta <[email protected]>

* Add Docstrings to Test Factory Functions (#64)

* Initial boilerplate setup

* Add ArticleFactory, TestingDBConnection, FactoryUtils, placeholder article test file

* Add test cases on getAllArticles

* Create PublicationFactory, add tests for getAllArticles, getArticlesByPublicationID(s), getArticlesByPublicationSlug(s)

* Add hooks

* Update README

* Add pr changes

* Add pr changes

* Add tests for incrementShoutouts, searchArticle, getArticlesAfterDate

* Add publication tests and refactor factory files

* Remove test db open message

* Update src/tests/article.test.ts

Co-authored-by: Archit Mehta <[email protected]>

* Update src/tests/data/ArticleFactory.ts

Co-authored-by: Archit Mehta <[email protected]>

* Refactor code

* Refactor byDate

* Add docstrings

Co-authored-by: Kidus Zegeye <[email protected]>
Co-authored-by: Archit Mehta <[email protected]>

* Update README.md

* Implement community board models (#65)

* Implemented community board models

- implemented Flyer and Organization models for community board feature
- modified User model
- updated typescript version to 4.0.5 to resolve es lint issue

* Revert package.json changes

- reverted package.json changes that are addressed in a different pr

* Add magazines to weekly debrief (#66)

* Implemented community board models

- implemented Flyer and Organization models for community board feature
- modified User model
- updated typescript version to 4.0.5 to resolve es lint issue

* Implemented weekly debrief magazines

- added magazines to weekly debrief feature
- updated user and weekly debrief models to allow tracking of read magazines
- updated logic in user and weekly debrief controllers to enable reading of magazines

* Revert package.json changes

- reverted package.json changes back to the original file
- added additional rules to eslintrc to suppress es lint warnings

* Create jest testing for magazines

- added jest test cases for magazines

* Implement jest testing for User

- implemented unit testing for UserRepo
- indirectly test Weekly Debrief with User unit tests

* Update gitignore

- updated gitignore file to include secrets folder

* Implement reshuffle articles (#68)

* Add Docstrings to Test Factory Functions (#64)

* Initial boilerplate setup

* Add ArticleFactory, TestingDBConnection, FactoryUtils, placeholder article test file

* Add test cases on getAllArticles

* Create PublicationFactory, add tests for getAllArticles, getArticlesByPublicationID(s), getArticlesByPublicationSlug(s)

* Add hooks

* Update README

* Add pr changes

* Add pr changes

* Add tests for incrementShoutouts, searchArticle, getArticlesAfterDate

* Add publication tests and refactor factory files

* Remove test db open message

* Update src/tests/article.test.ts

Co-authored-by: Archit Mehta <[email protected]>

* Update src/tests/data/ArticleFactory.ts

Co-authored-by: Archit Mehta <[email protected]>

* Refactor code

* Refactor byDate

* Add docstrings

Co-authored-by: Kidus Zegeye <[email protected]>
Co-authored-by: Archit Mehta <[email protected]>

Implement shuffle article function

try to implement reshuffling with aggregate

* Implement reshuffling of articles

* Revert package.json, update eslint and update .gitignore to match main branch

---------

Co-authored-by: Kidus Zegeye <[email protected]>

* Implement magazine search (#69)

* Implement magazine search

- implemented searching for magazines

* update magazinerepo

* Add unit test for magazine search

- created unit test for MagazineRepo.searchMagazine

* Convert result of shuffling resolver to ArticleModel (#71)

* Add 3 new publications (Cornell Daily Sun, Collective X, and Cornell Healthcare Review) to publications.js (#70)

* Resolve merge conflicts in publications.json (keep release version) (#76)

* Kidus/filter articles (#48)

* Add covid filter to all article query functions

* Add filtering capability

* Fix getArticleById filter

* Create filter migration script

* Finish migration script

* Add toggle for filtering enforcement

* Implement PR changes

Co-authored-by: Kidus Zegeye <[email protected]>

* Fix BRSN's url

* Migrate bookmark resolver and update User Repo & Entity

* Resolve remaining merge conflicts

* Implement chronological sorting

* Update prod deployment script

* Remove unused MagazineURL index from Magazine DB

* Add no rules to publications.json

* Remove trailing comma

---------

Co-authored-by: Kidus Zegeye <[email protected]>
Co-authored-by: Kidus Zegeye <[email protected]>
Co-authored-by: Archit404Error <[email protected]>

* Revert "Resolve merge conflicts in publications.json (keep release version) (#76)" (#77)

This reverts commit eccf00c.

* fix merge conflicts (#78)

* Kidus/filter articles (#48)

* Add covid filter to all article query functions

* Add filtering capability

* Fix getArticleById filter

* Create filter migration script

* Finish migration script

* Add toggle for filtering enforcement

* Implement PR changes

Co-authored-by: Kidus Zegeye <[email protected]>

* Fix BRSN's url

* Migrate bookmark resolver and update User Repo & Entity

* Resolve remaining merge conflicts

* Implement chronological sorting

* Update prod deployment script

* Remove unused MagazineURL index from Magazine DB

* Add no rules to publications.json

* Remove trailing comma

---------

Co-authored-by: Kidus Zegeye <[email protected]>
Co-authored-by: Kidus Zegeye <[email protected]>
Co-authored-by: Archit404Error <[email protected]>

* Implement community board [1/7] (#81)

* Begin implementing FlyerRepo

- implemented basic FlyerRepo functions
- updated Flyer model to support uploading in app instead of through a google form

* Implement flyers for community board

- alphabetized imports and fields
- finished implementing flyers for community board

* Address pr review comments

- addressed pr review comments
- removed redundant filtering in FlyerRepo
- added checks for null return values in FlyerRepo
- alphabetized imports and exports

* Add imageURL field to Magazine entity. (#73)

* Add no rules to volume-backend's publications.json (#82)

* Implement community board (flyer tests) [2/7] (#84)

* Begin implementing FlyerRepo

- implemented basic FlyerRepo functions
- updated Flyer model to support uploading in app instead of through a google form

* Implement flyers for community board

- alphabetized imports and fields
- finished implementing flyers for community board

* Implement jest testing for flyers

- created jest unit testing for FlyerRepo
- created FlyerFactory to help with jest testing

* Remove isFiltered field from Flyer entity

- removed redundant isFiltered field from Flyer entity (already checked in microservice)
- updated FlyerRepo and jest testing to reflect changes

* Alphabetize imports and exports

- alphabetized imports and exports in FlyerRepo, flyer.test, and FlyerFactory

* Revert merge conflict changes

- reverted merge conflict changes (accept incoming when actually wanted to keep current)

* Address review comments

- alphabetize imports
- add unit test cases for FlyerRepo including searching for 0 flyers and maximum limit in response
- added unit test case for FlyerRepo.getTrendingFlyers

* Address review comments (Shungo)

- added spaces between test cases

* Implement community board organizations (#85)

- resolve merge conflicts in Flyer.ts and FlyerFactory.ts
- update Organization model
- implement logic in OrganizationRepo
- implement queries and mutations in OrganizationResolver

* Implement community board (organization tests) [4/7] (#86)

* Implement community board organizations

- resolve merge conflicts in Flyer.ts and FlyerFactory.ts
- update Organization model
- implement logic in OrganizationRepo
- implement queries and mutations in OrganizationResolver

* Implement jest testing for organizations

- implemented jest testing for community board organizations
- created organizations.json with 3 onboarded organizations
- added FlyerResolver and OrganizationResolver to app.ts

* Implement community board (user queries/mutations) [5/7] (#87)

* Kidus/filter articles (#48)

* Add covid filter to all article query functions

* Add filtering capability

* Fix getArticleById filter

* Create filter migration script

* Finish migration script

* Add toggle for filtering enforcement

* Implement PR changes

Co-authored-by: Kidus Zegeye <[email protected]>

* Fix BRSN's url

* Migrate bookmark resolver and update User Repo & Entity

* Resolve remaining merge conflicts

* Implement chronological sorting

* Update prod deployment script

* Remove unused MagazineURL index from Magazine DB

* Add no rules to publications.json

* Remove trailing comma

* Begin implementing FlyerRepo

- implemented basic FlyerRepo functions
- updated Flyer model to support uploading in app instead of through a google form

* Implement basic community board features

- finished implementing basic organization and flyer repos/resolvers
- created jest testing for organization and flyer repos

* Remove unnecessary OrganizationRepo function

- removed content types route from organization repo and organization resolver

* Implement user routes for community board

- implemented user routes for community board to allow following orgs and reading flyers
- added jest unit test cases for new UserRepo functions

* Implement mutations for following and unfollowing organizations

- added resolvers to UserResolver for following and unfollowing organizations
- updated documentation in UserRepo
- added import of FlyerRepo in app.ts

* Address pr review comments

- fix spelling

* Address pr review comments

- made style consistent in UserRepo by checking for if(user) in appendReadFlyer, appendReadArticle, and appendReadMagazine

---------

Co-authored-by: Kidus Zegeye <[email protected]>
Co-authored-by: Kidus Zegeye <[email protected]>
Co-authored-by: Archit404Error <[email protected]>

* Onboard organizations (#90)

- add organizations from volume-microservice onto organizations.json

* Implement community board (categories and org lists) [6/7] (#89)

* Implement community board organizations

- resolve merge conflicts in Flyer.ts and FlyerFactory.ts
- update Organization model
- implement logic in OrganizationRepo
- implement queries and mutations in OrganizationResolver

* Implement jest testing for organizations

- implemented jest testing for community board organizations
- created organizations.json with 3 onboarded organizations
- added FlyerResolver and OrganizationResolver to app.ts

* initial commit

* Implement organizations as list for flyer model

- updated flyer model to allow a list of organizations and organizationSlugs to be associated with each flyer
- updated flyer and organization queries accordingly
- added unit jest test cases and update old ones accordingly

* Address pr review comments

- removed redundant resolvers
- updated getOrganizationByCategory test

* Address pr review comments (kate)

- updated docs in OrganizationResolver

* Implement cboard start and end dates (#93)

* Implement end dates

- implemented start and end dates
- changed shoutouts to times clicked
- updated testing and documentation to reflect changes

* Address pr review comments

- removed async from getFlyersBeforeDate and getFlyersAfterDate
- updated documentation in FactoryUtils

* add incrementTimesClicked to resolver

* update organization shoutouts query (#94)

* Implement end dates

- implemented start and end dates
- changed shoutouts to times clicked
- updated testing and documentation to reflect changes

* Address pr review comments

- removed async from getFlyersBeforeDate and getFlyersAfterDate
- updated documentation in FactoryUtils

* add incrementTimesClicked to resolver

* Update organization clicks

- changed shoutouts query to clicks in OrganizationResolver

* Implement trending flyers logic (#95)

- updated trending flyers logic
- updated FlyerRepo
- updated documentation in FlyerResolver

---------

Co-authored-by: Kidus Zegeye <[email protected]>
Co-authored-by: Kidus Zegeye <[email protected]>
Co-authored-by: Archit Mehta <[email protected]>
Co-authored-by: Shungo Najima <[email protected]>
Co-authored-by: Sasha Loayza <[email protected]>
  • Loading branch information
6 people committed Jun 26, 2023
1 parent 1e16a30 commit 174c7e5
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 82 deletions.
1 change: 1 addition & 0 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export const IMAGE_ADDRESS = 'https://raw.githubusercontent.com/cuappdev/assets/
export const IOS = 'IOS';
export const MAX_NUM_DAYS_OF_TRENDING_ARTICLES = 30;
export const MAX_NUM_DAYS_OF_FEATURED_MAGAZINES = 30;
export const MAX_NUM_OF_TRENDING_FLYERS = 10;
8 changes: 6 additions & 2 deletions src/entities/Flyer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class Flyer {

@Field()
@Property()
date: Date;
endDate: Date;

@Field()
@Property({ nullable: true })
Expand Down Expand Up @@ -39,9 +39,13 @@ export class Flyer {
@Property({ type: () => [String] })
organizationSlugs: [string];

@Field()
@Property()
startDate: Date;

@Field()
@Property({ default: 0 })
shoutouts?: number;
timesClicked?: number;

@Field()
@Property()
Expand Down
8 changes: 4 additions & 4 deletions src/entities/Organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export class Organization {
id: string;

@Field()
@Property()
@Property({ nullable: true })
backgroundImageURL: string;

@Field()
@Property()
@Property({ nullable: true })
bio: string;

@Field()
Expand All @@ -23,7 +23,7 @@ export class Organization {
name: string;

@Field()
@Property()
@Property({ nullable: true })
profileImageURL: string;

@Field()
Expand All @@ -35,7 +35,7 @@ export class Organization {
shoutouts?: number;

@Field()
@Property()
@Property({ nullable: true })
websiteURL: string;
}

Expand Down
92 changes: 57 additions & 35 deletions src/repos/FlyerRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
DEFAULT_OFFSET,
FILTERED_WORDS,
MAX_NUM_DAYS_OF_TRENDING_ARTICLES,
MAX_NUM_OF_TRENDING_FLYERS,
} from '../common/constants';
import { OrganizationModel } from '../entities/Organization';

Expand All @@ -23,14 +24,44 @@ function isFlyerFiltered(flyer: Flyer) {

const getAllFlyers = async (offset = DEFAULT_OFFSET, limit = DEFAULT_LIMIT): Promise<Flyer[]> => {
return FlyerModel.find({})
.sort({ date: 'desc' })
.sort({ startDate: 'desc' })
.skip(offset)
.limit(limit)
.then((flyers) => {
return flyers.filter((flyer) => !isFlyerFiltered(flyer));
});
};

const getFlyersAfterDate = (since: string, limit = DEFAULT_LIMIT): Promise<Flyer[]> => {
return (
FlyerModel.find({
// Get all Flyers after or on the desired date
endDate: { $gte: new Date(since) },
})
// Sort dates in order of most recent to least
.sort({ endDate: 'desc' })
.limit(limit)
.then((flyers) => {
return flyers.filter((flyer) => flyer !== null && !isFlyerFiltered(flyer));
})
);
};

const getFlyersBeforeDate = (before: string, limit = DEFAULT_LIMIT): Promise<Flyer[]> => {
return (
FlyerModel.find({
// Get all Flyers before the desired date
endDate: { $lt: new Date(before) },
})
// Sort dates in order of most recent to least
.sort({ endDate: 'desc' })
.limit(limit)
.then((flyers) => {
return flyers.filter((flyer) => flyer !== null && !isFlyerFiltered(flyer));
})
);
};

const getFlyerByID = async (id: string): Promise<Flyer> => {
return FlyerModel.findById(new ObjectId(id)).then((flyer) => {
if (!isFlyerFiltered(flyer)) {
Expand All @@ -54,7 +85,7 @@ const getFlyersByOrganizationSlug = async (
offset: number = DEFAULT_OFFSET,
): Promise<Flyer[]> => {
return FlyerModel.find({ organizationSlugs: slug })
.sort({ date: 'desc' })
.sort({ startDate: 'desc' })
.skip(offset)
.limit(limit)
.then((flyers) => {
Expand All @@ -69,7 +100,7 @@ const getFlyersByOrganizationSlugs = async (
): Promise<Flyer[]> => {
const uniqueSlugs = [...new Set(slugs)];
return FlyerModel.find({ organizationSlugs: { $in: uniqueSlugs } })
.sort({ date: 'desc' })
.sort({ startDate: 'desc' })
.skip(offset)
.limit(limit)
.then((flyers) => {
Expand All @@ -84,7 +115,7 @@ const getFlyersByOrganizationID = async (
): Promise<Flyer[]> => {
const organization = await (await OrganizationModel.findById(organizationID)).execPopulate();
return FlyerModel.find({ organizationSlugs: organization.slug })
.sort({ date: 'desc' })
.sort({ startDate: 'desc' })
.skip(offset)
.limit(limit)
.then((flyers) => {
Expand All @@ -106,21 +137,6 @@ const getFlyersByOrganizationIDs = async (
);
};

const getFlyersAfterDate = async (since: string, limit = DEFAULT_LIMIT): Promise<Flyer[]> => {
return (
FlyerModel.find({
// Get all Flyers after or on the desired date
date: { $gte: new Date(new Date(since).setHours(0, 0, 0)) },
})
// Sort dates in order of most recent to least
.sort({ date: 'desc' })
.limit(limit)
.then((flyers) => {
return flyers.filter((flyer) => flyer !== null && !isFlyerFiltered(flyer));
})
);
};

/**
* Performs fuzzy search on all Flyers to find Flyers with title/publisher matching the query.
* @param query the term to search for
Expand Down Expand Up @@ -163,17 +179,19 @@ const refreshTrendingFlyers = async (): Promise<Flyer[]> => {
});

// Get new trending Flyers
const flyers = await FlyerModel.aggregate()
// Get a sample of random Flyers
.sample(100)
// Get Flyers after 30 days ago
.match({
date: {
$gte: new Date(
new Date().setDate(new Date().getDate() - MAX_NUM_DAYS_OF_TRENDING_ARTICLES),
),
},
});
const flyers = await (
await FlyerModel.aggregate()
// sort flyers by trendiness
.sort({ trendiness: 'desc' })
// Only get flyers for events that start in the next few days
.match({
startDate: {
$lte: new Date(
new Date().setDate(new Date().getDate() + MAX_NUM_DAYS_OF_TRENDING_ARTICLES),
),
},
})
).slice(0, MAX_NUM_OF_TRENDING_FLYERS);

flyers.forEach(async (a) => {
const flyer = await FlyerModel.findById(new ObjectId(a._id)); // eslint-disable-line
Expand All @@ -185,14 +203,17 @@ const refreshTrendingFlyers = async (): Promise<Flyer[]> => {
};

/**
* Increments number of shoutouts on an Flyer and publication by one.
* Increments number of times clicked on a flyer by one.
* @function
* @param {string} id - string representing the unique Object Id of an Flyer.
* @param {string} id - string representing the unique Object Id of a flyer.
*/
const incrementShoutouts = async (id: string): Promise<Flyer> => {
const incrementTimesClicked = async (id: string): Promise<Flyer> => {
const flyer = await FlyerModel.findById(new ObjectId(id));
if (flyer) {
flyer.shoutouts += 1;
flyer.timesClicked += 1;
// update the trendiness of a flyer
flyer.trendiness =
(flyer.timesClicked / (flyer.startDate.getTime() - new Date().getTime())) * 10000000;
return flyer.save();
}
return flyer;
Expand All @@ -213,13 +234,14 @@ export default {
getAllFlyers,
getFlyerByID,
getFlyersAfterDate,
getFlyersBeforeDate,
getFlyersByIDs,
getFlyersByOrganizationID,
getFlyersByOrganizationIDs,
getFlyersByOrganizationSlug,
getFlyersByOrganizationSlugs,
getTrendingFlyers,
incrementShoutouts,
incrementTimesClicked,
refreshTrendingFlyers,
searchFlyers,
};
10 changes: 5 additions & 5 deletions src/repos/OrganizationRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,24 @@ const getMostRecentFlyer = async (organization: Organization): Promise<Flyer> =>
// Organization['_doc'] must be used to access fields of a Organization object
return FlyerModel.findOne({
organizationSlugs: organization['_doc'].slug, // eslint-disable-line
}).sort({ date: 'desc' });
}).sort({ startDate: 'desc' });
};

/**
* Retrieves the number of shoutouts a Organization has by summing the shoutouts
* Retrieves the number of clicks an Organization has by summing the clicks
* of all of its flyers.
* @param {Organization} Organization
* @returns {Number}
*/
const getShoutouts = async (organization: Organization): Promise<number> => {
const getClicks = async (organization: Organization): Promise<number> => {
// Due to the way Mongo interprets 'Organization' object,
// Organization['_doc'] must be used to access fields of a Organization object
const orgFlyers = await FlyerModel.find({
organizationSlugs: organization['_doc'].slug, // eslint-disable-line
});

return orgFlyers.reduce((acc, flyer) => {
return acc + flyer.shoutouts;
return acc + flyer.timesClicked;
}, 0);
};

Expand All @@ -107,11 +107,11 @@ const getNumFlyers = async (organization: Organization): Promise<number> => {
export default {
addOrganizationsToDB,
getAllOrganizations,
getClicks,
getMostRecentFlyer,
getNumFlyers,
getOrganizationsByCategory,
getOrganizationByID,
getOrganizationsByIDs,
getOrganizationBySlug,
getShoutouts,
};
35 changes: 22 additions & 13 deletions src/resolvers/FlyerResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Resolver, Mutation, Arg, Query, FieldResolver, Root } from 'type-graphq
import { Flyer } from '../entities/Flyer';
import FlyerRepo from '../repos/FlyerRepo';
import { DEFAULT_LIMIT, DEFAULT_OFFSET } from '../common/constants';
import UserRepo from '../repos/UserRepo';

@Resolver((_of) => Flyer)
class FlyerResolver {
Expand Down Expand Up @@ -37,27 +36,27 @@ class FlyerResolver {
@Query((_returns) => [Flyer], {
nullable: false,
description:
'Returns a list of <Flyers> of size <limit> via the given <publicationID>. Results can offsetted by <offset> >= 0.',
'Returns a list of <Flyers> of size <limit> via the given <organizationID>. Results can offsetted by <offset> >= 0.',
})
async getFlyersByOrganizationID(
@Arg('publicationID') publicationID: string,
@Arg('organizationID') organizationID: string,
@Arg('limit', { defaultValue: DEFAULT_LIMIT }) limit: number,
@Arg('offset', { defaultValue: DEFAULT_OFFSET }) offset: number,
) {
return FlyerRepo.getFlyersByOrganizationID(publicationID, limit, offset);
return FlyerRepo.getFlyersByOrganizationID(organizationID, limit, offset);
}

@Query((_returns) => [Flyer], {
nullable: false,
description:
'Returns a list of <Flyers> of size <limit> via the given list of <publicationIDs>. Results offsetted by <offset> >= 0.',
'Returns a list of <Flyers> of size <limit> via the given list of <organizationIDs>. Results offsetted by <offset> >= 0.',
})
async getFlyersByOrganizationIDs(
@Arg('publicationIDs', (type) => [String]) publicationIDs: string[],
@Arg('organizationIDs', (type) => [String]) organizationIDs: string[],
@Arg('limit', { defaultValue: DEFAULT_LIMIT }) limit: number,
@Arg('offset', { defaultValue: DEFAULT_OFFSET }) offset: number,
) {
return FlyerRepo.getFlyersByOrganizationIDs(publicationIDs, limit, offset);
return FlyerRepo.getFlyersByOrganizationIDs(organizationIDs, limit, offset);
}

@Query((_returns) => [Flyer], {
Expand Down Expand Up @@ -98,6 +97,18 @@ class FlyerResolver {
return FlyerRepo.getFlyersAfterDate(since, limit);
}

@Query((_returns) => [Flyer], {
nullable: false,
description: `Returns a list of <Flyers> <before> a given date, limited by <limit>.
<before> is formatted as an compliant RFC 2822 timestamp. Valid examples include: "2019-01-31", "Aug 9, 1995", "Wed, 09 Aug 1995 00:00:00", etc. Default <limit> is ${DEFAULT_LIMIT}`,
})
async getFlyersBeforeDate(
@Arg('before') before: string,
@Arg('limit', { defaultValue: DEFAULT_LIMIT }) limit: number,
) {
return FlyerRepo.getFlyersBeforeDate(before, limit);
}

@Query((_returns) => [Flyer], {
nullable: false,
description: `Returns a list of trending <Flyers> of size <limit>. Default <limit> is ${DEFAULT_LIMIT}`,
Expand All @@ -122,7 +133,7 @@ class FlyerResolver {
const presentDate = new Date().getTime();
// Due to the way Mongo interprets 'Flyer' object,
// Flyer['_doc'] must be used to access fields of a Flyer object
return flyer['_doc'].shoutouts / ((presentDate - flyer['_doc'].date.getTime())/1000); // eslint-disable-line
return flyer['_doc'].timesClicked / ((presentDate - flyer['_doc'].startDate.getTime()) / 1000); // eslint-disable-line
}

@FieldResolver((_returns) => Boolean, {
Expand All @@ -134,12 +145,10 @@ class FlyerResolver {

@Mutation((_returns) => Flyer, {
nullable: true,
description: `Increments the shoutouts of a <Flyer> with the given <id>.
Increments the numShoutouts given of the user with the given [uuid].`,
description: `Increments the times clicked of a <Flyer> with the given <id>.`,
})
async incrementShoutouts(@Arg('uuid') uuid: string, @Arg('id') id: string) {
UserRepo.incrementShoutouts(uuid);
return FlyerRepo.incrementShoutouts(id);
async incrementTimesClicked(@Arg('id') id: string) {
return FlyerRepo.incrementTimesClicked(id);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/resolvers/OrganizationResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ class OrganizationResolver {
}

@FieldResolver((_returns) => Number, {
description: "Returns the total shoutouts of an <Organization's> <Flyers>",
description: "Returns the total times clicked of an <Organization's> <Flyers>",
})
async shoutouts(@Root() organization: Organization): Promise<number> {
return OrganizationRepo.getShoutouts(organization);
async clicks(@Root() organization: Organization): Promise<number> {
return OrganizationRepo.getClicks(organization);
}
}

Expand Down
Loading

0 comments on commit 174c7e5

Please sign in to comment.