Skip to content

Commit

Permalink
fix: qualifications join
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael.Taylor committed Jan 5, 2022
1 parent ed79ecb commit f2eed4e
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/controllers/units.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const findAll = async (req, res) => {
include: [
{
model: Qualification,
as: 'qualification',
as: 'qualifications',
},
Vintage,
],
Expand All @@ -87,12 +87,12 @@ export const findOne = async (req, res) => {
}

res.json(
await Unit.findAll({
await Unit.findOne({
where: { uuid: req.query.uuid },
include: [
{
model: Qualification,
as: 'qualification',
as: 'qualifications',
},
Vintage,
],
Expand Down Expand Up @@ -139,3 +139,31 @@ export const destroy = async (req, res) => {
});
}
};

export const split = async (req, res) => {
try {
const originalRecord = await Unit.findOne({
where: { uuid: req.query.unitUid },
});

const stagedData = {
uuid: req.body.uuid,
action: 'UPDATE',
table: 'Units',
data: [
{
...originalRecord,
},
],
};

await Staging.create(stagedData);
res.json({
message: 'Unit split successfully',
});
} catch (err) {
res.json({
message: 'Error splitting unit',
});
}
};

0 comments on commit f2eed4e

Please sign in to comment.