Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small improvements #1330

Merged
merged 4 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit $1
2 changes: 0 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

node_modules/.bin/lint-staged
13 changes: 9 additions & 4 deletions api/controllers/v1/document/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,20 @@ module.exports = async (req, res) => {

if (deletePermanently) {
await TDocument.update({ redirectTo: documentId }).set({
dateReviewed: new Date(), // Avoid a uniqueness error
redirectTo: shouldMergeInto ? mergeIntoId : null,
});
await TDocument.update({ parent: documentId }).set({
parent: shouldMergeInto ? mergeIntoId : null,
});
await TDocument.update({ parent: documentId })
.set({
dateReviewed: new Date(), // Avoid a uniqueness error
parent: shouldMergeInto ? mergeIntoId : null,
})
.meta({ fetch: false });
await HDocument.update({ parent: documentId }).set({
parent: shouldMergeInto ? mergeIntoId : null,
});
await TDocument.update({ authorizationDocument: null }).set({
await TDocument.update({ authorizationDocument: documentId }).set({
dateReviewed: new Date(), // Avoid a uniqueness error
authorizationDocument: null,
});

Expand Down
50 changes: 23 additions & 27 deletions api/controllers/v1/partner/find-for-carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,38 @@ const ControllerService = require('../../../services/ControllerService');
const { toOrganization } = require('../../../services/mapping/converters');
const { toListFromController } = require('../../../services/mapping/utils');

module.exports = (req, res) => {
module.exports = async (req, res) => {
let skip = 0;
let limit = 50;
if (req.param('skip')) {
skip = req.param('skip');
}
let limit = 30;
if (req.param('limit')) {
limit = req.param('limit');
}
TGrotto.find({ select: ['id', 'pictureFileName', 'customMessage'] })
.skip(skip)
.limit(limit)
.sort('id ASC')
const found = await TGrotto.find({
select: ['id', 'pictureFileName', 'customMessage'],
})
.where({
customMessage: {
'!=': null,
},
pictureFileName: {
'!=': '',
},
customMessage: { '!=': null },
pictureFileName: { '!=': '' },
isOfficialPartner: '1',
})
.skip(skip)
.limit(limit)
.sort('id ASC')
.populate('names')
.exec((err, found) => {
const params = {};
params.controllerMethod = 'PartnerController.findForCarousel';
params.notFoundMessage = 'No partners found.';
return ControllerService.treatAndConvert(
req,
err,
found,
params,
res,
(data, meta) =>
toListFromController('organization', data, toOrganization, { meta })
);
});
.populate('names');

return ControllerService.treatAndConvert(
req,
null,
found,
{
controllerMethod: 'PartnerController.findForCarousel',
notFoundMessage: 'No partners found.',
},
res,
(data, meta) =>
toListFromController('organization', data, toOrganization, { meta })
);
};
11 changes: 11 additions & 0 deletions api/services/NotificationService.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const NameService = require('./NameService');
const CommonService = require('./CommonService');

const NOTIFICATION_ENTITIES = {
CAVE: 'cave',
Expand All @@ -22,6 +23,11 @@ const NOTIFICATION_TYPES = {
RESTORE: 'RESTORE',
};

async function removeOlderNotifications() {
const query = `DELETE FROM t_notification WHERE date_inscription < current_timestamp - interval '2 month';`;
await CommonService.query(query);
}

const safeGetPropId = (prop, data) => {
if (data && data[prop]) {
if (data[prop] instanceof Object) {
Expand Down Expand Up @@ -470,6 +476,11 @@ module.exports = {
return true;
})
);

// 5% chance to also remove older notifications
if (process.env.NODE_ENV !== 'test' && Math.random() < 0.05)
removeOlderNotifications();

return res;
} catch (error) {
// Fail silently to avoid sending an error to the user
Expand Down
Loading