Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #882 from Shinsina/newsletter-scheduled-content-qu…
Browse files Browse the repository at this point in the history
…ery-improvements

`newsletterEmailSchedules` query
  • Loading branch information
solocommand authored Mar 25, 2024
2 parents 22c1994 + 48bdeb7 commit 4b7556f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
12 changes: 12 additions & 0 deletions services/graphql-server/src/graphql/definitions/email/schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ extend type Query {
model: "email.Schedule",
using: { contentId: "content.$id" },
)
"Query for newsletter schedules by newlsetter product id and specified date range"
newsletterEmailSchedules(input: NewsletterEmailSchedulesQueryInput!): [EmailSchedule]!
}
extend type Mutation {
Expand Down Expand Up @@ -88,6 +90,16 @@ input EmailScheduleSortInput {
order: SortOrder = desc
}
"Input for retrieiving newsletter schedules for a specified time range"
input NewsletterEmailSchedulesQueryInput {
"The newsletter product id"
newsletterId: ObjectID!
"The millisecond precision UNIX timestamp to start looking for schedules at (inclusive)"
after: Date!
"The millsecond precision UNIX timestamp to stop looking for schedules at (inclusive"
before: Date!
}
input QuickCreateEmailSchedulesMutationInput {
contentId: Int!
sectionIds: [Int!]!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ interface Content @requiresProject(fields: ["type"]) {
websiteSchedules: [ContentWebsiteSchedule]!
# Returns the magazine schedules
magazineSchedules: [MagazineSchedule]! @projection(localField: "_id")
# Returns the email schedules
emailSchedules: [EmailSchedule]! @projection(localField: "_id")
hasWebsiteSchedule(input: ContentHasWebsiteScheduleInput!): Boolean! @projection(localField: "sectionQuery")
Expand Down
29 changes: 29 additions & 0 deletions services/graphql-server/src/graphql/resolvers/email/schedule.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const { BaseDB, MongoDB } = require('@parameter1/base-cms-db');
const { Base4RestPayload } = require('@parameter1/base-cms-base4-rest-api');
const { dasherize } = require('@parameter1/base-cms-inflector');
const moment = require('moment');
const getProjection = require('../../utils/get-projection');
const buildProjection = require('../../utils/build-projection');

const validateRest = require('../../utils/validate-rest');

Expand All @@ -15,6 +17,33 @@ const clearSeconds = (date) => {
};

module.exports = {
/**
*
*/
Query: {

newsletterEmailSchedules: async (_, { input }, { basedb }, info) => {
const {
newsletterId,
before,
after,
} = input;
const start = moment(after).toDate();
const end = moment(before).toDate();
const scheduleSort = { sequence: 1, deploymentDate: 1 };
const scheduleQuery = {
product: BaseDB.coerceID(newsletterId),
status: 1,
deploymentDate: { $gte: start, $lte: end },
};
const projection = buildProjection({ info, type: 'EmailSchedule' });
const schedules = await basedb.find('email.Schedule', scheduleQuery, {
sort: scheduleSort,
projection,
});
return schedules;
},
},
/**
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ module.exports = {

magazineSchedules: ({ _id }, _, { basedb }) => basedb.find('magazine.Schedule', { 'content.$id': _id }),

emailSchedules: ({ _id }, _, { basedb }) => basedb.find('email.Schedule', { 'content.$id': _id, status: 1 }),

/**
* Load primary section of content.
* If primary section's site matches the current site, return the section.
Expand Down

0 comments on commit 4b7556f

Please sign in to comment.