Skip to content

Commit

Permalink
Adding lastBackupAt property.
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisAlejandro committed Mar 22, 2024
1 parent ad05058 commit e9f3089
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/app/services/backups.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,19 @@ module.exports = (Model, App) => {
where: { name: folder.name, userId: userData.id },
include: [{ model: Model.backup }],
});
if (!device) throw createHttpError(404, 'Device does not exist');
if (!device) throw createHttpError(404, `${folder.name} is not on a device`);

let hasBackups = false;
let lastBackupAt = folder.updatedAt;
if (device.backups && device.backups.length) {
hasBackups = true;
lastBackupAt = device.backups.reduce(
(acc, backup) => (backup.updatedAt > acc ? backup.updatedAt : acc),
folder.updatedAt,
);
}

return { ...folder, hasBackups: !!device.backups || !!device.backups.length };
return { ...folder, hasBackups, lastBackupAt };
};

const renameDeviceAsFolder = async (userData, id, deviceName) => {
Expand Down

0 comments on commit e9f3089

Please sign in to comment.