Skip to content
This repository has been archived by the owner on Feb 10, 2022. It is now read-only.

Commit

Permalink
added template contract in leases
Browse files Browse the repository at this point in the history
  • Loading branch information
Camel Aissani committed May 18, 2021
1 parent cd1c51e commit a164ef6
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 12 deletions.
1 change: 1 addition & 0 deletions backend/managers/documentmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const get = async (req, res) => {
const response = await axios.get(url, {
responseType: 'stream',
headers: {
organizationId: req.headers.organizationid || String(req.realm._id),
'Accept-Language': language,
},
});
Expand Down
7 changes: 4 additions & 3 deletions backend/managers/emailmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const logger = require('winston');
const config = require('../../config');
const occupantModel = require('../models/occupant');

const _sendEmail = async (locale, message) => {
const _sendEmail = async (req, message) => {
const postData = {
templateName: message.document,
recordId: message.tenantId,
Expand All @@ -17,7 +17,8 @@ const _sendEmail = async (locale, message) => {
try {
const response = await axios.post(config.EMAILER_URL, postData, {
headers: {
'Accept-Language': locale,
organizationId: req.headers.organizationid || String(req.realm._id),
'Accept-Language': req.language,
},
});

Expand Down Expand Up @@ -69,7 +70,7 @@ module.exports = {
const statusList = await Promise.all(
messages.map(async (message) => {
try {
return await _sendEmail(req.language, message);
return await _sendEmail(req, message);
} catch (error) {
return [
{
Expand Down
1 change: 1 addition & 0 deletions backend/managers/leasemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ async function update(req, res) {
name: lease.name || dbLease.name,
description: lease.description || dbLease.description,
active: lease.active !== undefined ? lease.active : dbLease.active,
templateId: lease.templateId || '',
};
}

Expand Down
12 changes: 7 additions & 5 deletions backend/managers/propertymanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ function _toPropertiesData(realm, inputProperties, callback) {
property,
occupants.reduce(
(acc, occupant) => {
const occupant_property = occupant.properties.find(
(currentProperty) =>
currentProperty.propertyId === property._id.toString()
);
const occupant_property =
occupant.properties &&
occupant.properties.find(
(currentProperty) =>
currentProperty.propertyId === property._id.toString()
);
if (occupant_property) {
if (!acc.occupant) {
acc.occupant = occupant;
Expand All @@ -59,7 +61,7 @@ function _toPropertiesData(realm, inputProperties, callback) {
{ occupant: null }
).occupant,
occupants
.filter(({ properties }) =>
.filter(({ properties = [] }) =>
properties
.map(({ propertyId }) => propertyId)
.includes(property._id)
Expand Down
8 changes: 5 additions & 3 deletions backend/managers/rentmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ const _findOccupants = (realm, occupantId, startTerm, endTerm) => {
});
};

const _getEmailStatus = async (startTerm, endTerm) => {
const _getEmailStatus = async (realm, startTerm, endTerm) => {
try {
let emailEndPoint = `${config.EMAILER_URL}/status/${startTerm}`;
if (endTerm) {
emailEndPoint = `${config.EMAILER_URL}/status/${startTerm}/${endTerm}`;
}
logger.debug(`get email status ${emailEndPoint}`);
const response = await axios.get(emailEndPoint);
const response = await axios.get(emailEndPoint, {
organizationId: String(realm._id),
});
logger.debug(response.data);
return response.data.reduce((acc, status) => {
const data = {
Expand Down Expand Up @@ -93,7 +95,7 @@ const _getRentsDataByTerm = async (realm, currentDate, frequency) => {

const [dbOccupants, emailStatus = {}] = await Promise.all([
_findOccupants(realm, null, startTerm, endTerm),
_getEmailStatus(startTerm, endTerm).catch(logger.error),
_getEmailStatus(realm, startTerm, endTerm).catch(logger.error),
]);

// compute rents
Expand Down
2 changes: 1 addition & 1 deletion backend/managers/templatemanager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const config = require('../../config');
const axios = require('axios');

//TODO: if no added value to have the api in loca then move that in nginx config
//TODO: if no added value to have the api in loca then move that in nginx config

const pdfGeneratorUrl = `${config.PDFGENERATOR_URL}/templates`;

Expand Down
1 change: 1 addition & 0 deletions backend/models/lease.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class LeaseModel extends Model {
timeRange: String, // days, weeks, months, years
active: Boolean,
system: Boolean,
templateId: String,
});
}

Expand Down
9 changes: 9 additions & 0 deletions backend/routes/apiv2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const leaseManager = require('../managers/leasemanager');
const rentManager = require('../managers/rentmanager');
const occupantManager = require('../managers/occupantmanager');
const documentManager = require('../managers/documentmanager');
const templateManager = require('../managers/templatemanager');
const propertyManager = require('../managers/propertymanager');
const ownerManager = require('../managers/ownermanager');
const notificationManager = require('../managers/notificationmanager');
Expand Down Expand Up @@ -96,6 +97,14 @@ module.exports = function () {
documentsRouter.patch('/:id', documentManager.update);
router.use('/documents', documentsRouter);

const templatesRouter = express.Router();
templatesRouter.get('/', templateManager.all);
templatesRouter.get('/:id', templateManager.one);
templatesRouter.post('/', templateManager.add);
templatesRouter.put('/', templateManager.update);
templatesRouter.delete('/:ids', templateManager.remove);
router.use('/templates', templatesRouter);

const notificationsRouter = express.Router();
notificationsRouter.get('/', notificationManager.all);
router.use('/notifications', notificationsRouter);
Expand Down

0 comments on commit a164ef6

Please sign in to comment.