Skip to content

Commit

Permalink
feat: add uuid to units model
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael.Taylor committed Dec 29, 2021
1 parent 9035ab0 commit 17a76de
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 25 deletions.
56 changes: 33 additions & 23 deletions src/controllers/units.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { uuid as uuidv4 } from 'uuidv4';
import { Staging, UnitMock, Unit, Qualification, Vintage } from '../models';
import { optionallyPaginatedResponse, paginationParams } from "./helpers";
import { optionallyPaginatedResponse, paginationParams } from './helpers';

export const create = async (req, res) => {
try {
Expand Down Expand Up @@ -37,30 +37,40 @@ export const findAll = async (req, res) => {
}

if (req.query.onlyEssentialColumns) {
return res.json(optionallyPaginatedResponse(await Unit.findAndCountAll({
attributes: [
'orgUid',
'unitLink',
'registry',
'unitType',
'unitCount',
'unitStatus',
'unitStatusDate',
],
}), page, limit));
return res.json(
optionallyPaginatedResponse(
await Unit.findAndCountAll({
attributes: [
'orgUid',
'unitLink',
'registry',
'unitType',
'unitCount',
'unitStatus',
'unitStatusDate',
],
}),
page,
limit,
),
);
}

res.json(
optionallyPaginatedResponse(await Unit.findAndCountAll({
include: [
{
model: Qualification,
as: 'qualification',
},
Vintage,
],
...paginationParams(page, limit),
}), page, limit),
optionallyPaginatedResponse(
await Unit.findAndCountAll({
include: [
{
model: Qualification,
as: 'qualification',
},
Vintage,
],
...paginationParams(page, limit),
}),
page,
limit,
),
);
};

Expand All @@ -78,7 +88,7 @@ export const findOne = async (req, res) => {

res.json(
await Unit.findAll({
where: { id: req.query.id },
where: { uuid: req.query.uuid },
include: [
{
model: Qualification,
Expand Down
7 changes: 5 additions & 2 deletions src/models/projects/projects.modeltypes.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ module.exports = {
primaryKey: true,
autoIncrement: true,
},
// The orgUid is teh singeltonId of the
warehouseProjectId: {
type: Sequelize.STRING,
unique: true,
},
// The orgUid is the singeltonId of the
// organizations tables on the datalayer
orgUid: Sequelize.STRING,
warehouseProjectId: Sequelize.STRING,
projectId: Sequelize.STRING,
projectLocationId: Sequelize.NUMBER,
currentRegistry: Sequelize.STRING,
Expand Down
4 changes: 4 additions & 0 deletions src/models/units/units.modeltypes.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ module.exports = {
primaryKey: true,
autoIncrement: true,
},
uuid: {
type: Sequelize.STRING,
unique: true,
},
// The orgUid is teh singeltonId of the
// organizations tables on the datalayer
orgUid: Sequelize.STRING,
Expand Down
5 changes: 5 additions & 0 deletions src/models/units/units.stub.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[
{
"id": 1,
"uuid": "5c960ac1-a180-45a4-9850-be177e26d2fb",
"orgUid": "f1c54511-865e-4611-976c-7c3c1f704662",
"unitLink": "https://unit.link",
"buyer": "person 1",
Expand All @@ -20,6 +21,7 @@
},
{
"id": 2,
"uuid": "50aa22fe-20c4-4af9-a9e9-8472e73a9222",
"orgUid": "f1c54511-865e-4611-976c-7c3c1f704662",
"unitLink": "https://unit.link",
"buyer": "person 2",
Expand All @@ -39,6 +41,7 @@
},
{
"id": 3,
"uuid": "7703e6be-1781-4322-9a9c-502ca0dca29b",
"orgUid": "35f92331-c8d7-4e9e-a8d2-cd0a86cbb2cf",
"unitLink": "https://unit.link",
"buyer": "person 3",
Expand All @@ -58,6 +61,7 @@
},
{
"id": 4,
"uuid": "04582672-47a9-411b-896f-3d45974e360e",
"orgUid": "f1c54511-865e-4611-976c-7c3c1f704662",
"unitLink": "https://unit.link",
"buyer": "person 4",
Expand All @@ -77,6 +81,7 @@
},
{
"id": 5,
"uuid": "cdc90991-a00d-4567-a09a-cbe5430fdc56",
"orgUid": "35f92331-c8d7-4e9e-a8d2-cd0a86cbb2cf",
"unitLink": "https://unit.link",
"buyer": "person 5",
Expand Down

0 comments on commit 17a76de

Please sign in to comment.