Skip to content

Commit

Permalink
Merge pull request #61 from TaturanaMobi/hotfix/fluxo-emails-download
Browse files Browse the repository at this point in the history
feat(notifications): Add page to view by screening
  • Loading branch information
lpirola authored Mar 2, 2020
2 parents 9befca6 + 1814aa8 commit c107a35
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ [email protected] # Meteor's client-side reactive programming librar
[email protected] # CSS minifier run for production mode
[email protected] # JS minifier run for production mode
[email protected] # ECMAScript 5 compatibility for older browsers
[email protected].0 # Enable ECMAScript2015+ syntax in app code
[email protected].2 # Enable ECMAScript2015+ syntax in app code
[email protected] # Server-side component of the `meteor shell` command

udondan:slick
Expand Down
2 changes: 1 addition & 1 deletion .meteor/release
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[email protected]
[email protected].2
6 changes: 3 additions & 3 deletions .meteor/versions
8 changes: 8 additions & 0 deletions docker-compose.staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ services:

fake-smtp:
image: mailhog/mailhog
restart: always
environment:
MH_HOSTNAME: fake-smtp.taturana
ports:
Expand All @@ -55,6 +56,7 @@ services:

traefik:
image: traefik:1.7-alpine
restart: always
ports:
- 80:80/tcp
- 8080/tcp
Expand All @@ -70,6 +72,7 @@ services:

images:
image: h2non/imaginary
restart: always
ports:
- 9000/tcp
volumes:
Expand All @@ -91,6 +94,7 @@ services:

postgres:
image: postgres
restart: always
ports:
- 9000/tcp
environment:
Expand Down Expand Up @@ -133,6 +137,7 @@ services:

metabase:
image: metabase/metabase
restart: always
environment:
JAVA_TIMEZONE: America/Sao_Paulo
MB_DB_TYPE: postgres
Expand Down Expand Up @@ -180,6 +185,7 @@ services:

frontend:
image: taturanamobi/plataforma-frontend
restart: always
build: .
ports:
- 3000/tcp
Expand Down Expand Up @@ -251,6 +257,7 @@ services:

mariadb:
image: 'bitnami/mariadb:latest'
restart: always
environment:
- ALLOW_EMPTY_PASSWORD=yes
- MARIADB_USER=bn_wordpress
Expand All @@ -259,6 +266,7 @@ services:
- mariadb:/bitnami
wordpress:
image: bitnami/wordpress:latest
restart: always
depends_on:
- mariadb
ports:
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ volumes:
services:
mongo:
image: mongo
restart: always
# restart: always
ports:
- 27017:27017
networks:
Expand Down Expand Up @@ -98,7 +98,7 @@ services:

mongo-express:
image: mongo-express
restart: always
# restart: always
ports:
- 4005:8081
networks:
Expand Down
6 changes: 4 additions & 2 deletions imports/models/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Notifications.attachSchema(Schemas.Notification);

if (Meteor.isServer) {
Notifications.before.insert((userId, doc) => {
doc.createdAt = Date.now();
doc.createdAt = new Date();
});
Notifications.before.upsert((userId, doc) => {
doc.updatedAt = Date.now();
doc.updatedAt = new Date();
});
Notifications.after.insert((userId, doc) => {
const template = NotificationTemplates.findOne({ _id: doc.notificationTemplateId });
Expand Down Expand Up @@ -43,6 +43,8 @@ if (Meteor.isServer) {
pidgeon.html = SSR.render(template.name, varsData);

Email.send(pidgeon);

Notifications.update({ _id: doc._id }, { $set: { deliveredAt: new Date() } });
// console.log('Enviando e-mail:', doc);
});
}
Expand Down
54 changes: 27 additions & 27 deletions imports/models/zones.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
// An optimized hard-coded index to get zone by uf

const ZONES = {
"SP": "Sudeste",
"ES": "Sudeste",
"MG": "Sudeste",
"RG": "Sudeste",
"PR": "Sul",
"SC": "Sul",
"RS": "Sul",
"DF": "Centro-Oeste",
"GO": "Centro-Oeste",
"MS": "Centro-Oeste",
"MT": "Centro-Oeste",
"BA": "Nordeste",
"AL": "Nordeste",
"CE": "Nordeste",
"MA": "Nordeste",
"PB": "Nordeste",
"PE": "Nordeste",
"PI": "Nordeste",
"RN": "Nordeste",
"SE": "Nordeste",
"AM": "Norte",
"PA": "Norte",
"RO": "Norte",
"RR": "Norte",
"AC": "Norte",
"AP": "Norte",
"TO": "Norte",
SP: 'Sudeste',
ES: 'Sudeste',
MG: 'Sudeste',
RG: 'Sudeste',
PR: 'Sul',
SC: 'Sul',
RS: 'Sul',
DF: 'Centro-Oeste',
GO: 'Centro-Oeste',
MS: 'Centro-Oeste',
MT: 'Centro-Oeste',
BA: 'Nordeste',
AL: 'Nordeste',
CE: 'Nordeste',
MA: 'Nordeste',
PB: 'Nordeste',
PE: 'Nordeste',
PI: 'Nordeste',
RN: 'Nordeste',
SE: 'Nordeste',
AM: 'Norte',
PA: 'Norte',
RO: 'Norte',
RR: 'Norte',
AC: 'Norte',
AP: 'Norte',
TO: 'Norte',
};

export default ZONES;
11 changes: 11 additions & 0 deletions imports/startup/client/routes-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Router } from 'meteor/iron:router';
import '../../ui/components/adm-sidebar.html';
import '../../ui/components/admFilter.html';

import '../../ui/pages/admin/adm-fluxo-by-screening';
import '../../ui/pages/admin/adm-notification-templates';
import '../../ui/pages/admin/adm-notification-templates-new';
import '../../ui/pages/admin/adm-notification-templates-edit';
Expand All @@ -31,6 +32,7 @@ import Screenings from '../../models/screenings.js';
import Films from '../../models/films.js';
import Users from '../../models/users';
import NotificationTemplates from '../../models/notification_templates';
import Notifications from '../../models/notifications';

import { publicRoutes } from './routes-ambassador.js';

Expand Down Expand Up @@ -64,6 +66,15 @@ Router.route('/adm/notification-templates', {
action() { this.render('admNotificationTemplates'); },
});

Router.route('/adm/fluxo-by-screening/:screeningId', {
waitOn() { return Meteor.subscribe('notificationTemplates.all') && Meteor.subscribe('notificationByScreening.byScreening'); },
data() {
return NotificationTemplates.find({})
&& Notifications.find({ screeningId: this.params.screeningId });
},
action() { this.render('admFluxoByScreening'); },
});

Router.route('/adm/notification-templates-new', {
waitOn() { return Meteor.subscribe('films.all'); },
// data() { return NotificationTemplates.find({}); },
Expand Down
3 changes: 3 additions & 0 deletions imports/startup/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import './fixtures.js';
import './migrations';
import Films from '../../models/films';
import Screenings from '../../models/screenings';
import Notifications from '../../models/notifications';
import Images from '../../models/images';
import { Cities, States } from '../../models/states_and_cities';
import Worker from './worker';
Expand All @@ -35,6 +36,8 @@ Meteor.startup(() => {

Meteor.publish('notificationTemplates.all', function() { return NotificationTemplates.find({}); });

Meteor.publish('notificationByScreening.byScreening', function(screeningId) { return Notifications.find({ screeningId }); });

Meteor.publish('files.images.all', function() { return Images.find().cursor; });

Meteor.publish('cities', function(uf) {
Expand Down
24 changes: 15 additions & 9 deletions imports/startup/server/processScreenings.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,53 @@ import NotificationTemplates from '../../models/notification_templates';
const processScreenings = {
isGreaterThan10days(sDate, refDate = new Date()) {
check(sDate, Date);
const tenDaysAfter = moment(refDate).add(9, 'days');
const tenDaysAfter = moment(refDate).add(11, 'days');

return moment(sDate).isSameOrAfter(tenDaysAfter);
},

isBetween9and4days(sDate, refDate = new Date()) {
check(sDate, Date);
const nineDaysBefore = moment(refDate).add(9, 'days').toDate();
const fourDaysBefore = moment(refDate).add(3, 'days').toDate();
const nineDaysBefore = moment(refDate).add(10, 'days').toDate();
const fourDaysBefore = moment(refDate).add(4, 'days').toDate();

return moment(sDate).isBetween(fourDaysBefore, nineDaysBefore, null, '[]');
},

isLowerThan3days(sDate, refDate = new Date()) {
const threeDaysBefore = moment(refDate).add(3, 'days').toDate();
// const threeDaysBefore = moment(refDate).add(3, 'days').toDate();
const fourDaysBefore = moment(refDate).add(4, 'days').toDate();

check(sDate, Date);
return moment(sDate).isSameOrBefore(threeDaysBefore);
return moment(sDate).isSameOrBefore(fourDaysBefore);
},

isAt10thDayBefore(sDate, refDate = new Date()) {
check(sDate, Date);
const at10thDayBefore = moment(refDate).add(10, 'days').toDate();
const at11thDayBefore = moment(refDate).add(11, 'days').toDate();

return moment(sDate).isSame(at10thDayBefore, 'day');
return moment(sDate).isBetween(at10thDayBefore, at11thDayBefore, null, '[]');
},

is7daysBefore(sDate, refDate = new Date()) {
check(sDate, Date);
const sevenDaysBefore = moment(refDate).add(7, 'days').toDate();
const eightDaysBefore = moment(refDate).add(8, 'days').toDate();

return moment(sDate).isSameOrBefore(sevenDaysBefore);
return moment(sDate).isBetween(sevenDaysBefore, eightDaysBefore, null, '[]');
},

is2daysBefore(sDate, refDate = new Date()) {
check(sDate, Date);
const twoDaysBefore = moment(refDate).add(2, 'days').toDate();
const twoDaysBefore = moment(refDate).add(3, 'days').toDate();

return moment(sDate).isSameOrBefore(twoDaysBefore);
},

is1dayBefore(sDate, refDate = new Date()) {
check(sDate, Date);
const oneDayBefore = moment(refDate).add(1, 'days').toDate();
const oneDayBefore = moment(refDate).add(2, 'days').toDate();

return moment(sDate).isSameOrBefore(oneDayBefore);
},
Expand Down Expand Up @@ -118,6 +121,7 @@ const processScreenings = {
processConfirmada(s) {
// Confirmada - Sessão agendada com 10 dias ou mais de antecedência,
// enviar e-mail 1 dias antes da sessão send_the_movie_3
console.log('processScreenings.isGreaterThan10days(s.date, s.created_at)', processScreenings.isGreaterThan10days(s.date, s.created_at), s.date, s.created_at);
if (processScreenings.isLowerThan3days(s.date, s.created_at)) {
if (processScreenings.is1dayBefore(s.date)) {
processScreenings.createNotification(s, 'send_the_movie_3');
Expand All @@ -132,9 +136,11 @@ const processScreenings = {
// enviar e-mail 7 dias antes da sessão send_the_movie_10
} else if (processScreenings.isGreaterThan10days(s.date, s.created_at)) {
// enviar e-mail no dia 10 screening_date
console.log('processScreenings.isAt10thDayBefore(s.date)', processScreenings.isAt10thDayBefore(s.date));
if (processScreenings.isAt10thDayBefore(s.date)) {
processScreenings.createNotification(s, 'confirm_screening_date');
}
console.log('processScreenings.is7daysBefore(s.date)', processScreenings.is7daysBefore(s.date));
if (processScreenings.is7daysBefore(s.date)) {
processScreenings.createNotification(s, 'send_the_movie_10');
}
Expand Down
Loading

0 comments on commit c107a35

Please sign in to comment.