Skip to content

Commit

Permalink
feat: expose get all labels api
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Feb 7, 2022
1 parent c62c092 commit 1143443
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 75 deletions.
120 changes: 46 additions & 74 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * as UnitController from './units.controller';
export * as StagingController from './staging.controller';
export * as OrganizationController from './organization.controller';
export * as IssuanceController from './issuance.controller';
export * as LabelController from './label.controller';
2 changes: 1 addition & 1 deletion src/controllers/issuance.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const findAll = async (req, res) => {

return res.json(
await Issuance.findAll({
where: { orgUid: Object.keys(homeOrg)[0] },
where: { orgUid: homeOrg.orgUid },
}),
);
} catch (error) {
Expand Down
21 changes: 21 additions & 0 deletions src/controllers/label.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Label, Organization } from '../models';

import { assertHomeOrgExists } from '../utils/data-assertions';

export const findAll = async (req, res) => {
try {
await assertHomeOrgExists();
const homeOrg = await Organization.getHomeOrg();

return res.json(
await Label.findAll({
where: { orgUid: homeOrg.orgUid },
}),
);
} catch (error) {
res.status(400).json({
message: 'Can not retreive labels',
error: error.message,
});
}
};
2 changes: 2 additions & 0 deletions src/routes/v1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import {
StagingRouter,
OrganizationRouter,
IssuanceRouter,
LabelRouter,
} from './resources';

V1Router.use('/projects', ProjectRouter);
V1Router.use('/units', UnitRouter);
V1Router.use('/staging', StagingRouter);
V1Router.use('/organizations', OrganizationRouter);
V1Router.use('/issuances', IssuanceRouter);
V1Router.use('/labels', LabelRouter);

export { V1Router };
1 change: 1 addition & 0 deletions src/routes/v1/resources/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './units';
export * from './staging';
export * from './organization';
export * from './issuances';
export * from './labels';
13 changes: 13 additions & 0 deletions src/routes/v1/resources/labels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

import express from 'express';

import { LabelController } from '../../../controllers';

const LabelRouter = express.Router();

LabelRouter.get('/', (req, res) => {
return LabelController.findAll(req, res);
});

export { LabelRouter };

0 comments on commit 1143443

Please sign in to comment.