Skip to content

Commit

Permalink
fix: delete staging data returns correct data, return array for diff …
Browse files Browse the repository at this point in the history
…data
  • Loading branch information
Michael.Taylor committed Dec 22, 2021
1 parent fd22053 commit 0b1bf40
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 45 deletions.
18 changes: 1 addition & 17 deletions src/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
import * as ProjectController from './project.controller';
import * as CoBenefitController from './co-benefit.controller';
import * as LocationController from './location.controller';
import * as RatingController from './rating.controller';
import * as QualificationController from './qualification.controller';
import * as RelatedProjectController from './related-projects.controller';
import * as UnitController from './units.controller';
import * as VintageController from './vintages.controller';
import * as StagingController from './staging.controller';

export {
ProjectController,
CoBenefitController,
LocationController,
RatingController,
QualificationController,
RelatedProjectController,
UnitController,
VintageController,
StagingController,
};
export { ProjectController, UnitController, StagingController };
4 changes: 2 additions & 2 deletions src/controllers/project.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const create = async (req, res) => {
uuid,
action: 'INSERT',
table: 'Projects',
data: JSON.stringify(req.body),
data: JSON.stringify([req.body]),
});
res.json('Added project to stage');
} catch (err) {
Expand Down Expand Up @@ -87,7 +87,7 @@ export const update = async (req, res) => {
uuid: req.body.warehouseProjectId,
action: 'UPDATE',
table: 'Projects',
data: JSON.stringify(req.body),
data: JSON.stringify(Array.isArray(req.body) ? req.body : [req.body]),
};

await Staging.create(stagedData);
Expand Down
5 changes: 4 additions & 1 deletion src/controllers/staging.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export const findAll = async (req, res) => {
}

if (workingData.action === 'DELETE') {
workingData.diff.original = JSON.parse(workingData.data);
const original = await Project.findOne({
where: { warehouseProjectId: workingData.uuid },
});
workingData.diff.original = original;
workingData.diff.change = {};
}

Expand Down
4 changes: 2 additions & 2 deletions src/controllers/units.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const create = async (req, res) => {
uuid,
action: 'INSERT',
table: 'Units',
data: JSON.stringify(req.body),
data: JSON.stringify([req.body]),
};

await Staging.create(stagedData);
Expand Down Expand Up @@ -67,7 +67,7 @@ export const update = async (req, res) => {
uuid: req.body.uuid,
action: 'UPDATE',
table: 'Units',
data: JSON.stringify(req.body),
data: JSON.stringify(Array.isArray(req.body) ? req.body : [req.body]),
};

await Staging.create(stagedData);
Expand Down
18 changes: 1 addition & 17 deletions src/routes/v1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,10 @@
import express from 'express';
const V1Router = express.Router();

import {
ProjectRouter,
UnitRouter,
CoBenefitRouter,
LocationRouter,
QualificationRouter,
RatingRouter,
VintageRouter,
RelatedProjectRouter,
StagingRouter,
} from './resources';
import { ProjectRouter, UnitRouter, StagingRouter } from './resources';

V1Router.use('/projects', ProjectRouter);
V1Router.use('/units', UnitRouter);
V1Router.use('/co-benefits', CoBenefitRouter);
V1Router.use('/locations', LocationRouter);
V1Router.use('/qualifications', QualificationRouter);
V1Router.use('/ratings', RatingRouter);
V1Router.use('/vintages', VintageRouter);
V1Router.use('/related-projects', RelatedProjectRouter);
V1Router.use('/staging', StagingRouter);

export { V1Router };
6 changes: 0 additions & 6 deletions src/routes/v1/resources/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
export * from './projects';
export * from './units';
export * from './locations';
export * from './qualifications';
export * from './ratings';
export * from './vintages';
export * from './related-projects';
export * from './co-benefits';
export * from './staging';

0 comments on commit 0b1bf40

Please sign in to comment.