Skip to content

Commit

Permalink
fix select issue #67
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigura committed Mar 6, 2020
1 parent 29a38ee commit a88f374
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/client/components/WrappedViewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ const WrappedViewport = ({
useEffect(() => {
const action = !hasToken && !!shared
? showAuthDialog()
: getDefaultJwt(token);
: (!!token && getDefaultJwt(token));

!hasData && store.dispatch(action);
});
!hasData && action && store.dispatch(action);
}, [hasToken]);
return hasToken || !shared
? (!loading ? <Viewport /> : <Loading />)
: <AuthForm />;
Expand Down
9 changes: 6 additions & 3 deletions src/server/models/Device.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ export async function getDevice({
}

export async function getDevices(params, isAdmin) {
const { org } = params || {};
if (!isAdmin && !org) {
const { org, companyId } = params || {};

if (!isAdmin && !(org || companyId)) {
return [];
}

const whereConditions = { company_token: org };
const whereConditions = isAdmin
? { company_id: companyId }
: { company_token: org };

const result = await DeviceModel.findAll({
where: whereConditions,
Expand Down
4 changes: 1 addition & 3 deletions src/server/models/Org.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ export async function findOrCreate({ org }) {
}

export const findOne = async ({ org }) => {
const co = await CompanyModel.findOne({
const company = await CompanyModel.findOne({
where: { company_token: org },
order: [['recorded_at', desc]],
raw: true,
});
const company = co ? hydrate(co) : null;
return company;
};
7 changes: 4 additions & 3 deletions src/server/routes/site-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ router.get('/company_tokens', checkAuth(verify), async (req, res) => {
*/
router.get('/devices', checkAuth(verify), async (req, res) => {
const { org } = req.jwt;
const { company_id: companyId } = req.query;
try {
const devices = await getDevices({ ...req.query, org }, isAdmin(req.jwt));
const devices = await getDevices({ companyId, org }, isAdmin(req.jwt));
res.send(devices);
} catch (err) {
console.error('v1', '/devices', err);
Expand Down Expand Up @@ -250,10 +251,10 @@ router.post('/jwt', async (req, res) => {
const { org } = req.body || {};

try {
const { id } = findOne(org) || {};
const { id } = await findOne({ org }) || {};

if (!id) {
res.status(401).send({ org, error: 'Org not found' });
return res.status(401).send({ org, error: 'Org not found' });
}

const jwtInfo = {
Expand Down

0 comments on commit a88f374

Please sign in to comment.