Skip to content

Commit

Permalink
feat: add edit staging table
Browse files Browse the repository at this point in the history
  • Loading branch information
frantzarty committed Jun 21, 2022
1 parent f1e6626 commit 445fd5b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/controllers/staging.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,28 @@ export const clean = async (req, res) => {
}
};

export const editRecord = async (req, res) => {
try {
await assertIfReadOnlyMode();
await assertHomeOrgExists();
await assertStagingRecordExists(req.body.uuid);

await Staging.update(
{ data: JSON.stringify([req.body.data]) },
{ where: { uuid: req.body.uuid } },
);

res.status(400).json({
message: 'Staging Record sucessfully updated.',
});
} catch (error) {
res.status(400).json({
message: 'Staging Record can not be edited.',
error: error.message,
});
}
};

export const retryRecrod = async (req, res) => {
try {
await assertIfReadOnlyMode();
Expand Down
4 changes: 4 additions & 0 deletions src/routes/v1/resources/staging.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ StagingRouter.get('/', validator.query(stagingGetQuerySchema), (req, res) => {
return StagingController.findAll(req, res);
});

StagingRouter.put('/', (req, res) => {
return StagingController.editRecord(req, res);
});

StagingRouter.delete(
'/',
validator.body(stagingDeleteSchema),
Expand Down
5 changes: 5 additions & 0 deletions src/validations/staging.validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export const commitStagingSchema = Joi.object({
comment: Joi.string().optional(),
});

export const stagingEditSchema = Joi.object({
uuid: Joi.string().required(),
data: Joi.object().required(),
});

export const stagingGetQuerySchema = Joi.object()
.keys({
page: Joi.number(),
Expand Down

0 comments on commit 445fd5b

Please sign in to comment.