diff --git a/database/schedule.js b/database/schedule.js index 0b3f7d4..6bd4cc7 100644 --- a/database/schedule.js +++ b/database/schedule.js @@ -123,6 +123,23 @@ export const updateWeekType = async ({ weekID, type }) => { } } } + break + + case WEEK_TYPES.coVisit.value: + for (const assignmentName of ['congregationBibleStudy', 'reader']) { + const assignment = week.assignments[assignmentName] + if (assignment) { + for (const field of ASSIGNEE_FIELDS) { + const memberID = assignment[field] + if (memberID) { + const member = await removeAssignment({ memberID, assignment: { type: assignment.type, date: week.date } }) + updatedMembers.push(member) + const assignmentPath = `assignments.${assignmentName}.${field}` + update.$set[assignmentPath] = null + } + } + } + } } // Update Type @@ -133,3 +150,21 @@ export const updateWeekType = async ({ weekID, type }) => { // Return week and any removed assigned members return { week: value, members: updatedMembers } } + +export const updateCOName = async ({ weekID, name }) => { + const coll = await getCollection + const query = { _id: ObjectID(weekID) } + const update = { $set: { coName: name } } + const { value } = await coll.findOneAndUpdate(query, update, { returnOriginal: false }) + assert.notStrictEqual(null, value, 404) + return value +} + +export const updateCOTitle = async ({ weekID, title }) => { + const coll = await getCollection + const query = { _id: ObjectID(weekID) } + const update = { $set: { coTitle: title } } + const { value } = await coll.findOneAndUpdate(query, update, { returnOriginal: false }) + assert.notStrictEqual(null, value, 404) + return value +} diff --git a/lambda/api.js b/lambda/api.js index 996048d..8a60fca 100644 --- a/lambda/api.js +++ b/lambda/api.js @@ -144,6 +144,22 @@ router.put('/schedule/updateWeekType', (req, res) => { .catch(handleErrors(res)) }) +router.put('/schedule/updateCOName', (req, res) => { + const { weekID, name } = req.body + if (!weekID || name === undefined) return res.status(400).json({ message: 'Required Fields are: weekID, name' }) + schedule.updateCOName({ weekID, name }) + .then(returnResult(res)) + .catch(handleErrors(res)) +}) + +router.put('/schedule/updateCOTitle', (req, res) => { + const { weekID, title } = req.body + if (!weekID || title === undefined) return res.status(400).json({ message: 'Required Fields are: weekID, title' }) + schedule.updateCOTitle({ weekID, title }) + .then(returnResult(res)) + .catch(handleErrors(res)) +}) + // The lambda function route must match the netlify path app.use('/.netlify/functions/api', router) app.use((req, res) => { diff --git a/src/api/index.js b/src/api/index.js index 867721e..86fffd4 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -37,6 +37,8 @@ export default { month: ({ month }) => api.get(`/schedule/month/${month}`), scrape: ({ weekID }) => api.put(`/schedule/scrape/`, { weekID }), updateAssignment: ({ weekID, name, assignment }) => api.put(`/schedule/updateAssignment`, { weekID, name, assignment }), - updateWeekType: ({ weekID, type }) => api.put(`/schedule/updateWeekType`, { weekID, type }) + updateWeekType: ({ weekID, type }) => api.put(`/schedule/updateWeekType`, { weekID, type }), + updateCOName: ({ weekID, name }) => api.put(`/schedule/updateCOName`, { weekID, name }), + updateCOTitle: ({ weekID, title }) => api.put(`/schedule/updateCOTitle`, { weekID, title }) } } diff --git a/src/components/Schedule/ScheduleWeek.vue b/src/components/Schedule/ScheduleWeek.vue index 7dd2e51..f22b771 100644 --- a/src/components/Schedule/ScheduleWeek.vue +++ b/src/components/Schedule/ScheduleWeek.vue @@ -15,17 +15,19 @@ settings - - Redownload - - cloud_download - - + + + Redownload + + cloud_download + + + + + + + Circuit Overseer Details + + + + @@ -106,36 +122,40 @@ - - - + + + + Circuit Overseer Visit + + + - - - - - + + + - - - - - - + + + + + - - - - - - - - + + + + + + + + + + + + + + + + { + this.alert({ text: 'Circuit Overseer Name could not be updated.', color: 'error' }) + }) + }, + onUpdateCOTitle (title) { + this.updateCOTitle({ weekID: this.week._id, title }) + .then(this.loadLocalWeek) + .catch(() => { + this.alert({ text: 'Circuit Overseer Talk Title could not be updated.', color: 'error' }) + }) + }, onScrape () { this.scrapeLoading = true this.scrapeWeek({ weekID: this.week._id }) diff --git a/src/constants.js b/src/constants.js index 386e905..12c81ec 100644 --- a/src/constants.js +++ b/src/constants.js @@ -46,6 +46,6 @@ export const LANGUAGE_GROUPS = ['English', 'Portuguese'] export const WEEK_TYPES = { normal: { label: 'Normal', value: 0 }, assembly: { label: 'Assembly', value: 1 }, - coVisit: { label: 'CO Visit', value: 2 }, + coVisit: { label: 'Circuit Overseer Visit', value: 2 }, memorial: { label: 'Memorial', value: 3 } } diff --git a/src/plugins/pdfMake.js b/src/plugins/pdfMake.js index 1357dd2..9823e48 100644 --- a/src/plugins/pdfMake.js +++ b/src/plugins/pdfMake.js @@ -221,14 +221,22 @@ export function generateSchedule (weeks, month) { null ] if (serviceTalk2) livingTableRows[2] = [timer, getAssignmentTitle(serviceTalk2), null, getScheduleAssignees(serviceTalk2), addTime(serviceTalk2.time)] - livingTableRows.push( - [timer, 'Congregation Bible Study (30 min.)', 'Conductor:', getScheduleAssignees(congregationBibleStudy), addTime(30)], - [null, congregationBibleStudy.title, 'Reader:', getScheduleAssignees(reader), null], - [timer, 'Review/Preview/Announcements (3 min.)', 'Chairman:', getScheduleAssignees(chairman), addTime(3)], - [timer, songs[2], 'Prayer:', getScheduleAssignees(closingPrayer), addTime(5)] - ) + if (type === WEEK_TYPES.coVisit.value) { + livingTableRows.push( + [timer, 'Review/Preview/Announcements (3 min.)', 'Chairman:', getScheduleAssignees(chairman), addTime(3)], + [timer, week.coTitle + ' (30 min.)', 'Circuit Overseer:', week.coName, addTime(30)], + [timer, songs[2], 'Prayer:', getScheduleAssignees(closingPrayer), addTime(5)] + ) + } else { + livingTableRows.push( + [timer, 'Congregation Bible Study (30 min.)', 'Conductor:', getScheduleAssignees(congregationBibleStudy), addTime(30)], + [null, congregationBibleStudy.title, 'Reader:', getScheduleAssignees(reader), null], + [timer, 'Review/Preview/Announcements (3 min.)', 'Chairman:', getScheduleAssignees(chairman), addTime(3)], + [timer, songs[2], 'Prayer:', getScheduleAssignees(closingPrayer), addTime(5)] + ) + } const livingTable = createScheduleTable(COLORS.LIVING, livingTableRows) - Object.assign(livingTable.table.body[3][1], { rowSpan: 2 }) + if (type !== WEEK_TYPES.coVisit.value) Object.assign(livingTable.table.body[3][1], { rowSpan: 2 }) stack.push(livingTable) stack.push(createScheduleSeparator()) }) diff --git a/src/store/schedule.js b/src/store/schedule.js index c6590c3..c04aa14 100644 --- a/src/store/schedule.js +++ b/src/store/schedule.js @@ -60,6 +60,22 @@ const actions = { } return week }) + }, + updateCOName ({ commit }, { weekID, name }) { + return api.schedule.updateCOName({ weekID, name }) + .then(res => { + const week = res.data.result + commit('UPDATE_WEEK', week) + return week + }) + }, + updateCOTitle ({ commit }, { weekID, title }) { + return api.schedule.updateCOTitle({ weekID, title }) + .then(res => { + const week = res.data.result + commit('UPDATE_WEEK', week) + return week + }) } }
+ Circuit Overseer Visit +