Skip to content

Commit

Permalink
feat: option to commit units seperate from projects
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Feb 9, 2022
1 parent 2855bf1 commit 823a348
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/controllers/staging.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const commit = async (req, res) => {
await assertHomeOrgExists();
await assetNoPendingCommits();

await Staging.pushToDataLayer();
await Staging.pushToDataLayer(_.get(req, 'query.table', null));
res.json({ message: 'Staging Table committed to full node' });
} catch (error) {
res.status(400).json({
Expand Down
13 changes: 11 additions & 2 deletions src/models/staging/staging.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,17 @@ class Staging extends Model {
return [insertRecords, updateRecords, deleteChangeList];
};

static async pushToDataLayer() {
const stagedRecords = await Staging.findAll({ raw: true });
static async pushToDataLayer(tableToPush) {
let stagedRecords;
if (tableToPush) {
stagedRecords = await Staging.findAll({
where: { table: tableToPush },
raw: true,
});
} else {
stagedRecords = await Staging.findAll({ raw: true });
}

const unitsChangeList = await Unit.generateChangeListFromStagedData(
stagedRecords,
);
Expand Down
1 change: 1 addition & 0 deletions src/validations/staging.validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ import Joi from 'joi';

export const stagingDeleteSchema = Joi.object({
uuid: Joi.string().required(),
table: Joi.string().valid('projects', 'units').optional(),
});
2 changes: 2 additions & 0 deletions tests/resources/staging.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ describe('Staging Resource CRUD', function () {
it('Staging record is removed when Insert records propagate through the datalayer', function () {});
it('Staging record is removed when Update records propagate through the datalayer', function () {});
it('Staging record is removed when Delete records propagate through the datalayer', function () {});
it('can commit just the project staging records optionally', function () {});
it('can commit just the unit staging records optionally', function () {});
});

describe('DELETE - Delete a single staging record', function () {
Expand Down

0 comments on commit 823a348

Please sign in to comment.