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

feat: added resetToGeneration audit endpoint #1101

Merged
merged 22 commits into from
May 31, 2024
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
aa851b9
feat: added resetToGeneration audit endpoint
wwills2 May 24, 2024
5ee54f0
chore: resolved merge conflicts
wwills2 May 24, 2024
69733fc
feat: added resetToDate audit endpoint
wwills2 May 27, 2024
f94fe1e
fix: reset to date endpoint query
wwills2 May 28, 2024
c813bf5
chore: addressed PR comments
wwills2 May 28, 2024
93a90df
chore: addressed PR comments
wwills2 May 28, 2024
7e5fd29
Merge branch 'reset-audit-table-to-generation' of github.com:Chia-Net…
wwills2 May 28, 2024
75f05ef
feat: added option to exclude home org
wwills2 May 28, 2024
10285f2
fix: reset audit table task
wwills2 May 29, 2024
819ebb0
fix: reset audit table task
wwills2 May 29, 2024
abdab36
Merge remote-tracking branch 'origin/reset-audit-table-to-generation'…
wwills2 May 29, 2024
f13d93e
Merge remote-tracking branch 'origin/reset-audit-table-to-generation'…
wwills2 May 29, 2024
23c0655
Merge remote-tracking branch 'origin/reset-audit-table-to-generation'…
wwills2 May 29, 2024
cf3e5b7
Merge remote-tracking branch 'origin/reset-audit-table-to-generation'…
wwills2 May 29, 2024
325ddc2
Merge remote-tracking branch 'origin/reset-audit-table-to-generation'…
wwills2 May 29, 2024
4541b1b
fix: reset to generation validation schema
wwills2 May 29, 2024
729e79d
fix: task meta data retrieval
wwills2 May 29, 2024
5b8bcbe
fix: task meta data retrieval
wwills2 May 29, 2024
4a5845d
fix: reset to date
wwills2 May 29, 2024
e23ccba
chore: removed unnecessary option for reset to generation
wwills2 May 29, 2024
2b015c2
feat: added read-only check to reset date and audit endpoints
wwills2 May 30, 2024
7de1b68
chore: removed reset task interval from config
wwills2 May 31, 2024
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
Prev Previous commit
Next Next commit
feat: added resetToDate audit endpoint
  • Loading branch information
wwills2 committed May 27, 2024
commit 69733fc4128402d370b7dd2b87d4b7753061a316
26 changes: 25 additions & 1 deletion src/controllers/audit.controller.js
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ import {
optionallyPaginatedResponse,
} from '../utils/helpers';
import _ from 'lodash';
wwills2 marked this conversation as resolved.
Show resolved Hide resolved

export const findAll = async (req, res) => {
try {
let { page, limit, orgUid, order } = req.query;
@@ -43,6 +42,7 @@ export const findConflicts = async (req, res) => {
export const resetToGeneration = async (req, res) => {
try {
const { generation, orgUid } = req.body;

const result = await Audit.resetToGeneration(generation, orgUid);
if (_.isNil(result)) {
throw new Error('query failed');
@@ -62,3 +62,27 @@ export const resetToGeneration = async (req, res) => {
});
}
};

export const resetToDate = async (req, res) => {
try {
const { date, orgUid } = req.body;

const result = orgUid
? await Audit.resetOrgToDate(date, orgUid)
: await Audit.resetToDate(date);
if (_.isNil(result)) {
throw new Error('query failed');
}
return res.json({
message: result ? 'reset to date ' + String(date) : 'no matching records',
recordsDeleted: result,
wwills2 marked this conversation as resolved.
Show resolved Hide resolved
success: true,
});
} catch (error) {
res.status(400).json({
message: 'failed to reset to date',
error: error.message,
success: false,
});
}
};
33 changes: 33 additions & 0 deletions src/models/audit/audit.model.js
Original file line number Diff line number Diff line change
@@ -62,6 +62,39 @@ class Audit extends Model {
});
}
}

static async resetToDate(date) {
wwills2 marked this conversation as resolved.
Show resolved Hide resolved
const parsedDate = Math.round(date.valueOf() / 1000);

return await Audit.destroy({
where: sequelize.where(
sequelize.cast(
sequelize.col('onChainConfirmationTimeStamp'),
'UNSIGNED',
),
{
[Sequelize.Op.gte]: parsedDate,
},
),
});
}

static async resetOrgToDate(date, orgUid) {
const parsedDate = Math.round(date.valueOf() / 1000);

return await Audit.destroy({
where: {
orgUid: orgUid,
[Sequelize.Op.and]: sequelize.where(
sequelize.cast(
sequelize.col('onchainConfirmationTimeStamp'),
'UNSIGNED',
),
{ [Sequelize.Op.gte]: parsedDate },
),
},
});
}
}

Audit.init(ModelTypes, {
13 changes: 11 additions & 2 deletions src/routes/v1/resources/audit.js
Original file line number Diff line number Diff line change
@@ -6,7 +6,8 @@ import joiExpress from 'express-joi-validation';
import { AuditController } from '../../../controllers';
import {
auditGetSchema,
auditResetGenerationSchema,
auditResetToDateSchema,
auditResetToGenerationSchema,
} from '../../../validations';

const validator = joiExpress.createValidator({ passError: true });
@@ -22,10 +23,18 @@ AuditRouter.get('/findConflicts', (req, res) => {

AuditRouter.post(
'/resetToGeneration',
validator.body(auditResetGenerationSchema),
validator.body(auditResetToGenerationSchema),
(req, res) => {
return AuditController.resetToGeneration(req, res);
},
);

AuditRouter.post(
'/resetToDate',
validator.body(auditResetToDateSchema),
(req, res) => {
return AuditController.resetToDate(req, res);
},
);

export { AuditRouter };
7 changes: 6 additions & 1 deletion src/validations/audit.validations.js
Original file line number Diff line number Diff line change
@@ -10,7 +10,12 @@ export const auditGetSchema = Joi.object()
.with('page', 'limit')
.with('limit', 'page');

export const auditResetGenerationSchema = Joi.object().keys({
export const auditResetToGenerationSchema = Joi.object().keys({
generation: Joi.number(),
orgUid: Joi.string().optional(),
});

export const auditResetToDateSchema = Joi.object().keys({
date: Joi.date(),
wwills2 marked this conversation as resolved.
Show resolved Hide resolved
orgUid: Joi.string().optional(),
});
Loading